tiwas
April 17, 2016, 3:11pm
21
[quote=“akbooer, post:15, topic:182797”]so you could write this:
local mode = luup.attr_get "Mode"
local newMode = ({2,1}) [tonumber(mode)] or 1
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","SetHouseMode", {Mode = newMode}, 0)
Hope this helps.[/quote]
What does the newMode line mean? Is it an array with the new and the old mode?
Yes.
local newMode = ({2,1}) [tonumber(mode)] or 1
House mode is (or should be) an integer: 1 = Home, 2 = Away, …
This just says that if the mode is 1 make it 2, if it’s 2 make it 1, if it’s neither of those then set it to 1.
There’s an infinite number of different ways of writing this, I just chose this way.
tiwas
April 17, 2016, 3:46pm
23
Thanks! Just a got a flashback to bash scripts and c code when manual obfuscation and saving a couple of ticks was all the rage ;D
It’s just a pattern I use sometimes.
tiwas
April 17, 2016, 4:40pm
25
Ok
Is there any advantage to using this over luup.is_night()?
House modes are really nothing to with whether or not it’s night according to the sun.
I’ve been trying to change mode as part of a PLEG action. Is this actually possible? I plugged in the luup code listed above but never could get it to work. Same code worked fine as a scene though…
kwieto
January 30, 2017, 8:38am
28
Is there a list of attributes avaialble somewhere?