Current Weather DarkSky trigger  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Current Weather DarkSky trigger

Post by djdevil »

Hi I would like starting from the Darksky virtual weather sensor to extrapolate the current weather and based on the climatic conditions trigger an event, paste here an html code that I found on the forum how can I turn it into dzVents thanks

Code: Select all

function updateweather(){
 var url = "http://192.168.178.29:8080/json.htm?type=devices&rid=96";
 var forecast
 xmlhttp.onreadystatechange = function() {
 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 var myArr = JSON.parse(xmlhttp.responseText);
 forecast = myArr.result[0].ForecastStr;
 console.log("Forecast is "+forecast+".")

// myFunction(myArr);
 if (forecast == "Partly Cloudy") {
 
 }
 if (forecast == "Sunny") {
 
 }                                                              
 if (forecast == "Rain") {
 
 }              
 if (forecast == "Fog") {
 
 }                              
 if (forecast == "Snow") {
 
 }
 if (forecast == "Cloudy") {

 }                                              
 }
 }
xmlhttp.open("GET", url, true);
xmlhttp.send();
setTimeout(updateweather,6000);

}
 
 //-->
</script>
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Current Weather DarkSky trigger  [Solved]

Post by waaren »

djdevil wrote: Thursday 26 December 2019 23:49 Hi I would like starting from the Darksky virtual weather sensor to extrapolate the current weather and based on the climatic conditions trigger an event, paste here an html code that I found on the forum how can I turn it into dzVents thanks
This will get you the forecastString from the darksky THB device, the moment it is updated.

Code: Select all

return {
    on = {
        devices = {    'THB' }, --change to name of darksky Temperature, Humidity , barometer device  
    },
    execute = function(dz, item)
        if item.forecastString == 'Rain' then dz.log('do event based on Rain') 
        elseif item.forecastString == 'Sunny'  then  dz.log('do event based on Sunny')
        elseif item.forecastString == 'Partly Cloudy' then dz.log('do event based on Partly Cloudy')
        elseif item.forecastString == 'Fog' then dz.log('do event based on Fog')
        elseif item.forecastString == 'Snow' then dz.log('do event based on Snow')
        elseif item.forecastString == 'Cloudy' then dz.log('do event based on Cloudy')
        else 
            dz.log('do event based on unknown forecast')
         end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Current Weather DarkSky trigger

Post by djdevil »

Perfect it Work Thx!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest