Scripts for different scenes with one button

Moderator: leecollings

Post Reply
nickgosling
Posts: 33
Joined: Wednesday 06 January 2016 10:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Scripts for different scenes with one button

Post by nickgosling »

Hi,

I am new to Domoticz and scripts in general but I wanted to create a Scene that was run when a switch is pressed but run a different scene when the button is pressed again. I was planning on creating a virtual switch that would flip flop and a script that would look at that virtual device and run one of the scenes accordingly. Is that the most straightforward was to do this or is there a better way to activate scenes with different logic using only one button.

Also, in Vera it was obvious where to put scripts. Do they just go in a text file in the Domoticz folder and are referenced to in the script tab under "when activateda"

Thanks,
Nick
nickgosling
Posts: 33
Joined: Wednesday 06 January 2016 10:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Scripts for different scenes with one button

Post by nickgosling »

Right so as nobody has replied I've spent about a week watching YouTube videos on lua coding. But then I found that I may be able to acheive this in Blocky. Here is my idea.

Two dummy switches
S1 for scene 1
S2 for scene 2
The trigger is i2 on a qubino module.

So here goes.

Event 1.
IF i2 is triggered AND S1 AND S2 == off
Set S1 to ON and set a scene to do whatever you want.

Event 2
IF i2 is triggered AND S1 == ON
Set S1 to OFF, S2 to ON and set a scene to do whatever you want.

Event 3 - OFF
IF i2 is triggered and S2 == ON
Set S2 to off and turn all the lights off

I haven't actually made this in Blocky as I'm a dad of 2 and working shifts so have really little time but if anyone has a better idea before I try it can you post.
Thanks.







Sent from my Nexus 5X using Tapatalk
mrf68

Re: Scripts for different scenes with one button

Post by mrf68 »

Hi,

Suppose you have 2 lights you want to switch. When you press the virtual switch, you can check if light 1 is "On". If not, then turn on light 1. If light 1 is " On", turn light 2 "On".

If you want completely different things to happen, then I think you need to build in a check on how often the button is pressed within a specific period of time. In LUA this is possible, I don't know how to do it in Blockly.

Regards,
Martin
nickgosling
Posts: 33
Joined: Wednesday 06 January 2016 10:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: RE: Re: Scripts for different scenes with one button

Post by nickgosling »

mrf68 wrote:Hi,

Suppose you have 2 lights you want to switch. When you press the virtual switch, you can check if light 1 is "On". If not, then turn on light 1. If light 1 is " On", turn light 2 "On".

If you want completely different things to happen, then I think you need to build in a check on how often the button is pressed within a specific period of time. In LUA this is possible, I don't know how to do it in Blockly.

Regards,
Martin
Thank for the reply Martin. I'll give it a go in Blocky and if not will attempt some lua code. How would you check how many times a button is pressed jn lua. That sounds like something I could apply.

Nick.

Sent from my Nexus 5X using Tapatalk
User avatar
bizziebis
Posts: 182
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8805
Location: The Netherlands
Contact:

Re: Scripts for different scenes with one button

Post by bizziebis »

I do it with LUA like this:

Code: Select all

if devicechanged['Blinds_Toggle_1'] == 'On' then
	if otherdevices['Blinds1'] == 'Open' then
		commandArray['Blinds1']='On'
	elseif otherdevices['Blinds1'] == 'Stopped' then
		commandArray['Blinds1']='On'
	else
		commandArray['Blinds1']='Off'
	end
end
I only press the 'ON' button of the remote to toggle trough different states of my blinds.
You can also trigger a scene with this, then u use:

Code: Select all

commandArray['Scene:Blinds']='On'
nickgosling
Posts: 33
Joined: Wednesday 06 January 2016 10:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Scripts for different scenes with one button

Post by nickgosling »

Thank you for the reply. I'm going to experiment with this later. I'm going to make the virtual switches part of the scene so that each device in a particular scene is unique. That way it will satisfy the if statement.

Sent from my Nexus 5X using Tapatalk
nickgosling
Posts: 33
Joined: Wednesday 06 January 2016 10:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Scripts for different scenes with one button

Post by nickgosling »

So this is my first attempt with LUA. I haven't done any programming scripts since university and that is going back some years. But it works. I forgot how satisfying it is when a script runs correctly but it works anyway.

So this is my script:

commandArray = {}
if (devicechanged['motion sensor'] == 'On' and otherdevices['Dummy 1'] == 'Off' and otherdevices['Dummy 2'] == 'Off') then
commandArray['Scene:Scene 1']='On'
commandArray['Dummy 1']='On'
end
if (devicechanged['motion sensor'] == 'On' and otherdevices['Dummy 1'] == 'On' and otherdevices['Dummy 2'] == 'Off') then
commandArray['Scene:Scene 2']='On'
commandArray['Dummy 2']='On'
commandArray['Dummy 1']='Off'
end
if (devicechanged['motion sensor'] == 'On' and otherdevices['Dummy 1'] == 'Off' and otherdevices['Dummy 2'] == 'On') then
commandArray['Scene:All off']='On'
commandArray['Dummy 2']='Off'
commandArray['Dummy 1']='Off'

end
return commandArray

As I'm new to the language if there are any language housekeeping things that would make this simpler then I would be keen to know them. Obviously my first issue is that if I change any names in Domoticz I will need to re write the scripts. The other thing would be I'm going to have a lot of Dummy switches to make this work throughout my house for all of the other rooms.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest