updateWeatherSensors (yet another buienradar script)

User avatar
EdwinK
Posts: 1209
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: updateWeatherSensors (yet another buienradar script)

Post by EdwinK » Sunday 13 May 2018 15:11

waaren wrote:
Sunday 13 May 2018 13:39
EdwinK wrote:
Sunday 13 May 2018 12:50
[For 'pollen' I use https://www.weeronline.nl/Europa/Nederl ... on/4057944 as an iframe within Dashticz. Not sure if it has a json or other output.
@Edwink,

thx but I don't know how to process the information from that site given the format it is presented in. For now I only process data that is presented in JSON or plain text format. If required I probably could also add some functions to process XML but processing HTML to get the required information is more than 1 bridge too far for my programming skills.
Too bad, but understandable. Will keep using it the way it is now. Who knows, someone else can work this.
Running latest BETA on a Pi-3 | Toon Thermostat | RFxcom | Dashticz V2 |

patzzz
Posts: 2
Joined: Friday 06 April 2018 23:19
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: updateWeatherSensors (yet another buienradar script)

Post by patzzz » Sunday 08 July 2018 11:31

Feature request:
It would be nice if the script created a virtual device or environment variable which contains the amount of rain fallen in the last 12 hours.
So I can use that to decide whether or not my garden irrigation should turn on today or not.
Then I would combine that information with the amount of sunhours of (say) 25+ degrees celcius and I can water my garden only when needed.

User avatar
waaren
Posts: 718
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: updateWeatherSensors (yet another buienradar script)

Post by waaren » Sunday 08 July 2018 15:09

patzzz wrote:
Sunday 08 July 2018 11:31
Feature request:
It would be nice if the script created a virtual device or environment variable which contains the amount of rain fallen in the last 12 hours.
So I can use that to decide whether or not my garden irrigation should turn on today or not.
Then I would combine that information with the amount of sunhours of (say) 25+ degrees celcius and I can water my garden only when needed.
My preference is to do this with this (separate) script that can also be used by anyone who updates their rainsensors by other scripts / hardware.

moved to new topic http://www.domoticz.com/forum/viewtopic ... 72&t=24113
Last edited by waaren on Monday 09 July 2018 7:25, edited 2 times in total.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

User avatar
EdwinK
Posts: 1209
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: updateWeatherSensors (yet another buienradar script)

Post by EdwinK » Sunday 08 July 2018 20:08

waaren wrote:
Sunday 08 July 2018 15:09
patzzz wrote:
Sunday 08 July 2018 11:31
Feature request:
It would be nice if the script created a virtual device or environment variable which contains the amount of rain fallen in the last 12 hours.
So I can use that to decide whether or not my garden irrigation should turn on today or not.
Then I would combine that information with the amount of sunhours of (say) 25+ degrees celcius and I can water my garden only when needed.
My preference is to do this with this (separate) script that can also be used by anyone who updates their rainsensors by other scripts / hardware.
Spoiler: show

Code: Select all

-- setRainVar.lua for [ dzVents >= 2.4 ] 
-- Before first execution create var "amountOfRainDuringLastHours" as type float

return {
    on      =   {   timer           =   { "every hour" },                       -- Triggers the getJsonPart
                    httpResponses   =   { "setRainVar" }                        -- Trigger the handle Json part
                },
                
    logging =   {   level     =   domoticz.LOG_DEBUG,
                    marker    =   "setRainVar"    },

    execute = function(dz,trigger)

        local rainDevice    = dz.devices(128)                                 -- name enclosed in quotes or number without quotes
        local rainVar       = dz.variables("amountOfRainDuringLastHours")     -- name enclosed in quotes or number without quotes 
        local relevantHours = 12                                              -- below 24 we get the (graph) values for a day, above 23 we use year  
        local range         = "day"
        if relevantHours > 23 then range = "year" end 
        
        local function triggerJSON()
            local  URLString   = dz.settings['Domoticz url'] .. "/json.htm?type=graph&sensor=rain&idx=" .. rainDevice.idx .. "&range=" .. range 
            dz.openURL({    url = URLString,
                            method = "GET",
                            callback = "setRainVar" })                      
        end

        local function setVar()
            local Time = require('Time')
            local now  = Time()
            local relevantAmount = 0 
            local delta,t

            rt = trigger.json.result
            if range == "year" then timeCompletion = " 00:00:00" else timeCompletion = ":00" end
                
            for i=1,#rt do                                 -- Loop through the result
                t = Time(rt[i].d .. timeCompletion)        -- get time and prepare for compare
                delta = (t.compare(now).hours)             -- diff in hours between json record and now

                if delta <= relevantHours then
                    relevantAmount = relevantAmount + tonumber(rt[i].mm) 
                    dz.log(     "Date/time: " .. rt[i].d .. " ===>> Value in mm " .. 
                                rt[i].mm .. " ===>> Delta hours: "  .. delta .. 
                                " ===>> Total until now: " .. relevantAmount
                                ,dz.LOG_DEBUG)
                end    
            end
            rainVar.set(relevantAmount)   -- Store value in uservariable
        end
        
        if trigger.isTimer or trigger.isDevice then
            triggerJSON()
        elseif trigger.ok then                                      -- statusCode == 2xx
            setVar()
        else
            dz.log("No valid response from domoticz",dz.LOG_ERROR)
        end
    end
}
Spoiler: show

Code: Select all

 setRainVar: An error occured when calling event handler Neerslag
2018-07-08 20:06:02.256 Status: dzVents: Error (2.4.6): setRainVar: .../domoticz/scripts/dzVents/generated_scripts/Neerslag.lua:36: attempt to get length of global 'rt' (a nil value)
What am I doing wrong, or is this because we didn't have rain for some time now?
Running latest BETA on a Pi-3 | Toon Thermostat | RFxcom | Dashticz V2 |

User avatar
waaren
Posts: 718
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: updateWeatherSensors (yet another buienradar script)

Post by waaren » Sunday 08 July 2018 23:45

EdwinK wrote:
Sunday 08 July 2018 20:08

Code: Select all

 setRainVar: An error occured when calling event handler Neerslag
2018-07-08 20:06:02.256 Status: dzVents: Error (2.4.6): setRainVar: .../domoticz/scripts/dzVents/generated_scripts/Neerslag.lua:36: attempt to get length of global 'rt' (a nil value)
What am I doing wrong, or is this because we didn't have rain for some time now?
@EdwinK, No rain should not cause this error.
Could it be that the deviceName or IDX for rainDevice you are using is not of the type rain or that it is just created and /or no values are in the history in the hours to be reported (yet) ?

If it is of type rain and already in use for > 1 hour can you check the result of

http://domoticzIP:domoticzPort/json.htm?type=graph&sensor=rain&idx=nnn&range=day

Updated script at http://www.domoticz.com/forum/viewtopic ... 72&t=24113
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

User avatar
EdwinK
Posts: 1209
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: updateWeatherSensors (yet another buienradar script)

Post by EdwinK » Monday 09 July 2018 14:11

Will reply in the new topic ;), to keep this clean
Running latest BETA on a Pi-3 | Toon Thermostat | RFxcom | Dashticz V2 |

schulpr
Posts: 119
Joined: Thursday 01 January 2015 10:10
Target OS: NAS (Synology & others)
Domoticz version: Beta
Contact:

Re: updateWeatherSensors (yet another buienradar script)

Post by schulpr » Tuesday 17 July 2018 17:53

Hi,

A few times per day I get the following error message:
2018-07-17 14:48:05.367 Error: Error opening url: https://gadgets.buienradar.nl/data/rain ... 2&lon=5.47
2018-07-17 14:48:05.730 Error: dzVents: Error (2.4.7): WUS: [0006] Er is een probleem met inlezen van de data; controleer wat er fout is gegaan. in:WUS_rainForecastResponse, Error: 11699956
I assume that certain data is not available when the script runs. Is there a way to prevent this. Perhaps use the old data if the new is not available?

Kind regards, Rob

User avatar
waaren
Posts: 718
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: updateWeatherSensors (yet another buienradar script)

Post by waaren » Tuesday 17 July 2018 21:21

schulpr wrote:
Tuesday 17 July 2018 17:53
Hi,

A few times per day I get the following error message:
2018-07-17 14:48:05.367 Error: Error opening url: https://gadgets.buienradar.nl/data/rain ... 2&lon=5.47
2018-07-17 14:48:05.730 Error: dzVents: Error (2.4.7): WUS: [0006] Er is een probleem met inlezen van de data; controleer wat er fout is gegaan. in:WUS_rainForecastResponse, Error: 11699956
I assume that certain data is not available when the script runs. Is there a way to prevent this. Perhaps use the old data if the new is not available?

Kind regards, Rob
@schulpr

Rob, the first errormessage is from the main domoticz process telling us that the url could not be reached. I see this a couple of times a day. dzVents cannot check before firing the openURL that it will be successful so I cannot think of a way to prevent this.
The second errormessage is from dzVents telling that the return from the openURL contains no valid data and could not be processed. The design choice for this script is to ignore this and leave all values in the virtual sensors and switched as they were set in the previous run.
I assume that this is relative safe choice if we don't see these error messages flooding the logs.
Hope this clarifies
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

schulpr
Posts: 119
Joined: Thursday 01 January 2015 10:10
Target OS: NAS (Synology & others)
Domoticz version: Beta
Contact:

Re: updateWeatherSensors (yet another buienradar script)

Post by schulpr » Wednesday 18 July 2018 6:49

Hi @waaren,

Thanks for clarifying this. It's no problem but I like a clean error log .

Kind regards,

Rob


Verzonden vanaf mijn iPad met Tapatalk

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests