Pushing a button multiple times through script

Moderator: leecollings

Post Reply
leejoow
Posts: 11
Joined: Saturday 05 November 2016 17:30
Target OS: Linux
Domoticz version:
Contact:

Pushing a button multiple times through script

Post 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?
sion
Posts: 113
Joined: Friday 08 January 2016 12:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Pushing a button multiple times through script

Post 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.
running domoticz 3.4834 on rpi2, with
Hue bridge / bulbs.
lightwave rf sockets, mood controlers, sensors & contacts.
Home bridge / Siri.
Ha bridge / echo Alexa.
Hard wired alarm system - setting home / away status.

Next: harmony hub.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Pushing a button multiple times through script

Post 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
}
The most dangerous phrase in any language is:
"We always done this way"
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pushing a button multiple times through script

Post 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:

Code: Select all

sl('dimmer',100);
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');
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest