return {
on = {
devices = {
'Screen deur slaapkamer 1'
},
},
execute = function(domoticz, switch)
if (switch.state == 'Op' and switch.level ~= '10') then
domoticz.devices('Relais ^ deur slaapkamer 1').switchOn().forMin(1)
domoticz.devices('Relais v deur slaapkamer 1').switchOff()
elseif (switch.state == 'Neer' and switch.level ~= '30') then
domoticz.devices('Relais ^ deur slaapkamer 1').switchOff()
domoticz.devices('Relais v deur slaapkamer 1').switchOn().forMin(1)
elseif (switch.state == 'Stop') then
domoticz.devices('Relais ^ deur slaapkamer 1').switchOff()
domoticz.devices('Relais v deur slaapkamer 1').switchOff()
end
end
}
There are multiple screens so there are also multiple Blockly scripts, which are basically the same. Only the devices listed in the script are different. I wonder if the different Blockly scripts can be collected in a single DzVents script. If so, how to start?
Jan Jansen wrote: Sunday 05 July 2020 14:11
There are multiple screens so there are also multiple Blockly scripts, which are basically the same. Only the devices listed in the script are different. I wonder if the different Blockly scripts can be collected in a single DzVents script. If so, how to start?
A good start would be to show the Blockly's as the are now.
return
{
on =
{
devices =
{
'Screen deur slaapkamer*',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
marker = 'screens',
},
execute = function(domoticz, switch)
roomNumber = switch.name:sub(-1,-1) -- get the last char of the switchname
if (switch.state == 'Op' and switch.level ~= '10') then
domoticz.devices('Relais ^ deur slaapkamer ' .. roomNumber).switchOn().forMin(1)
domoticz.devices('Relais v deur slaapkamer ' .. roomNumber).switchOff()
elseif (switch.state == 'Neer' and switch.level ~= '30') then
domoticz.devices('Relais ^ deur slaapkamer ' .. roomNumber).switchOff()
domoticz.devices('Relais v deur slaapkamer ' .. roomNumber).switchOn().forMin(1)
elseif (switch.state == 'Stop') then
domoticz.devices('Relais ^ deur slaapkamer ' .. roomNumber).switchOff()
domoticz.devices('Relais v deur slaapkamer ' .. roomNumber).switchOff()
end
end
}
I discovered that "switch.level ~= '10' " makes no sense. With "switch.level ~= '10' " I wanted to prevent an unnecessary next action if, for example, the 'Up' button is pressed a second time.
It can be solved with a user variable as done in the following Blockly script.
blockly screens ramen keuken.png (88.86 KiB) Viewed 1272 times
Is this possible in DzVents without a user variable?
return
{
on =
{
devices =
{
'Screens ramen keuken',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
marker = 'screens ramen',
},
execute = function(dz, item)
local up = dz.devices('Relais ^ ramen keuken')
local down = dz.devices('Relais v ramen keuken')
if item.state == 'Op' and up.state ~= 'On' then
down.switchOff()
up.switchOn()
up.switchOff().afterSec(60)
elseif item.state == 'Neer' and down.state ~= 'On' then
up.switchOff()
down.switchOn()
down.switchOff().afterSec(60)
elseif item.state == 'Stop' then
up.switchOff()
down.switchOff()
end
end
}
Jan Jansen wrote: Sunday 05 July 2020 17:04
...It can be solved with a user variable. Is this possible in dzVents without a user variable?
something like this ?
It is not the solution I was looking for, unfortunately. Using the Blockly script (including the user variable) it works as desired. When I press the 'Up' button on the selector switch, the screen goes up. However, this only happens if the previous position of the selector switch was 'Stop' or 'Down'.
return
{
on =
{
devices =
{
'Screens ramen keuken',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
marker = 'screens ramen',
},
execute = function(dz, item)
local up = dz.devices('Relais ^ ramen keuken')
local down = dz.devices('Relais v ramen keuken')
if item.state == 'Op' and ( up.state ~= 'On' or item.lastUpdate.secondsAgo > 59 ) then
down.switchOff()
up.switchOn()
up.switchOff().afterSec(60)
elseif item.state == 'Neer' and ( down.state ~= 'On' or item.lastUpdate.secondsAgo > 59 ) then
up.switchOff()
down.switchOn()
down.switchOff().afterSec(60)
elseif item.state == 'Stop' then
up.switchOff()
down.switchOff()
end
end
}
waaren wrote: Monday 06 July 2020 13:21
Can you check this one?
First thank you for your time and attention!
The last script doesn't do what I want either. When I press the 'Neer' button, 'Relais v ramen keuken' is activated. For example, if I press the same button again after 5 minutes, 'Relais v ramen keuken' will be activated again. I do not want that relay to be reactivated when pressing the 'Neer' button again.
Jan Jansen wrote: Monday 06 July 2020 14:53
The last script doesn't do what I want either. When I press the 'Neer' button, 'Relais v ramen keuken' is activated. For example, if I press the same button again after 5 minutes, 'Relais v ramen keuken' will be activated again. I do not want that relay to be reactivated when pressing the 'Neer' button again.
If I understand correctly what you want I don't think it is possible without saving the last action in some way. Below script does that using dzVents persistent data.