Page 1 of 1

getting value of rain

Posted: Tuesday 02 May 2017 20:34
by JuanUil
Hi Folks I have a quibino weatherstation with a rain meter.
Recently I have automated my garden watering with domoticz.
Now I want to get the rainvalue of my rainmeter to decide if I should water the garden or not.

so in my LUA script I have entered:

Code: Select all

Regenval = tonumber(otherdevices_svalues['Regen']}
when I give the print command I don't get any value
So I changed the code to:

Code: Select all

Regenval = otherdevices_svalues['Regen']
In the print command I get :
2017-05-02 20:31:47.984 LUA: Regen= 0;531.3
The actual values when I look in the log of the rainmeter are:
3.5 mm in the last 24 hours with a rate of 0,0 mm.

anyone any idea what I need to do to get the right values?

Thanks in advance
Jan

Re: getting value of rain

Posted: Tuesday 02 May 2017 21:11
by Toulon7559
One question (for better understanding) and one remark:
1) What is the scriptline for your printcommand?
2) Regardless the own log of the rain meter, probably the report to Domoticz is a cumulative value.
2a)If you want to see the resulting svalue before processing or printing, then look in Setup / Devices for the rainmeter, or
alternatively in Setup / More Options / Events / Show current states.
If you take 2 read-outs which are 24hours apart, you should be able to deduct the rain/24hr
2b)That information enables you to derive by script the value/day, value/24hr, latest rain rate, etc., like they do for Domoticz' widgets.

Re: getting value of rain

Posted: Tuesday 02 May 2017 21:25
by JuanUil
Hi Toulon,

Thanks for your reply.
The print command is:

Code: Select all

print('Regen= '..Regenval)

if (Regenval <10) then
	print('Testing')
I do not understand what you mean with your other comment, how can I get these values?

found that, in devices I also get
321 rfxcom 800C 0 Regen Rain TFA 0;531.3

Jan

Re: getting value of rain

Posted: Tuesday 02 May 2017 21:46
by Toulon7559
First try 2a).
If you apply dutch textlayout, choose tab Instellingen, then tab Apparaten, and then look for the rainmeter: in column Data you will find the 2 values.

For 2b) ;-) just start with looking around in this forum for example scriptlines how to extract the separate svalues.
Once you can extract, next step is a script for calculation of rain per interval [which interval may be "today", last 24hrs, last hour or any other interval you want to have].
Generally it means that at a certain time you have to store a reference value (by means of a user value) and from that moment you have to periodically subtract the reference value from the actual value.
Example: for the value of "rain today" you store as reference the cumulative value at 00:00hours, and then each 10 minutes you make the sum.
Calculation of rain/24hrs is a bit more complicated because of the shifting time-window.
;-) Good exercise to learn lua-scripting ........

Re: getting value of rain

Posted: Tuesday 02 May 2017 21:54
by JuanUil
First try 2a).
If you apply dutch textlayout, choose tab Instellingen, then tab Apparaten, and then look for the rainmeter: in column Data you will find the 2 values.

For 2b) ;-) just start with looking around in this forum for example scriptlines how to extract the separate svalues.
Once you can extract, next step is a script for calculation of rain per interval [which interval may be "today", last 24hrs, last hour or any other interval you want to have].
Generally it means that at a certain time you have to store a reference value (by means of a user value) and from that moment you have to periodically subtract the reference value from the actual value.
Example: for the value of "rain today" you store as reference the cumulative value at 00:00hours, and then each 10 minutes you make the sum.
Calculation of rain/24hrs is a bit more complicated because of the shifting time-window.
;-) Good exercise to learn lua-scripting ........
oké I can live with a calculation but how can I get the separate values out of the rainmeter? i.c. 0 and 531.3

Re: getting value of rain

Posted: Wednesday 03 May 2017 0:23
by G3rard
Domoticz indeed shows a cumulative value for the rain in the svalues.
I saw this in the MQTT which I use for the Reacticz dashboard.

I fixed this as follows:
* Make a dummy rain rate sensor
* Run a LUA script with the following code

Code: Select all

if (devicechanged['Regenmeter']) then
    os.execute('curl --url "http://127.0.0.1/fp/php/regenmeter.php" &')
end
* That runs the following php code

Code: Select all

?php
//Update de regenmeter voor Reactiz
//De standaard regenmeter geeft in MQTT een som van de totale regen en dat is niet interessant voor een regenmeter
//Dit script haalt de waardes Rain en Rainrate uit de originele regenmeter en zet die in een nieuwe regenmeter
$domoticz_ip='http://192.168.1.157:8084';
$regenmeter_org=39;
$regenmeter_nieuw=498;
$data=json_decode(file_get_contents($domoticz_ip.'/json.htm?type=devices&rid='.$regenmeter_org),true);
$rain = filter_var($data['result']['0']['Rain']);
$rainrate = filter_var($data['result']['0']['RainRate']);
$rainrate = $rainrate * 100; //this is because of a calculation in Reacticz DeviceWidget.js
//echo $rain;
//echo $rainrate;
$update = file_get_contents($domoticz_ip.'/json.htm?type=command&param=udevice&idx='.$regenmeter_nieuw.'&nvalue=0&svalue='.$rainrate.';'.$rain);
echo "Regenmeter geupdate";
 
Change the devicename, ip, path etc. in the code above. Probably you won't need the line $rainrate = $rainrate * 100; as it is specific for the Reacticz dashboard.
Of course you can also do this completely in LUA.
This will update the values from your rain meter into the dummy rain meter without the cumulative data.

Re: getting value of rain

Posted: Wednesday 03 May 2017 9:28
by JuanUil
Thnaks G3ard, I will try this. I will let you know if it works for me.

Re: getting value of rain

Posted: Wednesday 03 May 2017 21:50
by JuanUil
Hi G3rard,

I have made a dummy rainmeter.
Am I wrong if I say that this gives the same values as my real rainmeter?
As I am not an expert in PHP could you give me details on how to derive the different values in LUA?
The calculation I canmake myself.
Thank you verry much in advance

Jan

getting value of rain

Posted: Wednesday 03 May 2017 22:02
by G3rard
Apparently the dummy rain sensor doesn't use the cumulative value, so this will work (at least over here it does ).
I suggest you first use the php, there are only a few things you need to change in the script. That way you can see if it works.
After that you can change it to Lua if you want. Just search for reading json data in Lua (I would need to do the same). I believe there is a script in this forum which gets data from Google Maps that is in json format.

Re: getting value of rain

Posted: Friday 05 May 2017 15:56
by Toulon7559
The code in this message may give an example how to extract & process rainvalues from rain-info available as svalues in Domoticz from a PWS TFA_Nexus. Assumed that is same for other PWSes.

First you have to identify the svalues-label and link it to the script.
In the example-script that is line

Code: Select all

RainMeter = 'TFA_Nexus_Neerslag'
Next you have to extract the information.
In the example script that happens in lines

Code: Select all

if RainMeter ~= '' then
   WU_URL = WU_URL .. "&dailyrainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain[RainMeter]))
   WU_URL = WU_URL .. "&rainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain_lasthour[RainMeter]))
end
For your application (probably) the interesting 'elements' are

(otherdevices_rain[RainMeter])
(otherdevices_rain_lasthour[RainMeter])

As you can see, a minor but significant difference with the scriptcommands you first tried.

Re: getting value of rain

Posted: Sunday 07 May 2017 12:50
by JuanUil
Toulon7559 wrote:The code in this message may give an example how to extract & process rainvalues from rain-info available as svalues in Domoticz from a PWS TFA_Nexus. Assumed that is same for other PWSes.

First you have to identify the svalues-label and link it to the script.
In the example-script that is line

Code: Select all

RainMeter = 'TFA_Nexus_Neerslag'
Next you have to extract the information.
In the example script that happens in lines

Code: Select all

if RainMeter ~= '' then
   WU_URL = WU_URL .. "&dailyrainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain[RainMeter]))
   WU_URL = WU_URL .. "&rainin=" .. string.format("%2.2f", mmtoInches(otherdevices_rain_lasthour[RainMeter]))
end
For your application (probably) the interesting 'elements' are

(otherdevices_rain[RainMeter])
(otherdevices_rain_lasthour[RainMeter])

As you can see, a minor but significant difference with the scriptcommands you first tried.
Than you very much!!!
This is very simple and it works perfect!!

my code is now:

Code: Select all

-- ~/domoticz/scripts/lua/script_device_Beregenen
commandArray = {}

-- Declaratie variabelen 
--otherdevices_rain[RainMeter])
RegenvalTot 	= tonumber(otherdevices_rain['Regenmeter'])
Regenval	= tonumber(otherdevices_rain_lasthour['Regenmeter'])
uur         = tonumber(os.date("%H"));
min         = tonumber(os.date("%M"));
print('Regen= '..Regenval)


if (RegenvalTot <10) then
	print('Regenval Totaal '..RegenvalTot)
	
	if (uur==20 and min==40 and otherdevices ['Beregening']=='Off')then
			commandArray['Beregening']='On FOR 15' 
	end
end
-- Beregening schakelen
return commandArray	

Re: getting value of rain

Posted: Sunday 07 May 2017 21:52
by G3rard
Nice! Didn't know that otherdevices_rain and otherdevices_rain_lasthour existed. Much easier indeed ;)

Re: getting value of rain

Posted: Friday 29 April 2022 17:21
by JuanUil
this works!