Page 1 of 1

Fetching changes inside lua script

Posted: Wednesday 18 October 2017 16:29
by zynexiz
Hi.

I have a wall switch that I use to control some lamps with dimmer function. I have NoOn Wall Switch Cozy White and Aeon Labs dimmers. Each button on the wall switch have 4 functions; press, press and hold, release and double click. When using the press and hold function, the LUA script starts the dimmer routine (up or down), and when I release the button it's supposed to stop dimming.

The problem is that the script don't get the release signal from the wall switch. As far as I can understand, the info sent to the script is static, and any triggers made during the execution isn't recognized inside the script? This means that the release signal from the wall switch wont be captured by the script. I'm a wrong, or is there a way round this limitation?

Right now I have a different, not very practical, solution.

Code: Select all

return {
	active = true,
	on = {
		devices = {
		'BT:*', 'BS:*'
		}
	},
	execute = function(domoticz, switch)
		local func = {}
		func['BT: B1 - Press'] = {f = 'on/dim', device = 'Lampor trappa', step = 10, lmin = 18}
		func['BT: B2 - Press'] = {f = 'dim', device = 'Lampor trappa', step = -10, lmin = 18}
		func['BT: B2 - Hold'] = {f = 'off', device = 'Lampor trappa', step = 10, lmin = 18}
		func['BT: B3 - Press'] = {f = 'on/dim', device = 'Lampor tak', step = 10, lmin = 28}
		func['BT: B4 - Press'] = {f = 'dim', device = 'Lampor tak', step = -10, lmin = 28}
		func['BT: B4 - Hold'] = {f = 'off', device = 'Lampor tak', step = 10, lmin = 28}
		
		func['BS: B1 - Press'] = {f = 'on', device = 'Taklampor sovrum', step = 0, lmin = 0}
		func['BS: B2 - Press'] = {f = 'off', device = 'Taklampor sovrum', step = 0, lmin = 0}
		func['BS: B3 - Press'] = {f = 'on/dim', device = 'Lampor tak', step = 10, lmin = 28}
		func['BS: B4 - Press'] = {f = 'dim', device = 'Lampor tak', step = -10, lmin = 28}
		func['BS: B4 - Hold'] = {f = 'off', device = 'Lampor tak', step = 10, lmin = 28}

		local dev = domoticz.devices(func[switch.name].device)
		
		if dev.state == 'On' and string.find(func[switch.name].f, 'dim') then
			dimLevel = math.min(math.max(func[switch.name].lmin,dev.level + func[switch.name].step),99)
			
			dev.dimTo(dimLevel)
		elseif string.find(func[switch.name].f, 'off') then
			dev.switchOff()
		elseif string.find(func[switch.name].f, 'on') then
			dev.switchOn()
		end
		
end
}
I really want the press and release way of doing it.

Re: Fetching changes inside lua script

Posted: Wednesday 18 October 2017 17:37
by emme
unfortunately I don0t think this could be done :(

You are right... the script is fired at the first signal, then, by design, the script is lunched with a table created ad-hoc for it
Script interact with this table that have the values at the time the script was lunched... actually there is no way to interact with real-time values

a change in a parameter will generate the script to be lunch again (the table will reflect the new value)

Re: Fetching changes inside lua script

Posted: Sunday 29 October 2017 13:34
by zynexiz
Like I thought then. This is kinda bad, because press and hold functions renders pretty useless then if you wanna add that kind of functionality to the system. I used Fibaro HC2 before, and it had the same limit. I created a dirty solution on my HC2 that worked 3-4 out of 5 times. I created a second script that just killed the first script that dimmed the lights. Not a very nice way of doing it thou.

I guess that Python scripts have the same limitation? I have thought of trying to use global values that can be changed when release is triggered, but I guess that those are static inside the script to?