Page 1 of 1

Current Weather DarkSky trigger

Posted: Thursday 26 December 2019 23:49
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>

Re: Current Weather DarkSky trigger  [Solved]

Posted: Friday 27 December 2019 1:22
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
}

Re: Current Weather DarkSky trigger

Posted: Friday 27 December 2019 12:00
by djdevil
Perfect it Work Thx!