dimming a group  [Solved]

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

Moderator: leecollings

Post Reply
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

dimming a group

Post by snellejellep »

Hi all,
i tried making a script which allows a dimmer switch control and dim a group.
simple on/off worked but i tried reading this script and use some things to let the group dim: https://www.domoticz.com/forum/viewtopi ... 28&t=23568
but unfortunately i get this error and i have no clue:

Code: Select all

2019-11-27 16:51:02.266 Error: dzVents: Error: (2.5.0) An error occurred when calling event handler knop group tk
2019-11-27 16:51:02.266 Error: dzVents: Error: (2.5.0) ...ticz/scripts/dzVents/generated_scripts/knop group tk.lua:14: attempt to index a nil value (field 'data')
this is the script:

Code: Select all

return {
	on = {
		devices = {
			'Tuinkamer licht'
		}
	},
	execute = function(dz, device)
		dz.log('Device ' .. device.name .. ' was changed', dz.LOG_INFO)
		
		local switch        = dz.devices("Tuinkamer licht")
		local group         = dz.groups("Tuinkamer licht")
		
		if switch.state == "On" and switch.level > 0 then
		    dz.data.dimLevel =  switch.level
		    group.switchOn()
		    group.dimTo(tonumber(dz.data.dimLevel))
		elseif switch.state == "Off" then
		    group.switchOff()
		end
		
	end
}
i hope someone can help me
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
zicht
Posts: 300
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: dimming a group

Post by zicht »

As far as i know a group cannot be dimmed, lamps can be dimmed.
What you can do is read one switch (define that as somekind of a group master in your thoughts)

Then with a script like above change the dimming value based on that master switch value for every individual lamp :)
Maybe that way it will work.
Not sure how it works in dzevents

in lua it would be something like
a=otherdevices["lamp1"]
commandArray["lamp2"]=a
commandArray["lamp3"]=a
commandArray["lamp4"]=a

this way the value of lamp1 will be copied to the others :)
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: dimming a group

Post by snellejellep »

zicht wrote: Wednesday 27 November 2019 17:10 As far as i know a group cannot be dimmed, lamps can be dimmed.
What you can do is read one switch (define that as somekind of a group master in your thoughts)
you can with a script, i tried before and it seems to work.
unfortunately i do not know lua, all my scripts are in dzvents
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
zicht
Posts: 300
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: dimming a group

Post by zicht »

"you can with a script, i tried before and it seems to work."

Maybe you can use same approach in DZ ? dimm all lamps upon value change ?
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: dimming a group

Post by snellejellep »

zicht wrote: Wednesday 27 November 2019 18:00 "you can with a script, i tried before and it seems to work."

Maybe you can use same approach in DZ ? dimm all lamps upon value change ?
yes but i need to extract the current value of the switch and use that value to dim the group to that value
the only thing is i do not know how to do that... setting a static dimmed value i do know but this i don't ant that is exactly my question, how do i do that in dzvents
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dimming a group

Post by waaren »

snellejellep wrote: Wednesday 27 November 2019 18:03 yes but i need to extract the current value of the switch and use that value to dim the group to that value
the only thing is i do not know how to do that... setting a static dimmed value i do know but this i don't ant that is exactly my question, how do i do that in dzvents
Something like this ?

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'Tuinkamer licht' -- device Trigger
        },
    },
    
    logging = 
    { 
        level = domoticz.LOG_DEBUG
    },
    
    execute = function(dz, item)
        _G.logMarker =  _G.moduleLabel
    
        local myGroup = dz.groups('Tuinkamer licht') -- Confusing ! Can you rename device or group ?
        
        if item.state ~= 'Off' and item.level > 0 then
            myGroup.devices().forEach(function(dv)
                dz.log(dv.name ..' ==>> device-level: ' .. dv.level,dz.LOG_FORCE)
                dv.dimTo(item.level)
           end)
        elseif item.state == 'Off' then
            dz.log(item.name ..'; state: ' .. item.state,dz.LOG_FORCE)
            myGroup.switchOff()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: dimming a group  [Solved]

Post by snellejellep »

waaren wrote: Wednesday 27 November 2019 18:50
Something like this ?
great! that is exactly what i was looking for!
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
dheuts
Posts: 65
Joined: Monday 25 March 2019 15:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Brunssum, Netherlands
Contact:

Re: dimming a group

Post by dheuts »

Thanks a lot for this script, great.
I'm looking for some script like this, to control the color temperature (Kelvin) of a group (RGBWW).
Can someone please help me with this? I think we have to do something in the script with:
getColor
SetKelvin

But I'm not sure how to get this running. Is it possible with the same device as the brightness slider? Or do we need another one?

UPDATE: Got it running with this script:
viewtopic.php?f=59&t=29498&p=247523#p224734
waaren wrote: Wednesday 27 November 2019 18:50
snellejellep wrote: Wednesday 27 November 2019 18:03 yes but i need to extract the current value of the switch and use that value to dim the group to that value
the only thing is i do not know how to do that... setting a static dimmed value i do know but this i don't ant that is exactly my question, how do i do that in dzvents
Something like this ?

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'Tuinkamer licht' -- device Trigger
        },
    },
    
    logging = 
    { 
        level = domoticz.LOG_DEBUG
    },
    
    execute = function(dz, item)
        _G.logMarker =  _G.moduleLabel
    
        local myGroup = dz.groups('Tuinkamer licht') -- Confusing ! Can you rename device or group ?
        
        if item.state ~= 'Off' and item.level > 0 then
            myGroup.devices().forEach(function(dv)
                dz.log(dv.name ..' ==>> device-level: ' .. dv.level,dz.LOG_FORCE)
                dv.dimTo(item.level)
           end)
        elseif item.state == 'Off' then
            dz.log(item.name ..'; state: ' .. item.state,dz.LOG_FORCE)
            myGroup.switchOff()
        end
    end
}
Raspberry Pi 4 With Domoticz - RFXCom - Tuya Wifi LED lights - Chuango Alarm - Zwave+ - Zigbee2MQTT - Anna Thermostat - Broadlink IR, P1 - Eufy Robo Vacuum - Worx Robo Mower
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest