LUA script to cycle Hue scenes with one button

Moderator: leecollings

Post Reply
hamster
Posts: 42
Joined: Friday 28 April 2017 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: USA
Contact:

LUA script to cycle Hue scenes with one button

Post by hamster »

Edit: see my post a couple posts down. Fixed the issue by going a different direction with the script. Updated post title to help anyone searching in the future.

Can anyone think of a way to speed up this script? When I activate it multiple times in quick succession, I'm noticing it's not finishing before the next activation, causing unwanted behavior.

This script is called by my harmony remote via habridge. Ideally, I'd like to be able to quickly cycle through the different scenes, but currently have to wait about 5 seconds between each button press.

If it can't be sped up, does anyone know how I might re-do it so that I could, say, click quickly 3 times and that click count would be passed to the uservariable? Thinking that by having it count as the very first step would at least prevent it from needing to process the whole string each time.
Disclaimer: My knowledge is limited and I usually just borrow code and mod it to my needs. Can't really write on my own yet.

Thanks for any ideas!

Code: Select all

commandArray = {}

--Living Room
if (devicechanged['Harmony Living Cycle'] == 'On') then
  scenes={"Scene Daylight Living","Scene Bright Living","Scene Bias Light Living","Scene Dim Living"}
  cur_scene=uservariables["CurLivingScene"]
  cur_scene = cur_scene + 1
  if (cur_scene==5) then
    cur_scene=1 
    commandArray['Variable:CurLivingScene'] = '1'
    print(scenes[cur_scene])
    commandArray[scenes[cur_scene]]='On'
  else
    print(scenes[cur_scene])
    commandArray[scenes[cur_scene]]='On'
    commandArray['Variable:CurLivingScene'] = tostring(cur_scene)
  end
end

if (devicechanged['Harmony Living Cycle'] == 'Off') then
  commandArray['Group Living Room']='Off'
  commandArray['Variable:CurLivingScene'] = '0'
end


return commandArray
portions of code borrowed from wormiedk
Last edited by hamster on Tuesday 19 December 2017 4:35, edited 3 times in total.
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Help speeding up my LUA script

Post by freijn »

Not an answer to your question :

Why do you cycle? Why not directly choose the one you like?

other option :

Get a Vswitch.. count how many times it was pressed in the last 10 sec. set the scene. Run the slow script according to the switch.
Not so easy to code, you need a variable keeping track of the # of presses.. and act.

Cheers,
Frank
hamster
Posts: 42
Joined: Friday 28 April 2017 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: USA
Contact:

Re: Help speeding up my LUA script

Post by hamster »

freijn wrote: Monday 18 December 2017 7:46 Not an answer to your question :

Why do you cycle? Why not directly choose the one you like?
Well, the Harmony Elite only has 4 buttons you can assign to Home Control functions and I have 4 scenes in 3 rooms I'd like to be able to control :\
hamster
Posts: 42
Joined: Friday 28 April 2017 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: USA
Contact:

Re: Help speeding up my LUA script

Post by hamster »

Changed the script to this and is now working with quick presses :)

Code: Select all

commandArray = {}

--Living Room
if devicechanged['Harmony Living Cycle'] == 'On' then
  if otherdevices['Scene Daylight Living'] == 'On' then
    commandArray['Scene Bright Living'] = 'On'
    commandArray['UpdateDevice'] = '108|0|Off'
  elseif otherdevices['Scene Bright Living'] == 'On' then
    commandArray['Scene Bias Light Living'] = 'On'
    commandArray['UpdateDevice'] = '69|0|Off'
  elseif otherdevices['Scene Bias Light Living'] == 'On' then
    commandArray['Scene Dim Living'] = 'On'
    commandArray['UpdateDevice'] = '139|0|Off'
  elseif otherdevices['Scene Dim Living'] == 'On' then
    commandArray['Scene Daylight Living'] = 'On'
    commandArray['UpdateDevice'] = '70|0|Off'
  else
    commandArray['Scene Daylight Living'] = 'On'
  end
end

if (devicechanged['Group Living Room'] == 'Off') then
  commandArray['Harmony Living Cycle'] = 'Off'
    commandArray['UpdateDevice'] = '108|0|Off' --Scene Daylight Living
    commandArray['UpdateDevice'] = '69|0|Off' --Scene Bright Living
    commandArray['UpdateDevice'] = '139|0|Off' --Scene Bias Light Living
    commandArray['UpdateDevice'] = '70|0|Off' --Scene Dim Living
end

return commandArray
'updatedevice' is changing the status of the switch for the scene to 'off' without firing an action, since when turning 'off' a HUE scene, domoticz is actually still sending the json to turn it on...
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest