Lua, and push buttons

Moderator: leecollings

Post Reply
robertj
Posts: 2
Joined: Sunday 13 November 2016 20:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Lua, and push buttons

Post by robertj »

Hi all, in my setup, I have a number of push buttons trigger different scenes (e.g. full light, dimmed light, etc.).

This works well when the push buttons are configured as activation devices for the scene, e.g.
1) Push button 1 selects full light
2) Push button 2 selects dimmed light
3) Push button 1 selects full light

I was trying to script (Lua) the behavior such that pressing push button 1 again would go to dimmed light, and another time for full light.

The problem I encounter is that the Lua variables do not show that push button 1 caused the script to run; the 'devicechanged' variable does not show push button 1 to be changed the second time, since according to Domoticz, the push button was already "on".

Any simple way, scripting or configuration, to achieve my desired behavior (i.e. pushing the push button another time changes to a different scene)?

Robert
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Lua, and push buttons

Post by Nautilus »

You can for example create a uservariable (type integer in this example) and create a LUA script that has three conditions, each of which also check the uservariable value. The first condition(s) will add 1 to the uservariable value and the last will reset it to 1 (or 0). This will allow you to run a different action on each press of the push button. I use similar approach in a selector switch that circles MiLight lamps from On (last dim level) -> 100% -> 50% -> 25% -> 100% and so on...
robertj
Posts: 2
Joined: Sunday 13 November 2016 20:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua, and push buttons

Post by robertj »

Thanks Nautilus,

Unfortunately, the user variable part was already working, the 'detect the click event' part not.

After pushing button 1 to 'off', and pushing it 'on', I see the event in the 'devicechanged' table. If I then push it 'on' again, the button is not contained in 'devicechanged', presumably because Domoticz already considers the switch 'on' after the first press.

Robert
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Lua, and push buttons

Post by Nautilus »

robertj wrote:Thanks Nautilus,

Unfortunately, the user variable part was already working, the 'detect the click event' part not.

After pushing button 1 to 'off', and pushing it 'on', I see the event in the 'devicechanged' table. If I then push it 'on' again, the button is not contained in 'devicechanged', presumably because Domoticz already considers the switch 'on' after the first press.

Robert
Strange, I presume you are using some "standard" dummy device (as I am too)? There is a "devicechanged" event in my case for each action, no matter if it is the same as the current state. Well, this is true at least with selector switches and "push on" and "push off" buttons. As I see it, if you are using standard "On/Off" button you always need to toggle it from the web interface (there is only one place to push and this toggles the state) so how exactly you then push "On" for the second time? In any case, you can create a selector switch with only one level ( = "on") in addition to "off" so then you have a switch that has both off and on buttons and that will create a devicechanged event for each press of "on" (and "off")...:)
PimJanse
Posts: 6
Joined: Saturday 03 June 2017 7:55
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Lua, and push buttons

Post by PimJanse »

Hello Robert / Nautilus,
I'm quite new with Domoticz LUA, but I'm searching for a way to control my MiLight lamps (via a v6 Wifi bridge) from LUA. Could you please share your LUA script that control the MiLight lamps? That could help me a lot!
Thanks, Pim
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Lua, and push buttons

Post by freijn »

This is how i with a single button ( 1 press generates a single on only) switch on and off my lights.
it is a device lua script.

Code: Select all

commandArray = {}
if (devicechanged['SecDeurbel'] == 'On') then
   if (otherdevices['LampFrank2'] == 'Off') then
       commandArray['LampFrank2']='On'
       commandArray['LampFrank']='On'
   else
       commandArray['LampFrank2']='Off'
       commandArray['LampFrank']='Off'
   end
   commandArray['SecDeurbel']='Off'
end
return commandArray
PimJanse
Posts: 6
Joined: Saturday 03 June 2017 7:55
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Lua, and push buttons

Post by PimJanse »

Yes, thanks for the example!
I do understand this, but I'm specifically looking for a way to manually control my MiLight lamps by sending commands to my Wifi bridge (v6). I would like to set them on/off, color, dimming etc. Anyone done this from a LUA script?
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Lua, and push buttons

Post by Nautilus »

PimJanse wrote:Yes, thanks for the example!
I do understand this, but I'm specifically looking for a way to manually control my MiLight lamps by sending commands to my Wifi bridge (v6). I would like to set them on/off, color, dimming etc. Anyone done this from a LUA script?
Saw the PM before this post, and I think I mostly explained on my reply to that PM how I use selectors with MiLights. I.e. either calling the domoticz switch or a nodejs script (https://github.com/mwittig/node-milight-promise/) which actually shouldn't be needed anymore (ok, you can do a bit more with the script still) now that the feature are integrated to Domoticz... :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest