How to use analog sensor value in LUA Domoticz

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Bram81
New user
Posts: 8
Joined: 16 Feb 2016, 13:54

How to use analog sensor value in LUA Domoticz

#1 Post by Bram81 » 16 Feb 2016, 14:13

Hi,

I'm using ESP Easy R48 on a Nodemcu 0.9, programmed with Arduino IDE, to get readings from a lipo powered soil moisture sensor into Domoticz. At first this was a problem, because despite my dummy humidity device was updated every minute, the value in Domoticz remained 0 even though the webinterface of the esp easy showed the sensor was working and making measurements. Following this topic http://www.esp8266.nu/forum/viewtopic.php?t=190 and changing &svalue to &nvalue did the trick. Sensor is working and sending the right info to Domoticz.

Now my problem is that I can't use the value of the sensor in LUA or Blocky because it sees the sensorvalue as a string with a nill value. Does anyone has a clue on how to fix this? All suggestions are much apreciated!

Bram81
New user
Posts: 8
Joined: 16 Feb 2016, 13:54

SOLVED: How to use analog sensor value in LUA Domoticz

#2 Post by Bram81 » 24 Feb 2016, 19:18

For those who might be interested, I've finaly found a workaround.
By running this .php script in crontab every 10 mins, the value of my virtual sensor is extracted from a json output in which the nvalue of the sensor is visible. Then that value is written to a uservariable in Domoticz, which can be used in events.

Code: Select all

#!/usr/bin/php
<?php

$todomoticz = "http://192.168.2.1:8080/json.htm?type=command&param=updateuservariable&idx=25&vname=Kruiden&vtype=0&vvalue=";
$json_string = file_get_contents("http://192.168.2.1:8080/json.htm?type=devices&rid=138");
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['result'][0];
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['result'][0];
$hum = $parsed_json['Humidity'];


$todomoticz .= $hum;
$todomoticz = str_replace(' ', '_', $todomoticz);
$json = file_get_contents($todomoticz); // send json command to domoticz, and store the reply from domoticz
$parsed = json_decode($json); // process the reply
echo("result of script: " . $parsed->status . "\n"); // report to user
 ?>



Just name it something like variables.php, put the script in your domoticz/script folder and make it executable using chmod +x

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 16 guests