Lux value = nil.

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

Moderator: leecollings

Post Reply
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Lux value = nil.

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lux value = nil.

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lux value = nil.

Post 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.
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lux value = nil.

Post 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 :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest