Need help with sunscreen script [Solved]
Moderator: leecollings
-
- Posts: 68
- Joined: Sunday 10 June 2018 16:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Need help with sunscreen script
Since I can't make such a script with blockly cause of the multiple 'if' I need some help with dzvents. Did some reading on wiki and the forum but guess I'm not much of a script writer.
The weather conditions are from darksky
What I want to create is the following:
If
'zonnescherm' is closed
Time is between 11.30 and sunset
Date is between 1 april and 30 september
'Windsnelheid Assen' <8
'UV Index Assen' >1
'Regen voorspelling Assen' <1
Then
Set 'Zonnescherm' On
If 'Zonnescherm' is On and one of the conditions changing, 'Zonnescherm' should close. (Off)
Not sure if I'm missing something.
Who can help me with creating this?
The weather conditions are from darksky
What I want to create is the following:
If
'zonnescherm' is closed
Time is between 11.30 and sunset
Date is between 1 april and 30 september
'Windsnelheid Assen' <8
'UV Index Assen' >1
'Regen voorspelling Assen' <1
Then
Set 'Zonnescherm' On
If 'Zonnescherm' is On and one of the conditions changing, 'Zonnescherm' should close. (Off)
Not sure if I'm missing something.
Who can help me with creating this?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Need help with sunscreen script
Could be something like this
Code: Select all
-- sunProtection.lua
return {
on = { timer = {"every 10 minutes between 11:30 and 10 minute after sunset on 1/4-30/9"}},
logging = { level = domoticz.LOG_DEBUG,
marker = "Sunscreen" },
execute = function(dz)
local sunscreen = dz.devices(###) -- replace ### by your sunscreen device IDX
local windSpeed = dz.devices(###).speed -- replace ### by your virtual wind device IDX
local UV = dz.devices(###).uv -- replace ### by your virtual UV device IDX
local rainPrediction = tonumber(dz.devices(###).state) -- replace ### by your virtual rainprediction device IDX
local OnConditionsMet = sunscreen.state == "Open" and -- Maybe you need to reverse this to ~= or to "Closed"
windSpeed < 8 and
UV > 1 and
rainPrediction < 1 and
dz.time.matchesRule("between 11:30 and sunset")
if OnConditionsMet then
sunscreen.switchOff()
else
sunscreen.switchOn().checkFirst()
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: 68
- Joined: Sunday 10 June 2018 16:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Need help with sunscreen script
That looks good.waaren wrote: ↑Tuesday 09 October 2018 21:10Could be something like this
Code: Select all
-- sunProtection.lua return { on = { timer = {"every 10 minutes between 11:30 and 10 minute after sunset on 1/4-30/9"}}, logging = { level = domoticz.LOG_DEBUG, marker = "Sunscreen" }, execute = function(dz) local sunscreen = dz.devices(###) -- replace ### by your sunscreen device IDX local windSpeed = dz.devices(###).speed -- replace ### by your virtual wind device IDX local UV = dz.devices(###).uv -- replace ### by your virtual UV device IDX local rainPrediction = tonumber(dz.devices(###).state) -- replace ### by your virtual rainprediction device IDX local OnConditionsMet = sunscreen.state == "Open" and -- Maybe you need to reverse this to ~= or to "Closed" windSpeed < 8 and UV > 1 and rainPrediction < 1 and dz.time.matchesRule("between 11:30 and sunset") if OnConditionsMet then sunscreen.switchOff() else sunscreen.switchOn().checkFirst() end end }
I've spend the intire evening on this script.
Code: Select all
return {
on = {
timer = { 'on 1/4-30/9 between 11:30 and sunset' },
},
execute = function (domoticz, item)
if item.isTimer and
domoticz.devices('Test lamp').state == "On" and
domoticz.devices('UV Index Assen').uv >0 then
domoticz.devices('Dummy Zonnescherm').switchOn()
else
domoticz.devices('Dummy Zonnescherm').switchOff()
end
end
}
Also need to work out how to get a message when the sunscreen is set to off, and which variable causes it.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Need help with sunscreen script
Does this help ?
Code: Select all
-- sunProtection.lua
return {
on = { timer = {"every 10 minutes between 11:30 and 10 minute after sunset on 1/4-30/9"}},
logging = { level = domoticz.LOG_DEBUG,
marker = "Sunscreen" },
execute = function(dz)
local sunscreen = dz.devices(###) -- replace ### by your sunscreen device IDX
local windSpeed = dz.devices(###).speed -- replace ### by your virtual wind device IDX
local UV = dz.devices(###).uv -- replace ### by your virtual UV device IDX
local rainPrediction = tonumber(dz.devices(###).state) -- replace ### by your virtual rainprediction device IDX
local OnConditionsMet = sunscreen.state == "Open" and -- Maybe you need to reverse this to ~= or to "Closed"
windSpeed < 8 and
UV > 1 and
rainPrediction < 1 and
dz.time.matchesRule("between 11:30 and sunset")
if OnConditionsMet then
sunscreen.switchOff()
else
if sunscreen.state == "Closed " then
sunscreen.switchOn()
if windSpeed >= 8 then dz.notify(sunscreen.name .. " closed because of windspeed " .. windSpeed)
elseif UV <= 1 then dz.notify(sunscreen.name .. " closed because of UV " .. UV)
elseif rainPrediction >= 1 then dz.notify(sunscreen.name .. " closed because of rainPrediction " .. rainPrediction)
else dz.notify(sunscreen.name .. " closed because of timerule " )
end
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: 68
- Joined: Sunday 10 June 2018 16:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Need help with sunscreen script
I've made a dummy switch for the sunscreen for testing.
The dummy switch turned on this morning but didn't turn off after sunset or because of the UV rule
The dummy switch turned on this morning but didn't turn off after sunset or because of the UV rule
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Need help with sunscreen script
Can you check what the On / Off equivalent of "Open" is for your sunscreen and report back ?
What would also help is to add some log statements.
Thx
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: 68
- Joined: Sunday 10 June 2018 16:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Need help with sunscreen script
Open = On and Close = Off.
The sunscreen isn't responding at all with the script, without the script the screen works as normal. Double checked the IDX's and they're right.
The log:
2018-10-10 22:18:00.410 Status: dzVents: Info: Sunscreen: ------ Start internal script: Zonnescherm:, trigger: every 1 minutes between 11:30 and 1 minute after 23:59 on 1/4-30/12
2018-10-10 22:18:00.446 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Dummy Zonnescherm Forum: Switch device adapter
2018-10-10 22:18:00.447 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Windsnelheid Assen: Wind device adapter
2018-10-10 22:18:00.449 Status: dzVents: Debug: Sunscreen: Processing device-adapter for UV Index Assen: UV device adapter
2018-10-10 22:18:00.450 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Regen voorspelling Assen: Rain device
2018-10-10 22:18:00.450 Status: dzVents: Info: Sunscreen: ------ Finished Zonnescherm
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Need help with sunscreen script
At line 23 there is an extra space after the word Closed that does not belong there. Can you correct that and try again ?drwurn wrote: ↑Wednesday 10 October 2018 22:26Open = On and Close = Off.
The sunscreen isn't responding at all with the script, without the script the screen works as normal. Double checked the IDX's and they're right.
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: 68
- Joined: Sunday 10 June 2018 16:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Need help with sunscreen script
Removed it but still don't workwaaren wrote: ↑Wednesday 10 October 2018 22:38At line 23 there is an extra space after the word Closed that does not belong there. Can you correct that and try again ?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Need help with sunscreen script [Solved]
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: 2
- Joined: Tuesday 20 February 2018 15:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Need help with sunscreen script
And? Did you manage to get it working?
-
- Posts: 165
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: Need help with sunscreen script
good question: did you succeed???
Who is online
Users browsing this forum: Bing [Bot] and 0 guests