Page 1 of 1

Hysteresis script

Posted: Wednesday 30 June 2021 11:21
by EddyG
Has anybody a good working hysteresis script based on lux level?
Based on multilevels or better a formula?
I am looking for a scripts which sets the level of bulbs, with 'dimTo()', based on the lux level in the room.

Re: Hysteresis script

Posted: Wednesday 30 June 2021 11:51
by Toulon7559
@EddyG

Perhaps more basic question to be answered before trying to find a control solution:
how do you determine lux level in the room?
And is that lux-reading sufficiently separated from the lamps' light?


Otherwise the risc of 'chicken-and-egg':
- if lamp-level is a dynamic reaction on room's lux-level, and the lux-sensor in some way reads the light of the lamps, then the risc that you get 'flip-flop'-action.

Myself solved this aspect by taking outdoor lightlevel as reference (not indoor), and 'gated' that reference using clock-time and a filter on the value:
- clock ( ~sunset and sunrise) as gate to suppress any on-switching while nominally still bright enough outside
[clock anyway needed to control automated off-switching]
- filter to suppress spikes and dips in the lux-value due to quick variations
Then hysteresis just becomes an add-on to set the upper and lower margin around the switching value.

Re: Hysteresis script

Posted: Wednesday 30 June 2021 13:39
by EddyG
I know that switching on lights have effect on the lux reading. I minimized that.
I am already partially using the outdoor lux to get a more 'stable' lux reading.
That's why I am looking for a "formula" of some kind to prevent the 'flip-flop', because there is always a threshold on which the dimTo() changes.
I am not using on/off bulbs, but bulbs with brightness setting.

Re: Hysteresis script

Posted: Wednesday 30 June 2021 14:06
by waltervl
See viewtopic.php?t=19956 were a hysteresis of 2% is used

Re: Hysteresis script

Posted: Wednesday 30 June 2021 15:55
by EddyG
Tnx, may be I could use parts of it.
I will keep testing....

Re: Hysteresis script  [Solved]

Posted: Thursday 01 July 2021 15:57
by EddyG
Roughly found my 'formula'.

Code: Select all

LUXLEVEL = 50
        local binnenlux = dz.devices(LUX_IN).lux
        local buitenlux = dz.devices(LUX_OUT).lux / 100	-- lux is kind of logarithmic so divide by 100 
        local lux = ((binnenlux + buitenlux) / 2) + 1	-- prevent lux from 0 value
        local brightness = (100/lux) + 8 		-- add a minimum of 10% brightness
        if brightness > 100 then
            brightness = 100				-- max 100% brightness
        end
        if lux < LUXLEVEL then
                dz.devices("<Device>").dimTo(brightness).silent()
 //or
                dz.devices("<Device>").dimTo(brightness/2).silent() -- 2 is factor to get 50% max. brightness
        end
Most important I set my Zigbee bulbs with 'transition: 5'
That means that those bulbs go from X brightness to desired brightness in 5 seconds. That has a good influence on the 'flip flop' effect.
On other settings all kind of different factors might be used.