Page 1 of 1
Script to protect sun screen [Solved]
Posted: Thursday 30 July 2020 16:24
by Jan Jansen
I want to convert a Blockly script to DzVents and I was inspired by:
https://www.domoticz.com/forum/viewtopi ... 59&t=33466
After adapting to my wishes the following script:
Code: Select all
return
{
on =
{
devices =
{
'Status',
'Neerslag verwacht',
'Wind',
},
variables = {
'Windstoten'
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(dz)
local status = dz.devices('Status').state -- Selector switch levels "Off", "Spaarstand", "Afwezig" and "Afwezig +"
local shutter = dz.devices('Zonnescherm').state -- Selector switch levels Op, Stop And Neer
local possibleRain = dz.devices('Neerslag verwacht').state
local wind = dz.devices('Wind').speedMs
local windstoten = tonumber(dz.variables('Windstoten').svalue)
dz.log('Status, state: ' .. tostring(status.state ) , dz LOG_DEBUG)
dz.log('Zonnescherm, state: ' .. tostring(shutter.state) , dz.LOG_DEBUG)
dz.log('Neerslag verwacht, state: ' .. tostring(possibleRain.state) , dz.LOG_DEBUG)
dz.log('Wind, value: ' .. tostring(wind) , dz.LOG_DEBUG)
dz.log('Windstoten, value: ' .. tostring(windstoten) , dz.LOG_DEBUG)
if shutter.state == 'Neer' and status == 'Spaarstand' and possibleRain == 'On' and wind > 20 and windstoten > 20 then
shutter.switchSelector(Op)
end
end
}
After saving the script I got an error on line 28. I don't know why.

- Zonnescherm.png (22.12 KiB) Viewed 659 times
In addition, I am not sure about lines 26 and 35.
Thanks in advance!
Re: Script to protect sun screen
Posted: Thursday 30 July 2020 16:48
by waaren
Jan Jansen wrote: Thursday 30 July 2020 16:24
After saving the script I got an error on line 28. I don't know why.
In addition, I am not sure about lines 26 and 35.
You missed a dot in 28 and some quotes in line 35. In line 26 you use svalue but it is value.
Code: Select all
return
{
on =
{
devices =
{
'Status',
'Neerslag verwacht',
'Wind',
},
variables = {
'Windstoten'
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(dz)
local status = dz.devices('Status').state -- Selector switch levels "Off", "Spaarstand", "Afwezig" and "Afwezig +"
local shutter = dz.devices('Zonnescherm').state -- Selector switch levels Op, Stop And Neer
local possibleRain = dz.devices('Neerslag verwacht').state
local wind = dz.devices('Wind').speedMs
local windstoten = dz.variables('Windstoten').value
dz.log('Status, state: ' .. status.state , dz.LOG_DEBUG)
dz.log('Zonnescherm, state: ' .. shutter.state , dz.LOG_DEBUG)
dz.log('Neerslag verwacht, state: ' .. possibleRain.state , dz.LOG_DEBUG)
dz.log('Wind, value: ' .. wind , dz.LOG_DEBUG)
dz.log('Windstoten, value: ' .. windstoten , dz.LOG_DEBUG)
if shutter.state == 'Neer' and status == 'Spaarstand' and possibleRain == 'On' and wind > 20 and windstoten > 20 then
shutter.switchSelector('Op')
end
end
}
Not sure if you don't mean
Code: Select all
if shutter.state == 'Neer' and status == 'Spaarstand' and ( possibleRain == 'On' or wind > 20 or windstoten > 20 ) then
in line 34
Re: Script to protect sun screen
Posted: Thursday 30 July 2020 16:56
by Jan Jansen
@ waaren,
Thanks again for your quick reply! And in line 34 must be or.
Jan
Re: Script to protect sun screen
Posted: Thursday 30 July 2020 20:17
by Jan Jansen
@ waaren,
First, I changed all 'ands', except the first one, in line 34 to 'ors'. Using your changes, line 28 still causes an error. I do not get it.

- Log zonnescherm.png (41.22 KiB) Viewed 611 times
Regards
Re: Script to protect sun screen
Posted: Thursday 30 July 2020 21:08
by waaren
Jan Jansen wrote: Thursday 30 July 2020 20:17
First, I changed all 'ands', except the first one, in line 34 to 'ors'. Using your changes, line 28 still causes an error. I do not get it.
Can you try this ?
Code: Select all
return
{
on =
{
devices =
{
'Status',
'Neerslag verwacht',
'Wind',
},
variables = {
'Windstoten'
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(dz)
local status = dz.devices('Status') -- Selector switch levels "Off", "Spaarstand", "Afwezig" and "Afwezig +"
local shutter = dz.devices('Zonnescherm') -- Selector switch levels Op, Stop And Neer
local possibleRain = dz.devices('Neerslag verwacht')
local wind = dz.devices('Wind')
local windstoten = dz.variables('Windstoten')
dz.log('Status, state: ' .. status.levelName , dz.LOG_DEBUG)
dz.log('Zonnescherm, state: ' .. shutter.levelName, dz.LOG_DEBUG)
dz.log('Neerslag verwacht, state: ' .. possibleRain.state , dz.LOG_DEBUG)
dz.log('Wind, value: ' .. wind.speedMs , dz.LOG_DEBUG)
dz.log('Windstoten, value: ' .. windstoten.value , dz.LOG_DEBUG)
if shutter.levelName == 'Neer' and status.levelName == 'Spaarstand' and ( possibleRain.state == 'On' or wind.speedMs > 20 or tonumber(windstoten.value) > 20 ) then
shutter.switchSelector('Op')
end
end
}
Re: Script to protect sun screen
Posted: Thursday 30 July 2020 21:35
by rrozema
I would replace "if shutter.levelName == 'Neer'" by "if shutter.levelName ~= 'Op'" or your shutter will be blown to pieces if a wind comes up and your shutter isn't in its end position (i.e. shutter.levelName = 'Stop')
Re: Script to protect sun screen
Posted: Friday 31 July 2020 10:38
by Jan Jansen
Good morning!
waaren wrote: Thursday 30 July 2020 21:08
Can you try this ?
I tried the last version you sent. This version also contains an error in line 28.

- Log1.png (38.77 KiB) Viewed 575 times
Re: Script to protect sun screen
Posted: Friday 31 July 2020 11:23
by rrozema
Jan Jansen wrote: Friday 31 July 2020 10:38
Good morning!
waaren wrote: Thursday 30 July 2020 21:08
Can you try this ?
I tried the last version you sent. This version also contains an error in line 28.
Log1.png
A dot was missing between dz and LOG_DEBUG.
Code: Select all
return
{
on =
{
devices =
{
'Status',
'Neerslag verwacht',
'Wind',
},
variables = {
'Windstoten'
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(dz)
local status = dz.devices('Status') -- Selector switch levels "Off", "Spaarstand", "Afwezig" and "Afwezig +"
local shutter = dz.devices('Zonnescherm') -- Selector switch levels Op, Stop And Neer
local possibleRain = dz.devices('Neerslag verwacht')
local wind = dz.devices('Wind')
local windstoten = dz.variables('Windstoten')
dz.log('Status, state: ' .. status.levelName , dz.LOG_DEBUG)
dz.log('Zonnescherm, state: ' .. shutter.levelName, dz.LOG_DEBUG)
dz.log('Neerslag verwacht, state: ' .. possibleRain.state , dz.LOG_DEBUG)
dz.log('Wind, value: ' .. wind.speedMs , dz.LOG_DEBUG)
dz.log('Windstoten, value: ' .. windstoten.value , dz.LOG_DEBUG)
if shutter.levelName ~= 'Op' and status.levelName == 'Spaarstand' and ( possibleRain.state == 'On' or wind.speedMs > 20 or tonumber(windstoten.value) > 20 ) then
shutter.switchSelector('Op')
end
end
}
Re: Script to protect sun screen
Posted: Friday 31 July 2020 13:12
by Jan Jansen
@ waaren and @rrozema,
First, I should have seen that dot in line 28 myself. Second, the script works as desired after I modified line 34, thank you both!
Code: Select all
34 was:
if shutter.levelName ~= 'Op' and status.levelName == 'Spaarstand' and ( possibleRain.state == 'On' or wind.speedMs > 20 or tonumber(windstoten.value) > 20 ) then
34 now is:
if shutter.levelName ~= 'Op' and (status.levelName == 'Spaarstand' or possibleRain.state == 'On' or wind.speedMs > 20 or tonumber(windstoten.value) > 5 ) then
Regards
Jan