Lux-controlled ECO-DIM.05 - Duo Zigbee

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

Post Reply
janpep
Posts: 288
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Lux-controlled ECO-DIM.05 - Duo Zigbee

Post by janpep »

A fun little project to combine my new lux meter and new duo dimmer in a temporary 'self-triggering' DzVents script.

Here is a brief overview of my setup:
1. A first script sets a user variable to indicate whether someone is home. It is triggered by a Wi-Fi or geofence change.
2. A second script sets a user variable to indicate the part of day. (I define 1=day based on my alarm clock, 2=twilight based on lux and avg lux in 20 minutes, 3=evening based on lux and avg lux in 20 minutes, and 4=night when a specific room light goes off between 10:00 PM and 2:00 AM.). It is triggered by devices, system events (start) and timers.
3. A third script switches various devices, lights, PIR, and camera motion detection on or off depending on the part of day and our presence, and some based on specific time. It is triggered by changes of variables and timers.

In my case, determining evening means the moment the lights in the room have to turn on. Initially, I had set this to xx minutes before sunset. That usually worked out well. Sometimes a bit too early on a bright day, and sometimes a bit too late on a gloomy day. With the lux value, I now use a combination of both the current value and an average of the past 20 minutes (values kept in persistent data). This takes the trend into account. That prevents the lights from suddenly turning on too early when a cloud passes or someone stands in front of the lux meter, which can cause falsely low readings.

I recently purchased a dual ZigBee built-in dimmer. See: https://www.ecobright.nl/zigbee-duo-led ... igbee.html
I have integrated the control for this dimmer into in the situation described above using a separate script.

The dimmer It is linked to Domoticz via:
  • SONOFF Zigbee 3.0 USB Dongle Plus | ZBDongle-E
  • Zigbee2mqtt
  • MQTT
Initially, I had a bit of trouble getting this working. It turned out that zigbee2mqtt support had only recently been added or improved. (The device was already listed, but it still was not working properly and was not recognized at first.)
In my situation, however, an upgrade turned out to be necessary to current version at this moment:
Zigbee2MQTT-versie 2.7.1, commit: 8916fb7b, with Frontendversion 2.4.2, zigbee-herdsman-converters version 25.83.1 and zigbee-herdsman version 7.0.4.
This resulted in immediate recognition of the dimmer in zigbee2mqtt and and also display in Domoticz.
EcoDim01-JanPep.png
EcoDim01-JanPep.png (64.53 KiB) Viewed 46 times
EcoDim02-JanPep.png
EcoDim02-JanPep.png (95.73 KiB) Viewed 46 times
I have hidden the ones for the power on behaviour, because once set up it does not need to be controlled from Domoticz for me.

During the transition from dusk to evening, I wanted the left dimmer, which controls a spotlight, to gradually increase its intensity to a certain value, while outside it is getting darker.
It was a fun puzzle, but I found it somewhat complicated with a timer trigger.
Here is how I solved it easily with a device trigger and a delayed setting of the dimmer, which causes a self triggering script at a set interval until the goal is reached.

It should perhaps be mentioned that in my situation the lux meter is in the view of the spotlight to be operated.
In this case that is great for determining whether the desired light level has been reached.
  • The script mentioned in point 3 switches the dimmer on at a low level. The moment of activation is therefore determined in that script in accordance with other lighting.
  • The script 'd-DimAchter2Level' is then triggered by switching on the dimmer.
  • The desired lux value (lux_treshold) and the time interval (increase_interval) by which the value should be increased are predefined.
  • If part of the day = evening and dimmer = On and the current lux value < the desired value, action is taken. The value is increased after the set interval.
  • I use a lux_cutoff point to start increasing the level with smaller steps to prevent a large overshoot.
  • Then the dimmer level is adjusted, which triggers the script again. Doing so it creates a loop that ends when the desired level is reached or slightly exceeded. In that case the dimmer is no longer adjusted, and the script stops triggering.
