Help for dimming time script  [Solved]

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

Moderator: leecollings

djksage
Posts: 12
Joined: Sunday 31 January 2016 15:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Help for dimming time script

Post by djksage »

hello,

I need some help to make dzvents script,

Between 21:30 to 06:30, when i press my switch, i would like light to 20%, other time at 100%

my first tink is, make dimTo(20) with a order swtichOff directly to setup level at 20% and when i press my switch, light is dimming to 20%
but not work, if i press my switch, light is always 100% ( or last manual state )

i read the wiki, and find maybee a solution quietOn/quietOff,

but when i use quietOn i have always a error :(
attempt to call field 'quieton' (a nil value)

can i use quietOn with a level or dimTo fonction?

sorry,i'm not good to make script for my test i make this :

Code: Select all

return {
   on = {
      timer = {
         'at 16:53'
      }
   },
   execute = function(domoticz, timer)
      domoticz.log('Script Run')
         domoticz.devices('SDB').quietOn.().dimTo(20)
         domoticz.devices('SDB').switchOff()
    end
}
thanks for your help ;)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help for dimming time script

Post by waaren »

djksage wrote: Tuesday 10 September 2019 19:13 I need some help to make dzVents script,
Between 21:30 to 06:30, when i press my switch, i would like light to 20%, other time at 100%
Couple of questions.
  • What is the name of your switch ?
  • Should the script also switch the light Off and by the same switch or should it switch off after a certain time ?
  • If the light is on at 21:30 or at 06:30 should it change dimlevel ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
djksage
Posts: 12
Joined: Sunday 31 January 2016 15:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Help for dimming time script

Post by djksage »

waaren wrote: Couple of questions.
  • What is the name of your switch ?

    the name is SDB but finaly is for 3 switch (bathroom, hall, my room)
  • Should the script also switch the light Off and by the same switch or should it switch off after a certain time ?

    script need only setup dimming value (20%) for turn On/Off/dimming is only manualy on pushing my switch buton.
  • If the light is on at 21:30 or at 06:30 should it change dimlevel ?
Yes is the best solution but if it is too hard isn't matter, is only for use 5 or 10 min max (time to go on bathroom and go back on my bed)

thanks for your help :)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help for dimming time script

Post by waaren »

djksage wrote: Tuesday 10 September 2019 21:27 the name is SDB but finaly is for 3 switch (bathroom, hall, my room)
Guess I mis something. switchname is SDB, What is the name of the dimmable light ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
djksage
Posts: 12
Joined: Sunday 31 January 2016 15:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Help for dimming time script

Post by djksage »

hello,

Image

my light name is SDB

sorry, my mistake, i use a qubino ZMNHSD1, my switch buton is connected directly on qubino so i don't have a switch declared on DZ to turn on my light
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help for dimming time script

Post by waaren »

djksage wrote: Tuesday 10 September 2019 23:10 my light name is SDB
my switch buton is connected directly on qubino so i don't have a switch declared on DZ to turn on my light
Hopefully domoticz will see the light switching. If not I don't know how to do what you described.
Can you try this ?

Code: Select all

return 
{
   on = 
   {
      devices = { 'SDB' },
   },
   
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'dim based on time'  
    },
    
   execute = function(dz, item)
        
        if item.active then  
            if dz.time.matchesRule('at 06:30-21:30') then
                item.dimTo(100).silent()
            else
                item.dimTo(20).silent()
            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
djksage
Posts: 12
Joined: Sunday 31 January 2016 15:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Help for dimming time script

Post by djksage »

hello,

with your script, i can't turn off my light, but timing work fine :)

so :

-if light is off @ 21:28, if i turn on => light is 100% and i can't turn off (tested with switch, app and web gui) @ 21:30 DZ dimto 20% without possibility to turn off

-if light is off @ 21:32 (and last state is 100%) and i turn on => light is dim to 20% directly but always without possibility to turn off, i turn off this script for full control my light
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help for dimming time script

Post by waaren »

djksage wrote: Wednesday 11 September 2019 20:04 with your script, i can't turn off my light, but timing work fine :)
can you please try this one and show what's in the domoticz log when switching and when switching off ?

Code: Select all

return 
{
   on = 
   {
      devices = { 'SDB' },
   },
   
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'dim based on time'  
    },
    
   execute = function(dz, item)
        
    dz.log('SDB state' .. item.state,dz.LOG_DEBUG)
    if item.active then  
            if dz.time.matchesRule('at 06:30-21:30') then
                item.dimTo(100).silent()
            else
                item.dimTo(20).silent()
            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
