Page 1 of 1

Lux value = nil.

Posted: Friday 26 October 2018 10:50
by henning84
Hiii

I have made a script to turn on the light when it get dark in the room. - See code below.

But when I compare the lux value, I do not always get a number. Only if the lux value has changed since last entry. otherwise i get "Nil".

The Lux Sensor is a Xiaomi Motion Sensor with lux. it report the lux value every 5 min.

eg if i compare.

17:55 - lux = 34
18:00 - lux = 30 domoticz.devices('Stue').lux will be "30"
18:05 - lux = 19 domoticz.devices('Stue').lux will be "19"
18:10 - lux = 0 domoticz.devices('Stue').lux will be "0"
18:15 - lux = 0 domoticz.devices('Stue').lux will be "Nil"
18:20 - lux = 0 domoticz.devices('Stue').lux will be "Nil"

Am I doing something wrong..? if i look in the log under the device it show the right value.

I know i can save the value to a variable only if it a valid number and use that for the compair, but it seems a bit like a work around..


Code: Select all

--- Turn on the light when it get dark.
    if (device.name == 'Pir - koekken') and (device.state == 'On') and (domoticz.time.hour <= 8 and domoticz.time.hour >= 6) and (domoticz.devices('Switch - Lampe skaenk').state == 'Off') and (domoticz.devices('Stue').lux <= 20) then 
            domoticz.devices('Switch - Lampe skaenk').dimTo(70)
            print('Lampe på skæmk tændes om morgenen')
    end
thanks in advance

Re: Lux value = nil.

Posted: Friday 26 October 2018 12:03
by waaren
henning84 wrote: Friday 26 October 2018 10:50 Hiii

I have made a script to turn on the light when it get dark in the room. - See code below.

But when I compare the lux value, I do not always get a number. Only if the lux value has changed since last entry. otherwise i get "Nil".

The Lux Sensor is a Xiaomi Motion Sensor with lux. it report the lux value every 5 min.

eg if i compare.

17:55 - lux = 34
18:00 - lux = 30 domoticz.devices('Stue').lux will be "30"
18:05 - lux = 19 domoticz.devices('Stue').lux will be "19"
18:10 - lux = 0 domoticz.devices('Stue').lux will be "0"
18:15 - lux = 0 domoticz.devices('Stue').lux will be "Nil"
18:20 - lux = 0 domoticz.devices('Stue').lux will be "Nil"

Am I doing something wrong..? if i look in the log under the device it show the right value.

I know i can save the value to a variable only if it a valid number and use that for the compair, but it seems a bit like a work around..


Code: Select all

--- Turn on the light when it get dark.
    if (device.name == 'Pir - koekken') and (device.state == 'On') and (domoticz.time.hour <= 8 and domoticz.time.hour >= 6) and (domoticz.devices('Switch - Lampe skaenk').state == 'Off') and (domoticz.devices('Stue').lux <= 20) then 
            domoticz.devices('Switch - Lampe skaenk').dimTo(70)
            print('Lampe på skæmk tændes om morgenen')
    end
thanks in advance
I must have received my Xiaomi Motion Sensors from a different batch, as I allways have a value for lux; both in the devices tab as in dzVents. If this cannot be solved in the Xiaomi hub or device, the only other option I see would be indeed to store the last known valid lux value.
Maybe something like:

Code: Select all

-- checkLux.lua

return { 
        
        
        on =        { timer   =   {"every 1 minutes"}
                    },
    
        logging =   {   level   =   domoticz.LOG_DEBUG,
                        marker  =   "checkLux" },
    
        data    =   {   lastKnownValidLux = { initial = 0 }},
               
    execute = function(dz)
        
        dz.data.lastKnownValidLux = domoticz.devices('Stue').lux or dz.data.lastKnownValidLux
        
        --- Turn on the light when it get dark.
        if  (device.name == 'Pir - koekken')                            and 
            (device.state == 'On')                                      and 
            (domoticz.time.hour <= 8 and domoticz.time.hour >= 6)       and 
            (domoticz.devices('Switch - Lampe skaenk').state == 'Off')  and 
            (tonumber(dz.data.lastKnownValidLux) <= 20)                         then 
                
                domoticz.devices('Switch - Lampe skaenk').dimTo(70)
                print('Lampe på skæmk tændes om morgenen')
        end
        
    end
}

Re: Lux value = nil.

Posted: Friday 26 October 2018 12:52
by henning84
Are you on the latest Domoticz beta..? i use the latest stable version.. Maybe thats the difference.

Xiaomi gateway is on the latest version.

Re: Lux value = nil.

Posted: Friday 26 October 2018 13:38
by henning84
Dammm... I found the problem :)

If i use the IDX number instead it work.
It turns out that I have another device called "Stue" under Temp and the Lux sensor call "Stue".. so the rule has not always used the lux sensor.

why it works when the lux sensor send a new valid value i can not figure out. But thanks any way :)