Dimmer Light Daytime

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Dimmer Light Daytime

Post by djdevil »

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

Immagine.jpg
Immagine.jpg (232.18 KiB) Viewed 486 times

Code: Select all

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
}  
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dimmer Light Daytime

Post by waaren »

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 ?

Code: Select all

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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Dimmer Light Daytime

Post by djdevil »

i try your code this is the log debug is correct?

Code: Select all

 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 

Code: Select all

 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 

zwave debug

Code: Select all

 2020-02-08 18:59:31.065 OpenZWave: Domoticz has send a Switch command!, Level: 255, NodeID: 2 (0x02)
2020-02-08 18:59:31.338 OpenZWave: Domoticz has send a Switch command!, Level: 30, NodeID: 2 (0x02)
2020-02-08 18:59:44.064 OpenZWave: Domoticz has send a Switch command!, Level: 0, NodeID: 2 (0x02)
2020-02-08 18:59:44.544 OpenZWave: Domoticz has send a Switch command!, Level: 0, NodeID: 2 (0x02) 
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dimmer Light Daytime

Post by waaren »

djdevil wrote: Saturday 08 February 2020 19:00 i try your code this is the log debug is correct?
Yes it is. I noticed this behavior before but dzVents is only sending the commands once so cannot be solved by changing dzVents code.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Dimmer Light Daytime

Post by djdevil »

waaren wrote: Saturday 08 February 2020 20:20
djdevil wrote: Saturday 08 February 2020 19:00 i try your code this is the log debug is correct?
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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dimmer Light Daytime

Post by waaren »

djdevil wrote: Saturday 08 February 2020 20:22
waaren wrote: Saturday 08 February 2020 20:20
djdevil wrote: Saturday 08 February 2020 19:00 i try your code this is the log debug is correct?
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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Dimmer Light Daytime

Post by djdevil »

waaren wrote: Saturday 08 February 2020 20:45
djdevil wrote: Saturday 08 February 2020 20:22
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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dimmer Light Daytime

Post by waaren »

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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest