Page 1 of 1
Pushing a button multiple times through script
Posted: Tuesday 24 October 2017 20:07
by leejoow
I'm using push buttons to set a light brighter or darker. This is done by using two different buttons, which send each a differtent signal through FxCom. Now I want to create a script which sends the signal for brighter 20 times to set it to max ilumination. Has anyone any ideas how I could do this?
Re: Pushing a button multiple times through script
Posted: Wednesday 25 October 2017 1:31
by sion
I’m not that good with scripting, so there is probably an easier way to do this, but you could try this with 2 blockys and variables.
Create a variable called X ( or what ever you want , brightness maybe?. )
Blocky 1
If
button = on. And X = 0
Set x = 1
Set button = off
Else if
button = on. And X = 1
Set x = 2
Set button = off
button = on. And X = 2
Set x = 3
Set button = off
And so on all the way up to 20........
Blackly 2
If x = 1
Set light to 5%
Else if
x = 2
Set light to 10%
..........and so on.....
This is probably a messy way to do it, but should work??
Siôn.
Re: Pushing a button multiple times through script
Posted: Wednesday 25 October 2017 8:21
by emme
try in dzVents:
first of all set a off delay of about 1sec to the pushbutton (of course this would you take at least 20secs to bright all the lamp)
I assume the lamp does not provide feedback about its state, so you have a custom dimmer device... but in any case my script will not consider the level of the device, but i will store the % in a reusable variable...
Code: Select all
return {
on = {
devices = {'buttonUp', 'buttonDown'},
data = { lastBright = { initial = 0 } }
},
execute = function(domoticz, device, triggerInfo)
local lamp = domoticz.devices(brightLamp)
local maxBright = 100 -- % of max bright, reached this value, pushing the Up button will not do anything)
local usedStep = 20 --how many steps you want to reach it
local stepLight = maxBright / usedStep -- gathered the amount of % to add os substract
local newValUP = domoticz.data.lastBright + stepLight
local newValDN = domoticz.data.lastBright - stepLight
if triggerInfo.trigger == 'buttonUp' and device.state == 'On' and domoticz.data.lastBright <= maxBright then -- pushed the UP button
lamp.SetLevel = newValUP
domoticz.data.lastBright = newValUP
elseIf triggerInfo.trigger == 'buttonDown' and device.state == 'On' and domoticz.data.lastBright >= 0 -- pushed the DOWN button
lamp.SetLevel = newValDN
domoticz.data.lastBright = newValDN
end if
end
}
Re: Pushing a button multiple times through script
Posted: Wednesday 25 October 2017 13:17
by Egregius
If you can set the dimlevel with a slider in domoticz you don't need to loop 20 times.
In pass2php that would be just:
If you can't use a slider and really need the push buttons that would be:
Code: Select all
for($x=1;$x<=20;$x++)sw('button','On');