Lux value only updated after motion is detected <solved>  [Solved]

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

Moderator: leecollings

Post Reply
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Lux value only updated after motion is detected <solved>

Post 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...
Last edited by nitpicker on Wednesday 14 October 2020 15:18, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lux value only updated after motion is detected

Post 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
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

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

Post by nitpicker »

Now it works as intended! It sends two notifications, but I will change it to MS only.

Thanks again!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest