Page 1 of 1

Motion script not working

Posted: Monday 11 October 2021 15:26
by Fredom
Dear forum members,
Can anyone help me to get this script to work.
After many attempts I did manage to get no more error messages in the Domoticz log. But the script still doesn't work :( .

The script should turn on a switch on movement and turn off after a set time.

Code: Select all

return
{
    active = true,

    on =
    {
        devices = { 
                     '691', --Bewegingsensor  (Xiaomi Human Body Sensor)
                     '37',  --Camera kinderkamer (schakelaar)
                    },
    },
        execute = function(dz,motion)
        local motion = dz.devices('691')
        local cam    = dz.devices('37')

        if motion.state == 'On' and cam.active then
        domoticz.log('Motion state');
        return
        elseif not(cam.active) then
            cam.switchOn()
            domoticz.log('Cam state on');
            cam.switchOff().afterSec(30)
            domoticz.log('Cam state off');
         end
    end
}
thanks in advance
Fredom

Re: Motion script not working

Posted: Tuesday 12 October 2021 15:00
by Fredom
It's working now

Re: Motion script not working

Posted: Thursday 24 February 2022 14:48
by McMelloW
Fredom wrote: Tuesday 12 October 2021 15:00 It's working now
Did you also post the working script version?

Re: Motion script not working

Posted: Thursday 24 February 2022 17:04
by Fredom
McMelloW wrote: Thursday 24 February 2022 14:48
Fredom wrote: Tuesday 12 October 2021 15:00 It's working now
Did you also post the working script version?
This is the script now

Code: Select all

return
{
    on =
    {
        devices = { 
                     'Motion Beerus',  --Xiaomi Human Body Sensor
                     'Beerus',          --kaku schakelaar
                  },

    },
   execute = function(dz)
        local motion = dz.devices('Motion Beerus')
        local   lamp = dz.devices('Beerus') 

    if motion.state == 'On' and lamp.state == 'Off' then
        lamp.switchOn().repeatAfterSec(1, 2)
        lamp.switchOff().afterMin(5).silent().repeatAfterSec(1, 2)
    end
end
}