Hi everyone I use this code to dim the lights according to the time and some switches, it works perfectly, only it sends the z-wave network in tilt by sending the same command twice both when I turn on the light and when off here is a log screen? is there any way to improve the code? thank you
return
{
on =
{
devices = { 'Studio'},
},
logging =
{
-- level = domoticz.LOG_DEBUG,
-- marker = 'dim based on time'
},
execute = function(dz, item)
dz.log('Studio stato: ' .. item.state,dz.LOG_DEBUG)
if item.active and item.lastUpdate.secondsAgo > 6 then
if dz.time.matchesRule('at 06:30-15:00') then
item.dimTo(10).silent()
end
if dz.time.matchesRule('at 15:00-17:00') then
item.dimTo(20).silent()
end
if dz.time.matchesRule('at 17:00-21:30') then
item.dimTo(30).silent()
end
if dz.time.matchesRule('at 21:30-22:30') then
item.dimTo(20).silent()
end
if dz.time.matchesRule('at 22:30-06:30') then
item.dimTo(10).silent()
end
if dz.devices('TV Studio').state == 'Paused' then
item.dimTo(1).silent()
end
if dz.devices('Ospiti').state == 'On' then
item.dimTo(80).silent()
end
if dz.devices('Modalità Notte').state == 'On' then
item.dimTo(1).silent()
end
if dz.devices('Buonanotte').state == 'On' then
item.dimTo(1).silent()
end
elseif item.lastUpdate.secondsAgo > 6 then
item.dimTo(0).silent()
end
end
}
djdevil wrote: Saturday 08 February 2020 0:10
Inglese
Hi everyone I use this code to dim the lights according to the time and some switches, it works perfectly, only it sends the z-wave network in tilt by sending the same command twice both when I turn on the light and when off here is a log screen? is there any way to improve the code? thank you
Kind of hard to say without debug logging but can you try this ?
return
{
on =
{
devices = { 'Studio'},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'dim based on time'
},
execute = function(dz, item)
dz.log('Studio stato: ' .. item.state,dz.LOG_DEBUG)
if item.active and item.lastUpdate.secondsAgo > 6 then
if dz.time.matchesRule('at 06:30-15:00') then
item.dimTo(10).silent()
elseif dz.time.matchesRule('at 15:00-17:00') then
item.dimTo(20).silent()
elseif dz.time.matchesRule('at 17:00-21:30') then
item.dimTo(30).silent()
elseif dz.time.matchesRule('at 21:30-22:30') then
item.dimTo(20).silent()
elseif dz.time.matchesRule('at 22:30-06:30') then
item.dimTo(10).silent()
elseif dz.devices('TV Studio').state == 'Paused' then
item.dimTo(1).silent()
elseif dz.devices('Ospiti').state == 'On' then
item.dimTo(80).silent()
elseif dz.devices('Modalità Notte').state == 'On' then
item.dimTo(1).silent()
elseif dz.devices('Buonanotte').state == 'On' then
item.dimTo(1).silent()
end
elseif item.lastUpdate.secondsAgo > 6 then
item.dimTo(0).silent()
end
end
}
2020-02-08 18:59:31.064 Status: User: davide initiated a switch command (66/Studio/On)
2020-02-08 18:59:31.316 Status: dzVents: Info: dim based on time: ------ Start internal script: Dimmer Studio: Device: "Studio (Z-Wave)", Index: 66
2020-02-08 18:59:31.316 Status: dzVents: Debug: dim based on time: Studio stato: On
2020-02-08 18:59:31.316 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 30
2020-02-08 18:59:31.317 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 30 NOTRIGGER
2020-02-08 18:59:31.317 Status: dzVents: Info: dim based on time: ------ Finished Dimmer Studio
2020-02-08 18:59:31.575 Status: dzVents: Info: dim based on time: ------ Start internal script: Dimmer Studio: Device: "Studio (Z-Wave)", Index: 66
2020-02-08 18:59:31.575 Status: dzVents: Debug: dim based on time: Studio stato: On
2020-02-08 18:59:31.575 Status: dzVents: Info: dim based on time: ------ Finished Dimmer Studio
2020-02-08 18:59:44.063 Status: User: davide initiated a switch command (66/Studio/Off)
2020-02-08 18:59:44.527 Status: dzVents: Info: dim based on time: ------ Start internal script: Dimmer Studio: Device: "Studio (Z-Wave)", Index: 66
2020-02-08 18:59:44.527 Status: dzVents: Debug: dim based on time: Studio stato: Off
2020-02-08 18:59:44.527 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 0
2020-02-08 18:59:44.527 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 0 NOTRIGGER
2020-02-08 18:59:44.527 Status: dzVents: Info: dim based on time: ------ Finished Dimmer Studio
waaren wrote: Saturday 08 February 2020 20:20
Yes it is. I noticed this behavior before but dzVents is only sending the commands once so cannot be solved by changing dzVents code.
Is a problem of zwave network?
I don't know what the root cause is but I have only seen this with Zwave devices.
ok thanks for the reply, anyway advice to use the code with the addition of "else if"? how did you reserve it? It's more correct?
djdevil wrote: Sunday 09 February 2020 13:33
ok thanks for the reply, anyway advice to use the code with the addition of "else if"? how did you reserve it? It's more correct?
From what I see in your script I understand that the conditions are to be evaluated as mutual exclusive. In such a case the elseif should be used.