Lua to cycle hue scenes

Moderator: leecollings

Post Reply
wormiedk
Posts: 15
Joined: Wednesday 18 May 2016 5:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Lua to cycle hue scenes

Post 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?
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Lua to cycle hue scenes

Post 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.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
wormiedk
Posts: 15
Joined: Wednesday 18 May 2016 5:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua to cycle hue scenes

Post by wormiedk »

Thanks. That worked brilliantly!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests