getting value of rain Topic is solved

Moderator: leecollings

Post Reply
JuanUil
Posts: 500
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

getting value of rain

Post 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
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
Toulon7559
Posts: 859
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: <2025
Location: Hengelo(Ov)/NL
Contact:

Re: getting value of rain

Post 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.
Last edited by Toulon7559 on Tuesday 02 May 2017 21:28, edited 2 times in total.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
JuanUil
Posts: 500
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: getting value of rain

Post 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
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
Toulon7559
Posts: 859
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: <2025
Location: Hengelo(Ov)/NL
Contact:

Re: getting value of rain

Post 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 ........
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
JuanUil
Posts: 500
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: getting value of rain

Post 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
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: getting value of rain

Post 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.
Not using Domoticz anymore
JuanUil
Posts: 500
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: getting value of rain

Post by JuanUil »

Thnaks G3ard, I will try this. I will let you know if it works for me.
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
JuanUil
Posts: 500
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: getting value of rain

Post 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
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

getting value of rain

Post 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.
Not using Domoticz anymore
Toulon7559
Posts: 859
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: <2025
Location: Hengelo(Ov)/NL
Contact:

Re: getting value of rain

Post 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.
Last edited by Toulon7559 on Friday 05 May 2017 16:05, edited 2 times in total.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
JuanUil
Posts: 500
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: getting value of rain

Post 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	
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: getting value of rain

Post by G3rard »

Nice! Didn't know that otherdevices_rain and otherdevices_rain_lasthour existed. Much easier indeed ;)
Not using Domoticz anymore
JuanUil
Posts: 500
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: getting value of rain

Post by JuanUil »

this works!
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest