Page 1 of 1

Lua to cycle hue scenes

Posted: Sunday 05 March 2017 21:58
by wormiedk
I have a hue system with multiple scenes which are all imported in to domoticz as push buttons. I have been trying to write a script that cycles the scenes using one button on an RF remote.


I have a user variable called CurSceneStue and the remote Is called REM Stue A. The variable "stue_scenes" contains a list of the scenes (push buttons) I would like to cycle through.

My script looks as follows

Code: Select all

commandArray = {}

stue_scenes={"Hue Scene Stue Morgen","Hue Scene Stue Hvid","Hue Scene Stue Film","Hue Scene Stue Aktiv"}
cur_stue=uservariables["CurSceneStue"]
tc=next(devicechanged)
REM_switch=tostring(tc)
if (REM_switch:sub(1,3) == 'REM') then
    if (string.match(REM_switch, "Stue A")) then
        cur_stue = cur_stue + 1
        if (cur_stue==5) then -- turn of lights
            cur_stue=1 
            commandArray['Variable:CurSceneStue'] = 1
        else --activate scene
            print(stue_scenes[cur_stue])
            commandArray[stue_scenes[cur_stue]]='On'
            commandArray['Variable:CurSceneStue'] = cur_stue
        end
	end
end
 
return commandArray
The script correctly turns on the scene corresponding to the current value of CurSceneStue, but I get an error and the uservariable Is never updated:
2017-03-05 21:55:07.760 Error: EventSystem: commandArray in script Remote should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
2017-03-05 21:55:07.761 EventSystem: Script event triggered: Remote

Any idea what is going wrong?

Re: Lua to cycle hue scenes

Posted: Monday 06 March 2017 10:04
by simonrg
As the error says you need to return strings not numbers so:

Code: Select all

commandArray['Variable:CurSceneStue'] = '1'
...
commandArray['Variable:CurSceneStue'] = tostring(cur_stue)
Then if the variable is an integer, Domoticz turns the string back into a number.

Re: Lua to cycle hue scenes

Posted: Tuesday 07 March 2017 20:28
by wormiedk
Thanks. That worked brilliantly!