Of course, the script is triggered when the dimmer is turned off (manually or otherwise), but then the conditions are not met and therefore no action is taken.

For now, this seems to be working well for me.
Not because it is very needed, but simply because it is possible.

Maybe you can do something with it (in an adapted form).
Note: You will need to adjust the lux level for your situation.
Note: You will need to change something to define 'evening'.

Script d-DimAchter2Level:

Code: Select all

-- 16-12-2025 Script by Jan Peppink; hppts://ict.peppink.nl
--    Result: Step by step  increase dimlevel until wanted lux value is reached.
-- Note that in my case the dimmer is switched on by another script at a low dim level.
-- Then this script is triggered bythe device change. Therefore setting is made after xx minutes (increase_interval).
-- Only action when Dimmer is On at some level (state~= "Off")
-- Only action when  it is evening (dagavondnacht = 3)
-- Onlyu action when lux is below lux_treshold.

--- Your settings ----------------------------------------------------------------
-- First set the used device index numbers and variables you might want to change.
local lux_idx = 1127          -- idx of the lux device.
local left_ecodim_idx = 1146  -- idx of the dimmer device.
local lux_treshold = 900      -- Set dimmer to reach this lux level.
local lux_cutoff = 150        -- Smaller steps for remaining lux increase
local increase_interval = 2       -- Time in minutes for next check / step.
--------------------------------------------------------------------------------
return {
	on = {
		devices = {
			left_ecodim_idx,
		},
	},
	logging = {
	    -- Level can be domoticz.LOG_INFO, domoicz.LOG_MODULE_EXEC_INFO, domoticz.LOG_DEBUG, domoticz.LOG_ERROR or domoticz.LOG_FORCE
        level = domoticz.LOG_INFO,
        --level = domoticz.LOG_DEBUG,
        marker = "DimAchter-"
    },
	execute = function( dz, triggeredItem )
        -- Set Local environment=================
        --local _u = dz.utils       -- Holds subset of handy utilities.
        --local _h = dz.helpers     -- Holds the global functions.
        --local _d = dz.globalData  -- Holds the global data.
        local dagavondnacht = dz.variables('DagAvondNachtStand').value  -- 1 = day, 2 = twilight, 3 = evening, 4 = night.
        local cur_lux = dz.devices(lux_idx).lux                 -- Current lux level            

        -- Local Functions go here =============
    


        -- Now start to do something ============

        -- Script triggered by dimmer change.
        if dz.devices(left_ecodim_idx).state ~= 'Off' and dagavondnacht == 3 and cur_lux < lux_treshold then
            --Dimmer is turned on or has changed and it is evening and lux < treshold.
            local cur_dimlevel = dz.devices(left_ecodim_idx).level  -- Current dim level
            local set_dimlevel = 0                                  -- Default set level

            if lux_treshold - cur_lux > lux_cutoff then
                -- Increase with greater steps when remaining increase > lux_cutoff
                set_dimlevel = cur_dimlevel + 5
            elseif lux_treshold - cur_lux <= lux_cutoff and lux_treshold - cur_lux > 0 then
                -- Increate with smaller steps when remaining increase <= lux_cutoff
                set_dimlevel = cur_dimlevel + 2
            end
            
            -- Check for 100% = maximum.
            if set_dimlevel > 100 then set_dimlevel = 100 end
            
            if cur_dimlevel ~= set_dimlevel then
                -- Change DimAcbhterLevel
                dz.devices(left_ecodim_idx).dimTo(set_dimlevel).afterMin(increase_interval)
                dz.log( 'Lux = ' .. cur_lux .. ', zet DimAcbhterLevel naar ' .. set_dimlevel, dz.LOG_DEBUG )
            end
        end
	end
}
-- That's All --------------------------------------------------
Dz on Ubuntu VM on DS718+ behind FRITZ!Box.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest