Set Dimmer/Switch default to percentage

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

Moderator: leecollings

Post Reply
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Set Dimmer/Switch default to percentage

Post by gschmidt »

Hi,

I have created a Selector Switch/Dimmer for a Yeelight LED Bulb RGBWW lamp.
In dzVents have created a script to dim the brightness of the lamp.

The script works but I want the slider of the Dimmer always to start at 25% when the Lamp is turned on again.
The current script remembers, when the lamp is set to OFF, the last slider location.

I already tried the device.dimTo(25) function, but this triggers strange behaviour, because dimming also to turn on the lamp.

Can somebody help me with this?

Code: Select all

return {
    active = true,
    on = { 
        devices = { 'Hoek Lamp 1'}
    },
    execute = function(domoticz, device)
        port = '55443'
        yeelights = {'192.168.1.57'}
        for ix, ipadress in ipairs(yeelights) do
            if (device.state == 'Off') then
                domoticz.log('Turning light off')
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | nc -w1 " ..ipadress.." " ..port..""
                os.execute(runcommand)
            else
                domoticz.log('Changing brightness level')
                brightvalue = (device.level - 1);
                runcommand = "sudo echo -ne '{\"id\":1, \"method\":\"set_scene\",\"params\":[\"ct\", 3000, " .. brightvalue .. "]}\\r\\n' | nc -w1 " ..ipadress.." " ..port..""
                -- device.dimTo(25);
                os.execute(runcommand)
            end
        end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Set Dimmer/Switch default to percentage

Post by waaren »

gschmidt wrote: Monday 31 December 2018 17:11 I already tried the device.dimTo(25) function, but this triggers strange behavior, because dimming also to turn on the lamp.
Did you try this ?

Code: Select all

device.dimTo(25).silent() 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Set Dimmer/Switch default to percentage

Post by gschmidt »

I tried several positions in the script, but none of them gave the desired result

When I place device.dimTo(25).silent() in the ELSE part: When I slide to other values, the slider always returns to 25% (and I want the slider to return to 25% after the Lamp is set to OFF.)

When I place device.dimTo(25).silent() in the IF part (where the lamp is set to OFF): The Lamp is off and the slider is set at 25%, this appears to work but the Switch object is not showing off but at 25% and with an ON icon, although the lamp is off???

Anyway, I also found a workaround creating a group (scene)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Set Dimmer/Switch default to percentage

Post by waaren »

gschmidt wrote: Thursday 03 January 2019 12:53 I tried several positions in the script, but none of them gave the desired result

When I place device.dimTo(25).silent() in the ELSE part: When I slide to other values, the slider always returns to 25% (and I want the slider to return to 25% after the Lamp is set to OFF.)

When I place device.dimTo(25).silent() in the IF part (where the lamp is set to OFF): The Lamp is off and the slider is set at 25%, this appears to work but the Switch object is not showing off but at 25% and with an ON icon, although the lamp is off???

Anyway, I also found a workaround creating a group (scene)
Script below works for me.

Code: Select all

return {
    active = true,
    on = { 
        devices = { 'Hoek Lamp 1' }
    },
    
    
           logging =   {   
                         level         =   domoticz.LOG_DEBUG,                   
                        marker        =   "YL control"
                    },
                    
    execute = function(domoticz, device)
        port = '55443'
        yeelights = {'192.168.1.57'}
        for ix, ipadress in ipairs(yeelights) do
            if (device.state == 'Off') then
                domoticz.log('Turning light off')
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | nc -w1 " ..ipadress.." " ..port..""
                os.execute(runcommand)
				device.dimTo(25).silent()
				device.switchOff().afterSec(1).silent()
			else
                domoticz.log('Changing brightness level')
                brightvalue = (device.level - 1);
                domoticz.log("brightvalue: " .. brightvalue ,domoticz.LOG_DEBUG)
                runcommand = "sudo echo -ne '{\"id\":1, \"method\":\"set_scene\",\"params\":[\"ct\", 3000, " .. brightvalue .. "]}\\r\\n' | nc -w1 " ..ipadress.." " ..port..""
                os.execute(runcommand)
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest