script qubino dimmer ad motion  [Solved]

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

Moderator: leecollings

Post Reply
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

script qubino dimmer ad motion

Post by AllesVanZelf »

I have a script that does not work as I would have expected.

Code: Select all

return
{
     on =
     { devices =
        {
            'Daglicht',
            'MS Zolder Overloop Beweging',
            'Lamp Zolder Overloop Dimmer',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },
    
    execute = function(dz)
        local dimmer = dz.devices('Lamp Zolder Overloop Dimmer')
        local daglicht = dz.devices('Daglicht').state
        local motion = dz.devices('MS Zolder Overloop Beweging').state
 
 
        dz.log('Lamp Zolder Overloop Dimmer,    state: ' .. dimmer.state, dz.LOG)
        dz.log('Daglicht,   state: ' .. daglicht, dz.LOG_DEBUG)
        dz.log('MS Zolder Overloop Beweging,      state: ' .. motion, dz.LOG)

        if dimmer.state == 'On' and motion == 'On' then
            dz.log('Switching dimmer zolder to 35%', dz.LOG_DEBUG)
            dimmer.dimTo(35)
            
        elseif dimmer.state == 'On' and daglicht == 'On' and motion == 'Off' then
            dz.log('Switching dimmer zolder to 20% and then Off overdag', dz.LOG_DEBUG)
            dimmer.setLevel(20).afterSec(45)
            dimmer.switchOff().afterSec(60)
            
        elseif dimmer.state == 'On' and daglicht == 'Off' and dz.time.matchesRule('at 16:00-23:00') and motion == 'Off' then
            dz.log('Switching dimmer zolder to 20% avond', dz.LOG_DEBUG)
            dimmer.dimTo(20).afterSec(150)
            
        elseif dimmer.state == 'On' and daglicht == 'Off' and dz.time.matchesRule('at 23:00-06:00') and motion == 'Off' then
            dz.log('Switching dimmer zolder to 20 and then Off nacht', dz.LOG_DEBUG)
            dimmer.dimTo(20).afterSec(150)
            dimmer.switchOff().afterSec(200)
        end
    end
}
The first command is excecuted. So 'Overdag' this is dimmer.setLevel(20). If I comment out -- dimmer.setLevel then The switch is switched Off.
Why is this? Why do they not both excecute?
Somethng wrong in my code, but what? Please advise
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

Re: script qubino dimmer ad motion

Post by AllesVanZelf »

I think I solved it myself 8-)
I rebuild the script and changed some:

Code: Select all

return
{
     on =
     {
        devices =
        {
            'MS Zolder Overloop Beweging',
            'Lamp Zolder Overloop Dimmer',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },
    
    execute = function(dz)
        local dimmer = dz.devices('Lamp Zolder Overloop Dimmer')
        local motion = dz.devices('MS Zolder Overloop Beweging').state
 
 
        dz.log('Lamp Zolder Overloop Dimmer,    state: ' .. dimmer.state, dz.LOG)
        dz.log('MS Zolder Overloop Beweging,      state: ' .. motion, dz.LOG)


        if dimmer.level > 0 and motion == 'On' then
            dz.log('Switching dimmer zolder to 35%', dz.LOG_DEBUG)
            dimmer.dimTo(35).silent()
         
         elseif dimmer.level > 0 and motion == 'Off' and dz.time.matchesRule('between 23:00 and sunset') then
            dz.log('Switching dimmer zolder to 20% and then Off', dz.LOG_DEBUG)
            dimmer.dimTo(20).afterSec(45).silent()
            dimmer.switchOff().afterSec(60).silent()
        
        elseif dimmer.level > 0 and motion == 'Off' and dz.time.matchesRule('between sunset and 23:00') then
            dz.log('Switching dimmer zolder to 20% avond', dz.LOG_DEBUG)
            dimmer.dimTo(20).afterSec(45).silent()
        
        elseif dimmer.state == 'Off' or dimmer.level == 0 then
            dimmer.cancelQueuedCommands()
            dz.log('Switching dimmer zolder cancelQueueCommands', dz.LOG_DEBUG)
        end
    end

} 
At first, after the light went Off, it went On again after some seconds. Therefore I added the last part:

Code: Select all

        elseif dimmer.state == 'Off' or dimmer.level == 0 then
            dimmer.cancelQueuedCommands()
            dz.log('Switching dimmer zolder cancelQueueCommands', dz.LOG_DEBUG)
It looks like this is working.
If you see a problem in this code, or if this could be more easily done, please advise me!
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: script qubino dimmer ad motion

Post by waaren »

AllesVanZelf wrote: Wednesday 22 July 2020 12:53 I have a script that does not work as I would have expected.

The first command is excecuted. So 'Overdag' this is dimmer.setLevel(20). If I comment out -- dimmer.setLevel then The switch is switched Off.
Why is this? Why do they not both excecute?
Somethng wrong in my code, but what? Please advise
the commands you give to dimmer (Lamp Zolder Overloop Dimmer) do trigger the script again leading to unexpected results because this device can have more states then only 'On' and 'Off' .

Can you try this?

Code: Select all

return
{
     on =
     { devices =
        {
            'Daglicht',
            'MS Zolder Overloop Beweging',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },
    
    execute = function(dz)
        local dimmer = dz.devices('Lamp Zolder Overloop Dimmer')
        local daglicht = dz.devices('Daglicht').state
        local motion = dz.devices('MS Zolder Overloop Beweging').state
 
 
        dz.log('Lamp Zolder Overloop Dimmer,    state: ' .. dimmer.state, dz.LOG)
        dz.log('Daglicht,   state: ' .. daglicht, dz.LOG_DEBUG)
        dz.log('MS Zolder Overloop Beweging,      state: ' .. motion, dz.LOG)

        if dimmer.state == 'On' and motion == 'On' then
            dz.log('Switching dimmer zolder to 35%', dz.LOG_DEBUG)
            dimmer.dimTo(35).silent()
            
        elseif dimmer.state == 'On' and daglicht == 'On' and motion == 'Off' then
            dz.log('Switching dimmer zolder to 20% and then Off overdag', dz.LOG_DEBUG)
            dimmer.dimTo(20).afterSec(45).silent()
            dimmer.dimTo(0).afterSec(60).silent()
            
        elseif dimmer.state == 'On' and daglicht == 'Off' and dz.time.matchesRule('at 16:00-23:00') and motion == 'Off' then
            dz.log('Switching dimmer zolder to 20% avond', dz.LOG_DEBUG)
            dimmer.dimTo(20).afterSec(150).silent()
            
        elseif dimmer.state == 'On' and daglicht == 'Off' and dz.time.matchesRule('at 23:00-06:00') and motion == 'Off' then
            dz.log('Switching dimmer zolder to 20 and then Off nacht', dz.LOG_DEBUG)
            dimmer.dimTo(20).afterSec(150).silent()
            dimmer.dimTo(0).afterSec(200).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
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

Re: script qubino dimmer ad motion  [Solved]

Post by AllesVanZelf »

So the silent() part would have done the trick here. I did include that in my second script and this seems to work. So maybe the dimmer.cancelQueuedCommands() would have not been necessary.
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest