I have a sonoff basic switch loaded with ESP Easy, which works fine using the timer in domoticz. My goal is trying to turn on the switch at a prescribed time only if certain weather conditions are met, such as if the wind is less than x Km/h and or temp is in a certain range (whatever it is in the weather forecast section of the Domoticz). Is this possible?
Thanks a million.
Turn on/off switches based on Weather
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Turn on/off switches based on Weather
Should be possible with a script. Domoticz retrieve the data used in the forecast from https://forecast.io/forecast?q=<lat,lon>jackwan1 wrote: ↑Saturday 24 October 2020 4:03 My goal is trying to turn on the switch at a prescribed time only if certain weather conditions are met, such as if the wind is less than x Km/h and or temp is in a certain range (whatever it is in the weather forecast section of the Domoticz). Is this possible?
Weather forecasts available are current, hourly and daily. (hourly forecasts: 48, daily forecasts: 8)
- Spoiler: show
- what is the name of the switch that needs to be controlled?
- what time(s) should the script run?
- what are the (forecasted weather) criteria that need to be evaluated?
- types?
- how far in the future?
- average or extremes?
- what values do you want the switch to be Off/On?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 41
- Joined: Saturday 15 April 2017 20:04
- Target OS: Linux
- Domoticz version: 2020.2
- Location: USA
- Contact:
Re: Turn on/off switches based on Weather
Thank you and to answer your question @waaren
1. By name of the switch do you mean the name of the virtual switch? Its called sonoff7 idx 13 its always off with a weekly on time
2. Time, will be weekly, Friday, at 17:00 on and off 15 min. Later or Saturday the same time if the Friday weather is too windy
3. Weather condition is current Wind <2mph then switch on otherwise skip
1. By name of the switch do you mean the name of the virtual switch? Its called sonoff7 idx 13 its always off with a weekly on time
2. Time, will be weekly, Friday, at 17:00 on and off 15 min. Later or Saturday the same time if the Friday weather is too windy
3. Weather condition is current Wind <2mph then switch on otherwise skip
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Turn on/off switches based on Weather
Can you try below script?jackwan1 wrote: ↑Saturday 24 October 2020 16:40 Thank you and to answer your question @waaren
1. By name of the switch do you mean the name of the virtual switch? Its called sonoff7 idx 13 its always off with a weekly on time
2. Time, will be weekly, Friday, at 17:00 on and off 15 min. Later or Saturday the same time if the Friday weather is too windy
3. Weather condition is current Wind <2mph then switch on otherwise skip
_____________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
_____________________________________________________________________________________________________________________________
Code: Select all
--[[
This script collects weather forecast data from https://forecast.io/forecast?q=<lat,lon>&lang=en-us&units=auto // based on your location
Please note that dzVents requires acces to domoticz at a sufficient level to retrieve the location settings
including the latititude and longitude. It can only get these if the Local Networks (no username/password)
include 127.0.0.1 (or ::1 for systems using IPv6)
Explained in the wiki at: https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting#Using_dzVents_with_Domoticz
original script posted: https://www.domoticz.com/forum/viewtopic.php?f=11&t=34308&p=259306#p259306
history
20201024 Start coding - shared on forum
]]--
local scriptVar = 'ForecastIO'
return
{
on = {
timer =
{
'at 17:00 on fri,sat' -- change to time(s) you want this script to execute
},
devices =
{
'trigger' .. scriptVar, -- just for test. Can be ignored
},
httpResponses =
{
scriptVar,
},
},
data =
{
actioned =
{
initial = false,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.ERROR when script works as designed
marker = scriptVar,
},
execute = function(dz, item)
-- ******** Your settings below this line
weeklySwitch = dz.devices('sonoff7') -- set to name of switch you want to control
maxWindSpeed = 2 -- Check this as it seems quite low
-- ******** No changes required below this line
local forecastURL = 'https://forecast.io/forecast?lang=en-us&units=us&q='
local function sendURL()
dz.openURL(
{
url = forecastURL .. dz.settings.location.latitude .. ',' .. dz.settings.location.longitude ,
callback = scriptVar, -- see httpResponses above.
})
end
local function processReturn(t)
dz.log('current windSpeed is ' .. t.windSpeed, dz.LOG_DEBUG )
if t.windSpeed <= maxWindSpeed then -- if friday and saturday too windy then no action at all. Is this correct?
weeklySwitch.switchOn()
weeklySwitch.switchOff().afterMin(15)
dz.data.actioned = true
end
end
-- main code
if item.isHTTPResponse then
if item.ok and item.isJSON then
processReturn(item.json.currently)
else
dz.log('There was a problem with the response from ' .. scriptVar, dz.LOG_ERROR)
dz.log(item, dz.LOG_DEBUG)
end
else -- get the data from forecastIO
-- if dz.time.matchesRule('on fri') then
if dz.time.matchesRule('on fri') then
sendURL()
dz.data.actioned = false
elseif dz.data.actioned ~= true then -- no action was done on Friday
sendURL()
end
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 41
- Joined: Saturday 15 April 2017 20:04
- Target OS: Linux
- Domoticz version: 2020.2
- Location: USA
- Contact:
Re: Turn on/off switches based on Weather
Thank you @waaren
I will try that
I will try that
Who is online
Users browsing this forum: No registered users and 1 guest