Khimo Support wrote:
Tassos wrote:
Hello again,
I am experimenting with the lua code you sent me for the nightmode: home / nightmode: away. I am trying to create a macro to automate my pool lights.
Pool lights are connected to mains via a tplink smart plug. Music is procured by an NL/ML Converter. What I am trying to achieve is that 30 minutes after sunset the pool lights turn on only if the NL/ML Converter is playing. I haven't succeeded yet and I need a bit of help since my lua knowledge is very limited. The lua code I am using is the following:
...
Hello Tassos,
Good work! You almost got it!
The name of the state variable is "state", so the conditional that check the status should be:
if nl_ml_converter.get("state") == "Play" then
Also, since you have the pool_lights_address defined, it would be better if you the command using the variable:
engine.fire(pool_lights_address .. "/SET?VALUE=false")
In this way, if you update the variable definition in the future all the commands will be updated.
Please, let us know if you have any further question!
Best,
the Khimo team.-
Hello again, lua coding seems very easy and actually a lot of fun. I have a small issue though. I have "automated" my virtual led buttons to change state according to the state of the lights they turn on/off. The system monitors the lights (hue) every minute and if they have a value other than 0 then the led of the button turns on. If the value is 0 then the led of the button turns off. It works like a charm but when I use a variable after the fire command nothing happens.
this is the code:
function(event, engine)
-- Define the resource address in your project:
local dimmer_level_address = "Main/$zone/DIMMER/*"
local dimmer_button_address = "Main/$zone/BUTTON/Lights"
-- Get dimmer state
local dimmer_level = engine.query(dimmer_level_address)[1]
if dimmer_level.get("LEVEL") == "0" then
-- the button led should turn off
engine.fire("Main/$zone/BUTTON/Lights/_SET STATE?STATE=0")
else
-- the button led should be on
engine.fire("Main/$zone/BUTTON/Lights/_SET STATE?STATE=1")
end
end
At this version the fire command doesn't use the variable but I want to use the variable as you suggested.
Furthermore can you give me an example of an "if" "and" and an "if" "or" condition? For example:
"if" the pool lights are on "or" the converter is playing then.....
"if" the pool lights are on "and" the converter is playing then....
Thanks a lot!!!