Is it gonna rain within the next X minutes?

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

josimd
Posts: 59
Joined: Saturday 09 January 2016 19:47
Target OS: -
Domoticz version:
Contact:

Re: Is it gonna rain within the next X minutes?

Post by josimd »

How do I know if the lua script is running? Script is located in domoticz\scripts\lua
BarryT
Posts: 358
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by BarryT »

josimd wrote:How do I know if the lua script is running? Script is located in domoticz\scripts\lua
In the log of domoticz?
Raspberry / ESP Boards / Relais / Milight / Hue / OTGW / P1 / Xiaomi / RFXCom / RFLink / ZWave / Conbee II / Z2M / MQTT / A lot of scripts and many more..
Software: Linux, Android and Windows
BarryT
Posts: 358
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by BarryT »

mlamie wrote:I checked the scripts used by me and they both do not have the 5 in the line as you mentioned...

Code: Select all

read = os.execute('curl -s -o '..tempfilename..' "'..url..'"')
Since I'm not a programmer is there someone willing to check, validate both scripts (wiki = switch device and this forum = text device). For now I have update the wiki page, but duplicates and inconsistencies in both scripts can be deleted I expect.

http://www.domoticz.com/wiki/Is_it_gonna_rain
Good job, but you can also do it this all in 1 script..
Please look a couple messages back, its written as 1 script with 3 options:
Device on/off
Text device
Send notification

If you need help let me know :)
Last edited by BarryT on Tuesday 09 May 2017 20:46, edited 1 time in total.
Raspberry / ESP Boards / Relais / Milight / Hue / OTGW / P1 / Xiaomi / RFXCom / RFLink / ZWave / Conbee II / Z2M / MQTT / A lot of scripts and many more..
Software: Linux, Android and Windows
User avatar
mlamie
Posts: 122
Joined: Friday 25 October 2013 17:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: The Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by mlamie »

josimd wrote:How do I know if the lua script is running? Script is located in domoticz\scripts\lua
If all ok, you should see these lines in the log under status tab.
Image
Raspberry Pi 3, RaZberry, RFXtrx433
Various Z-Wave devices, KlikAanKlikUit devices, ESP8266 NodeMCU, Sonoff POW and a Essent E-thermostaat
IP camera: Dahua 4MP IPC-HDBW4421R-AS, Vivotek FD8134V
User avatar
mlamie
Posts: 122
Joined: Friday 25 October 2013 17:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: The Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by mlamie »

BarryT wrote:
mlamie wrote:I checked the scripts used by me and they both do not have the 5 in the line as you mentioned...

Code: Select all

read = os.execute('curl -s -o '..tempfilename..' "'..url..'"')
Since I'm not a programmer is there someone willing to check, validate both scripts (wiki = switch device and this forum = text device). For now I have update the wiki page, but duplicates and inconsistencies in both scripts can be deleted I expect.

http://www.domoticz.com/wiki/Is_it_gonna_rain
Good job, but you can also do it this all in 1 script..
Please look a couple messages back, its written as 1 script with 3 options:
Device on/off
Text device
Send notification

If you need help let me know :)
Hi BarryT, if you can help that is appreciated. Are you able to combine the suggested improvements in a single script then I will update the wiki. P.s. I also see that the rain.tmp file is updated each minute...

In this post 'zicht' suggest to not use a tmp file...
http://www.domoticz.com/forum/viewtopic ... 40#p128588
In this post it is mentioned not all 3 devices are working as expected.
http://www.domoticz.com/forum/viewtopic ... 60#p130239

So I'm a bit dazzled.
Raspberry Pi 3, RaZberry, RFXtrx433
Various Z-Wave devices, KlikAanKlikUit devices, ESP8266 NodeMCU, Sonoff POW and a Essent E-thermostaat
IP camera: Dahua 4MP IPC-HDBW4421R-AS, Vivotek FD8134V
josimd
Posts: 59
Joined: Saturday 09 January 2016 19:47
Target OS: -
Domoticz version:
Contact:

Re: Is it gonna rain within the next X minutes?

Post by josimd »

BarryT wrote:
josimd wrote:How do I know if the lua script is running? Script is located in domoticz\scripts\lua
In the log of domoticz?
No info found in "Instellingen / Log" also no errors....
User avatar
mlamie
Posts: 122
Joined: Friday 25 October 2013 17:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: The Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by mlamie »

josimd wrote:
BarryT wrote:
josimd wrote:How do I know if the lua script is running? Script is located in domoticz\scripts\lua
In the log of domoticz?
No info found in "Instellingen / Log" also no errors....
Can you put the script in the events under Domoticz and see if that will result a status log update?

Image
Raspberry Pi 3, RaZberry, RFXtrx433
Various Z-Wave devices, KlikAanKlikUit devices, ESP8266 NodeMCU, Sonoff POW and a Essent E-thermostaat
IP camera: Dahua 4MP IPC-HDBW4421R-AS, Vivotek FD8134V
krizzz
Posts: 200
Joined: Wednesday 20 November 2013 20:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by krizzz »

ok...@BarryT, thanks for your help. Highly apreciated. The basic script is up and running! Now I am trying to add notification in the script and that doesnt work,........YET! Again. Thanks.
josimd
Posts: 59
Joined: Saturday 09 January 2016 19:47
Target OS: -
Domoticz version:
Contact:

Re: Is it gonna rain within the next X minutes?

Post by josimd »

mlamie wrote:
josimd wrote:
BarryT wrote: In the log of domoticz?
No info found in "Instellingen / Log" also no errors....
Can you put the script in the events under Domoticz and see if that will result a status log update?

Image
Txs...it's working now..
User avatar
gielie
Posts: 290
Joined: Tuesday 12 January 2016 11:40
Target OS: Raspberry Pi / ODroid
Domoticz version: latest β
Location: The Netherlands (Alkmaar)
Contact:

Re: Is it gonna rain within the next X minutes?

Post by gielie »

I use the following code in my rain code

Code: Select all

if (RainPrediction > 20  ) then
      verw = 3
      RainPredictionText=('('..round(RainmmHour, 1)..' mm) regen verwacht!')
      commandArray['SendNotification']='Regenscript#Regen verwacht'
      commandArray['Regenverwacht']='On'
   else 
      verw = 2
      RainPredictionText=('Voorlopig blijft het droog!')
   --commandArray['SendNotification']='Regenscript#Geen regen meer verwacht'
      commandArray['Regenverwacht']='Off'
   end
Tise part

Code: Select all

--commandArray['SendNotification']='Regenscript#Geen regen meer verwacht'
is disabled otherwise i get an message every minute when its not raining, but, when it IS raining i do get a message every minute, is it possible to change this is only once when it start to rain or when something changes?
- Aeon Labs USB Stick met Z-wave plus
- Aeotec MultiSensor 6
- FIBARO FGS223
- FIBARO FGWPE Wall Plug
- Neo CoolCam Power plug
- Popp Smoke Detector
- Toon
- Kodi Media Server
User avatar
mlamie
Posts: 122
Joined: Friday 25 October 2013 17:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: The Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by mlamie »

Weird, I used both scripts as mentioned on the wiki page and don't have any issue.
http://www.domoticz.com/wiki/Is_it_gonna_rain

Did you make is a time driven script or is it a device change driven script?
Raspberry Pi 3, RaZberry, RFXtrx433
Various Z-Wave devices, KlikAanKlikUit devices, ESP8266 NodeMCU, Sonoff POW and a Essent E-thermostaat
IP camera: Dahua 4MP IPC-HDBW4421R-AS, Vivotek FD8134V
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Is it gonna rain within the next X minutes?

Post by poudenes »

Does anybody got suddenly the follow error as well:

string "local RainTextIDX = 232 -- your domoticz te..."]:26: attempt to perform arithmetic on global 'rain' (a nil value)
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
HansieNL
Posts: 957
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Is it gonna rain within the next X minutes?

Post by HansieNL »

poudenes wrote:Does anybody got suddenly the follow error as well:

string "local RainTextIDX = 232 -- your domoticz te..."]:26: attempt to perform arithmetic on global 'rain' (a nil value)
I got this one again "Error: EventSystem: Warning!, lua script /home/pi/domoticz/scripts/lua/script_time_rain.lua has been running for more than 10 seconds"
Blah blah blah
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by jvdz »

As stated before: you really shouldn't be running this with the event system as it is single threaded making the even system unresponsive during the run of this script.
I have a variation of the script running in the background as a CRON scheduled task and is running fine for quite a while now.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
HansieNL
Posts: 957
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Is it gonna rain within the next X minutes?

Post by HansieNL »

jvdz wrote:As stated before: you really shouldn't be running this with the event system as it is single threaded making the even system unresponsive during the run of this script.
I have a variation of the script running in the background as a CRON scheduled task and is running fine for quite a while now.

Jos
Interesting... are you willing to share your script?
Blah blah blah
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by jvdz »

HansieNL wrote: Interesting... are you willing to share your script?
Of course: This is the script I have and it feed both a Rain and a percentage device. In case you don't want the percentage chance of rain device you need to remove the code at the bottom of the lua which tries to update that.
The filename and crontab task are listed in the source.
Just update the information in the top part and check if you want both devices to be fed with information.

Jos

Code: Select all

-------------------------------------------------------------------
---  Get rain info from buienradar for the next xx minutes
---
--- Crontab task:  */5 * * * * sudo lua /home/pi/domoticz/scripts/buienradar_rainprediction.lua >> /var/tmp/BRP.log
-- config ---------------------------------------------------------
lat='5?.??'
lon='4.??'
-- use information for the next xx minutes
minutesinfuture=15
-- Domoticz server url
domoticzurl="http://192.168.0.??:8080"
-- rain device
DEVIDX=???
-- General Percentage device
PDEVIDX=???
-- set to true or false
debug=true
-- set to the appropriate tmp path
tempfilename = '/var/tmp/rain.tmp' -- can be anywhere writeable
-- config ---------------------------------------------------------
-- http://gadgets.buienradar.nl/data/raintext?lat=5?.??&lon=4.??
--
-- url='http://gps.buienradar.nl/getrr.php?lat='..lat..'&lon='..lon  -- old link
url='http://gadgets.buienradar.nl/data/raintext?lat='..lat..'&lon='..lon
if debug then print(url) end
read = os.execute('curl -Lo '..tempfilename..' "'..url..'"')
file = io.open(tempfilename, "r")
totalrain=0
rainlines=0
-- now analyse the received lines, format is like 000|15:30 per line.
while true do
	line = file:read("*line")
	if not line then break end
	linetime=string.sub(tostring(line), 5, 9)
	-- Linetime2 holds the full date calculated from the time on a line
	linetime2 = os.time{year=os.date('%Y'), month=os.date('%m'), day=os.date('%d'), hour=string.sub(linetime,1,2), min=string.sub(linetime,4,5), sec=os.date('%S')}
	difference = os.difftime (linetime2,os.time())

	-- When a line entry has a time in the future AND is in the given range, then totalize the rainfall
	if ((difference >= 20) and (difference<=minutesinfuture*60)) then
		rain=tonumber(string.sub(tostring(line), 0, 3))
		totalrain = totalrain+rain
		rainlines=rainlines+1
		if debug then print('Rain in timerange: '..rain .. '   Total rain now: '..totalrain .. '   difference:' .. difference .. '    Line:' ..line ) end
	end

end
file:close()

-- Returned value is average rain fall for next time
-- 0 is no rain, 255 is very heavy rain
-- When needed, mm/h is calculated by 10^((value -109)/32) (example: 77 = 0.1 mm/hour)
if rainlines == 0 then
	averagerain=0
else
	averagerain=math.ceil(totalrain/rainlines)
end

function round(num, idp)
  return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end
-- Calculate the mm/h
calcmmh = round(10^((averagerain -109)/32),2)
if debug then print(os.date() .. "  averagerain:" .. averagerain .. "  calcmmh:" .. calcmmh) end

-- Update Domotics Devices
url=domoticzurl..'/json.htm?type=command&param=udevice&idx=' .. DEVIDX .. '&nvalue=0&svalue=' .. calcmmh .. ';' .. calcmmh
if debug then print(url) end
read = os.execute('curl -s "'..url..'"')
if debug then print(read) end

-- Update percentage regenkans Domotics Device ---------------
result = round(averagerain*0.392156862745098,2)
url=domoticzurl..'/json.htm?type=command&param=udevice&idx=' .. PDEVIDX .. '&nvalue=0&svalue=' .. result
if debug then print(url) end
read = os.execute('curl -s "'..url..'"')
if debug then print(read) end
if debug then print('==> Rain chance: '..result .. '%') end
-- end update percentage device -------------------------------------
if debug then print('------------------------------------------------------------------------------------------------------------------------------------------') end
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Is it gonna rain within the next X minutes?

Post by poudenes »

jvdz wrote:As stated before: you really shouldn't be running this with the event system as it is single threaded making the even system unresponsive during the run of this script.
I have a variation of the script running in the background as a CRON scheduled task and is running fine for quite a while now.

Jos
So its better to have a script running outside Domoticz? I have also some scripts running inside Domoticz...
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Is it gonna rain within the next X minutes?

Post by poudenes »

Hi All,

Moves the LUA script from inside Domoticz into the /scripts/lua/ location to see if some errors will stop. But there still there:

Code: Select all

2017-05-17 06:42:10.435 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 06:45:10.346 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 06:49:10.404 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 06:52:10.189 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 06:59:10.377 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 07:05:10.435 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 07:07:10.172 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 07:11:10.352 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 07:16:10.178 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 07:31:10.258 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 07:33:10.479 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 07:36:10.460 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 07:44:10.252 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 07:46:10.482 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 07:54:10.126 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 08:03:10.369 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
2017-05-17 08:12:10.421 Error: EventSystem: Warning!, lua script /home/osmc/domoticz/scripts/lua/script_time_regen.lua has been running for more than 10 seconds
This is the script im using:

Code: Select all

local RainTextIDX = 233   -- your domoticz text device
local checktime = 300
debug = false -- enable or disable debug output
tempfilename = '/home/osmc/domoticz/temp/Rain120.tmp' -- be sure this is in the correct map, and give it chmod 0666
totalrain = 0
rainlines = 0

function IsItGonnaRain( minutesinfuture )
   url='http://gpsgadget.buienradar.nl/data/raintext/?lat=52.33&lon=4.87' -- this is important!! change the lat and lon to your needs!!
   if debug then print(url) end
read = os.execute('curl --connect-timeout 3 -s -o '..tempfilename..' "'..url..'"')
file = io.open(tempfilename, "r")

   while true do
      line = file:read("*line")
      if not line then break end
      if debug then print('Line:'..line) end
      linetime=string.sub(tostring(line), 5, 9)
      if debug then print('Linetime: '..linetime) end

      linetime2 = os.time{year=os.date('%Y'), month=os.date('%m'), day=os.date('%d'), hour=string.sub(linetime,1,2), min=string.sub(linetime,4,5), sec=os.date('%S')}
      difference = os.difftime (linetime2,os.time())

      if ((difference > 0) and (difference<=minutesinfuture*60)) then
         if debug then print('Line in time range found') end
         rain=tonumber(string.sub(tostring(line), 0, 3))
         totalrain = totalrain+rain
         rainlines=rainlines+1
         if debug then print('Rain in timerange: '..rain) end
         if debug then print('Total rain now: '..totalrain) end
      end

   end
   file:close()

   averagerain=totalrain/rainlines
   return(averagerain)
end

function round(num, idp)
   local mult = 10^(idp or 0)
   return math.floor(num * mult + 0.5) / mult
end

commandArray = {}
   minuten=120
   RainPrediction = IsItGonnaRain(minuten)
   RainmmHour=10^((RainPrediction-109)/32)

   if (RainPrediction > 20  ) then
      verw = 3
      RainPredictionText=(''..round(RainmmHour, 1)..' mm regen verwacht!')
   else
      verw = 2
      RainPredictionText=('Het blijft droog!')
   end

   commandArray[2] = {['UpdateDevice'] = RainTextIDX .. '|0|' .. tostring(RainPredictionText)}

return commandArray

My Internet connection is stable (VPN on mac is always on without disconnections) and speed is around 90-100Mbit/sec

Can someone help me or tell me why this error is still there?
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
bertbigb
Posts: 147
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by bertbigb »

I have the feeling that you didn't understood the instructions quite well.
This script shouldn't run like a so-called time or device script.
It is a script you fire from crontab at regular times. So to provide more help I would like to know the full path and name of the script. Make sure the script is disabled in the domoticz event screen. Ad the script to your crontab and fire it. Let's see what happens.


Verzonden vanaf mijn iPhone met Tapatalk
Best regards Bert

Synology DS1517+ - DSM 6.2
Raspberry PI2-B, Raspberry Nano - Raspberry PI3 - model B
Xiaomi Gateway - Philips HUE Lights - Zwave - RFXCom(E) with KaKu and other 433MHz devices - Yeelight Lights - Toon
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Is it gonna rain within the next X minutes?

Post by poudenes »

bertbigb wrote:I have the feeling that you didn't understood the instructions quite well.
This script shouldn't run like a so-called time or device script.
It is a script you fire from crontab at regular times. So to provide more help I would like to know the full path and name of the script. Make sure the script is disabled in the domoticz event screen. Ad the script to your crontab and fire it. Let's see what happens.


Verzonden vanaf mijn iPhone met Tapatalk
Clear answer. I will add it to crontab and see what happens
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest