Page 1 of 1

Lux value only updated after motion is detected <solved>

Posted: Wednesday 14 October 2020 8:51
by nitpicker
I've a Aqara motion sensor that also shows the amount of lux. I want only execute an action when there is motion when the amount of lux is lower then a certain value. The problem is, the lux is only updated as soon as it detects motion... How can I execute the script once the lux value is updated and motion is triggered?

Code: Select all

return
{
    on =
    {
        devices = {
            'MS','MSL'
    }
},
    execute = function(domoticz, device)
        
        if ((device.name == 'MS' and device.active) and (device.name == 'MSL' and device.lux < 10 )) then
            domoticz.notify('Motion', 'Motion triggered', domoticz.PRIORITY_EMERGENCY)
        end
    end
}
I tried the above solution, but that didn't work, of course...

Re: Lux value only updated after motion is detected

Posted: Wednesday 14 October 2020 10:00
by waaren
nitpicker wrote: Wednesday 14 October 2020 8:51 I want only execute an action when there is motion when the amount of lux is lower then a certain value.
Could look like below,
It might send the notification twice. Then change 'MS','MSL', to 'MS' ,

Code: Select all

return
{
    on =
    {
        devices = 
        {
            'MS','MSL',
        },
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when all runs ok
        marker = 'lux on motion',
    },
    
    execute = function(dz)
        
        local motionSensor = dz.devices('MS')
        local luxSensor = dz.devices('MSL')
        
        if motionSensor.active and ( luxSensor.lux < 10 ) then
            dz.notify('Motion', 'Motion triggered', dz.PRIORITY_EMERGENCY)
        end
    end
}


Re: Lux value only updated after motion is detected  [Solved]

Posted: Wednesday 14 October 2020 15:18
by nitpicker
Now it works as intended! It sends two notifications, but I will change it to MS only.

Thanks again!