djksage
Posts: 12
Joined: Sunday 31 January 2016 15:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Help for dimming time script

Post by djksage »

i make this test with my kitchen light (lumière cuisine)

Turn On

Code: Select all

2019-09-11 21:04:01.742 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-09-11 21:04:01.954 Status: dzVents: Info: Handling events for: "Lumiere Cuisine", value: "On"
2019-09-11 21:04:01.954 Status: dzVents: Info: dim based on time: ------ Start internal script: testdim: Device: "Lumiere Cuisine (Clé USB ZWAVE+)", Index: 256
2019-09-11 21:04:01.955 Status: dzVents: Debug: dim based on time: Lumiere Cuisine stateOn
2019-09-11 21:04:01.956 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 20
2019-09-11 21:04:01.956 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 20 NOTRIGGER
2019-09-11 21:04:01.957 Status: dzVents: Info: dim based on time: ------ Finished testdim
Turn Off

Code: Select all

2019-09-11 21:10:40.237 Status: User: Admin initiated a switch command (256/Lumiere Cuisine/Off)
2019-09-11 21:10:40.459 Status: dzVents: Info: Handling events for: "Lumiere Cuisine", value: "Off"
2019-09-11 21:10:40.459 Status: dzVents: Info: dim based on time: ------ Start internal script: testdim: Device: "Lumiere Cuisine (Clé USB ZWAVE+)", Index: 256
2019-09-11 21:10:40.460 Status: dzVents: Debug: dim based on time: Lumiere Cuisine stateOff
2019-09-11 21:10:40.461 Status: dzVents: Info: dim based on time: ------ Finished testdim
2019-09-11 21:10:40.585 Status: dzVents: Info: Handling events for: "Lumiere Cuisine", value: "On"
2019-09-11 21:10:40.585 Status: dzVents: Info: dim based on time: ------ Start internal script: testdim: Device: "Lumiere Cuisine (Clé USB ZWAVE+)", Index: 256
2019-09-11 21:10:40.586 Status: dzVents: Debug: dim based on time: Lumiere Cuisine stateOn
2019-09-11 21:10:40.586 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 20
2019-09-11 21:10:40.586 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 20 NOTRIGGER
2019-09-11 21:10:40.587 Status: dzVents: Info: dim based on time: ------ Finished testdim
2019-09-11 21:10:40.589 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-09-11 21:10:40.705 Status: dzVents: Info: Handling events for: "Lumiere Cuisine", value: "Off"
2019-09-11 21:10:40.706 Status: dzVents: Info: dim based on time: ------ Start internal script: testdim: Device: "Lumiere Cuisine (Clé USB ZWAVE+)", Index: 256
2019-09-11 21:10:40.707 Status: dzVents: Debug: dim based on time: Lumiere Cuisine stateOff
2019-09-11 21:10:40.709 Status: dzVents: Info: dim based on time: ------ Finished testdim
2019-09-11 21:10:40.822 Status: dzVents: Info: Handling events for: "Lumiere Cuisine", value: "On"
2019-09-11 21:10:40.823 Status: dzVents: Info: dim based on time: ------ Start internal script: testdim: Device: "Lumiere Cuisine (Clé USB ZWAVE+)", Index: 256
2019-09-11 21:10:40.823 Status: dzVents: Debug: dim based on time: Lumiere Cuisine stateOn
2019-09-11 21:10:40.824 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 20
2019-09-11 21:10:40.824 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 20 NOTRIGGER
2019-09-11 21:10:40.825 Status: dzVents: Info: dim based on time: ------ Finished testdim

after 5 or 6 min to try to turn off is working (1 time only)

Code: Select all

 2019-09-11 21:06:33.382 Status: User: Admin initiated a switch command (256/Lumiere Cuisine/Off)
2019-09-11 21:06:33.682 Status: dzVents: Info: Handling events for: "Lumiere Cuisine", value: "Off"
2019-09-11 21:06:33.682 Status: dzVents: Info: dim based on time: ------ Start internal script: testdim: Device: "Lumiere Cuisine (Clé USB ZWAVE+)", Index: 256
2019-09-11 21:06:33.684 Status: dzVents: Debug: dim based on time: Lumiere Cuisine stateOff
2019-09-11 21:06:33.686 Status: dzVents: Info: dim based on time: ------ Finished testdim 
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help for dimming time script

Post by waaren »

djksage wrote: Wednesday 11 September 2019 21:12 i make this test with my kitchen light (lumière cuisine)
Thx, think I understand a bit better what is happening now.

Can you try this one.

Code: Select all

return
{
   on =
   {
      devices = { 'SDB' },
   },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'dim based on time'
    },

   execute = function(dz, item)

        dz.log('SDB state: ' .. item.state,dz.LOG_DEBUG)

        if item.active then
                if dz.time.matchesRule('at 06:30-21:30') then
                    item.dimTo(100).silent()
                else
                    item.dimTo(20).silent()
                end
        else
            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
djksage
Posts: 12
Joined: Sunday 31 January 2016 15:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Help for dimming time script

Post by djksage »

hello

same problem, i can't turn off, light start to turn off but script switch light on

Code: Select all

2019-09-12 19:55:11.521 (Clé USB ZWAVE+) Light/Switch (Lumiere Cuisine)
2019-09-12 19:55:11.702 OpenZWave: Domoticz has send a Switch command!, Level: 0, NodeID: 26 (0x1a)
2019-09-12 19:55:11.706 (Clé USB ZWAVE+) Usage (Cuisine)
2019-09-12 19:55:11.710 (Clé USB ZWAVE+) General/kWh (Cuisine kWh)
2019-09-12 19:55:11.715 (Clé USB ZWAVE+) Light/Switch (Lumiere Cuisine)
2019-09-12 19:55:11.807 (Clé USB ZWAVE+) Light/Switch (Lumiere Cuisine)
2019-09-12 19:55:11.957 OpenZWave: Domoticz has send a Switch command!, Level: 99, NodeID: 26 (0x1a)
2019-09-12 19:55:11.962 (Clé USB ZWAVE+) Light/Switch (Lumiere Cuisine)
2019-09-12 19:55:11.695 Status: dzVents: Info: Handling events for: "Lumiere Cuisine", value: "Off"
2019-09-12 19:55:11.695 Status: dzVents: Info: dim based on time: ------ Start internal script: testdim: Device: "Lumiere Cuisine (Clé USB ZWAVE+)", Index: 256
2019-09-12 19:55:11.696 Status: dzVents: Debug: dim based on time: Lumiere Cuisine state: Off
2019-09-12 19:55:11.696 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 0
2019-09-12 19:55:11.696 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 0 NOTRIGGER
2019-09-12 19:55:11.698 Status: dzVents: Info: dim based on time: ------ Finished testdim
2019-09-12 19:55:11.700 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-09-12 19:55:11.942 Status: dzVents: Info: Handling events for: "Lumiere Cuisine", value: "On"
2019-09-12 19:55:11.942 Status: dzVents: Info: dim based on time: ------ Start internal script: testdim: Device: "Lumiere Cuisine (Clé USB ZWAVE+)", Index: 256
2019-09-12 19:55:11.943 Status: dzVents: Debug: dim based on time: Lumiere Cuisine state: On
2019-09-12 19:55:11.944 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 100
2019-09-12 19:55:11.944 Status: dzVents: Debug: dim based on time: Constructed timed-command: Set Level 100 NOTRIGGER
2019-09-12 19:55:11.945 Status: dzVents: Info: dim based on time: ------ Finished testdim
2019-09-12 19:55:11.946 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help for dimming time script

Post by waaren »

djksage wrote: Thursday 12 September 2019 19:59 same problem, i can't turn off, light start to turn off but script switch light on
What I see in the log is that Zwave send two signals directly after each other. Only way to deal with that would be to build in a check to exclude actions directly after an earlier one.
Hopefully this will do it.

Code: Select all

return
{
   on =
   {
      devices = { 'SDB' },
   },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'dim based on time'
    },

   execute = function(dz, item)

        dz.log('SDB state: ' .. item.state,dz.LOG_DEBUG)

        if item.active and item.lastUpdate.secondsAgo > 4 then 
                if dz.time.matchesRule('at 06:30-21:30') then
                    item.dimTo(100).silent()
                else
                    item.dimTo(20).silent()
                end
        elseif item.lastUpdate.secondsAgo > 4 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
djksage
Posts: 12
Joined: Sunday 31 January 2016 15:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Help for dimming time script  [Solved]

Post by djksage »

IT'S work! turn on directly of good % and turn off also

thanks for your script !

i setup DZ for control my hall and bathroom, not in my room because i can't dim after power on, if i dim to 100% script go back on 20% quickly
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Help for dimming time script

Post by djdevil »

waaren wrote: Thursday 12 September 2019 20:22
djksage wrote: Thursday 12 September 2019 19:59 same problem, i can't turn off, light start to turn off but script switch light on
What I see in the log is that Zwave send two signals directly after each other. Only way to deal with that would be to build in a check to exclude actions directly after an earlier one.
Hopefully this will do it.

Code: Select all

return
{
   on =
   {
      devices = { 'SDB' },
   },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'dim based on time'
    },

   execute = function(dz, item)

        dz.log('SDB state: ' .. item.state,dz.LOG_DEBUG)

        if item.active and item.lastUpdate.secondsAgo > 4 then 
                if dz.time.matchesRule('at 06:30-21:30') then
                    item.dimTo(100).silent()
                else
                    item.dimTo(20).silent()
                end
        elseif item.lastUpdate.secondsAgo > 4 then
            item.dimTo(0).silent()
        end
    end
}  
Hello Waaren I have been using this script for some time to dim my lights, but with the latest release 2020-04-26, the script no longer works, the problem thinks it is this part of code "and item.lastUpdate.secondsAgo> 4" because when I exclude it it works but then as you already know then you make me in loop, how can I do thanks!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help for dimming time script

Post by waaren »

djdevil wrote: Monday 27 April 2020 17:35 I have been using this script for some time to dim my lights, but with the latest release 2020-04-26, the script no longer works, the problem thinks it is this part of code "and item.lastUpdate.secondsAgo> 4" because when I exclude it it works but then as you already know then you make me in loop, how can I do thanks!
Can you show me the domoticzlog when you activate the SDB with this script and the with the modified one ?
What was the version you used before the latest one and where this script still worked ?
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: Help for dimming time script

Post by djdevil »

waaren wrote: Monday 27 April 2020 21:11
djdevil wrote: Monday 27 April 2020 17:35 I have been using this script for some time to dim my lights, but with the latest release 2020-04-26, the script no longer works, the problem thinks it is this part of code "and item.lastUpdate.secondsAgo> 4" because when I exclude it it works but then as you already know then you make me in loop, how can I do thanks!
Can you show me the domoticzlog when you activate the SDB with this script and the with the modified one ?
What was the version you used before the latest one and where this script still worked ?
Hello Waaren thx for reply, yes this the code that always work,

I noticed that with the latest version of domoticz, the update of the zwave devices is very fast in fact the script seems to work by lowering the control time of the last update to 0.1 but this sometimes messes up the whole network! do you know any other way to do what i need?

Code: Select all

if item.active and item.lastUpdate.secondsAgo > 0.1 then 
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Help for dimming time script

Post by djdevil »

waaren wrote: Monday 27 April 2020 21:11
djdevil wrote: Monday 27 April 2020 17:35 I have been using this script for some time to dim my lights, but with the latest release 2020-04-26, the script no longer works, the problem thinks it is this part of code "and item.lastUpdate.secondsAgo> 4" because when I exclude it it works but then as you already know then you make me in loop, how can I do thanks!
Can you show me the domoticzlog when you activate the SDB with this script and the with the modified one ?
What was the version you used before the latest one and where this script still worked ?
Maybe that's the problem https://github.com/domoticz/domoticz/issues/4112, in any case I can only downgrade Dzvents?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help for dimming time script

Post by waaren »

djdevil wrote: Tuesday 28 April 2020 14:43 Maybe that's the problem https://github.com/domoticz/domoticz/issues/4112, in any case I can only downgrade Dzvents?
No that is not possible because of the close integration. Anyway the issue is in the domoticz core code. Not in the dzVents part.
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: Help for dimming time script

Post by djdevil »

waaren wrote: Tuesday 28 April 2020 15:09
djdevil wrote: Tuesday 28 April 2020 14:43 Maybe that's the problem https://github.com/domoticz/domoticz/issues/4112, in any case I can only downgrade Dzvents?
No that is not possible because of the close integration. Anyway the issue is in the domoticz core code. Not in the dzVents part.


Can I do something for now or wait for the fix?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help for dimming time script

Post by waaren »

djdevil wrote: Tuesday 28 April 2020 15:35 Can I do something for now or wait for the fix?
Probably it is best to wait for a fix because when you downgrade to build 11865 you will have an incompatibel database.
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