IF Else without LUA Code ?
-
I guess there is no way to do IF Else statements without using LUA code ?
This is a small portion of code, I've just copied out of one of my PLEG actions run LUA Code.
The code checks a WOL with Ping switch in Vera, if its ON, it then sends a particular HTTP request to that Kodi HTPC to bring an IP Camera image on screen
It then does the same check for the next WOL with Ping switch / Kodi HTPC and so on etc.
Also the code checks Harmony activities to see if I'm currently in a FireTV activity instead? and if so sends a particular HTTP request to do Picture in Picture on the FireTV stick.
local status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 38) --Check Status of KODI01 WOL switch if status == "1" then --If on then send command to show Security Cam os.execute('curl -X POST -H "content-type:application/json" http://kodi:kodi@192.168.1.101:8080/jsonrpc -d \'{"jsonrpc":"2.0","id":1,"method":"Addons.ExecuteAddon","params":{"addonid":"script.frontgardencam"},"id":"1"}\'') else end local status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 39) --Check Status of KODI02 WOL switch if status == "1" then --If on then send command to show Security Cam os.execute('curl -X POST -H "content-type:application/json" http://kodi:kodi@192.168.1.102:8080/jsonrpc -d \'{"jsonrpc":"2.0","id":1,"method":"Addons.ExecuteAddon","params":{"addonid":"script.frontgardencam"},"id":"1"}\'') else end
I can't see that this would be possible using just an MSR rule ?
Thanks
-
seem there is a ternary operator.
http://192.168.1.10:8111/docs/Expressions-%26-Variables/#new-operations-and-symbols -
-
Given that you have nothing in the ELSE, what does it matter? Very confusing...
As you've shown it, this is just an Entity Attribute condition on power_switch.state, and a Request action in the Set reaction. Two rules, one for each switch.
-
Given that you have nothing in the ELSE, what does it matter? Very confusing...
As you've shown it, this is just an Entity Attribute condition on power_switch.state, and a Request action in the Set reaction. Two rules, one for each switch.
@toggledbits said in IF Else without LUA Code ?:
Two rules, one for each switch.
I'm not a coding expert as you can probably guess, I can just tinker and muddle through
I thought the Else was to End that portion of the script and then continue with the next thing in the script.
This Lua script is very long. When motion is detected on my IP camera PLEG runs this Lua script and despite my lack of coding skills it all works.
It checks all the Kodi PCs and FireTVs and if any are On and active, it sends a particular http command to them to display the cameras video stream.
The code also sends particular Http commands to five different Android tablets running Tasker / TNES and TinyCam Pro, to display the cameras video stream.
Different Http commands are sent to first wake up the tablets, then switch to TinyCam pro app, show camera image for 60 secs, switch back to the Home Remote Dashboard app and then put the tablets back to sleep, so it's sending out a lot of http commands with various delays in between.
It also sends a Telegram message alert and TTS to Google Home.
It does slightly different things with the tablets depending on if Vera is in home or Night mode also.
So your saying I think, I'd need multiple rules each doing these different things, then all the rules being triggered off motion being detected on the IP camera (virtual motion sensor device in Vera) ?
I was just wondering if I could do away with this Lua script and do it all in an MSR rule instead.
-
No Lua seems to be required here, in either Vera Reactor or MSR, at least for what's described. The trickiest part is the HTTP requests, but both Reactors have a Request action that will do it. I don't think POST with payload has gotten a lot of use, but if it doesn't rise to occasion, you know I'll make sure it works.
-
Sending the HTTP requests out from a single MSR rule to the five Android tablets isn't the problem.
I have tested that and that part does work OK.
The problem is I don't know how to handle the Kodi PCs and FireTVs and "IF"
I will have to have an Entity Attribute to check the power state of each, as you said.
And IF any are turned On then send a particular http command to each of them to have them display the cameras video stream.
The problem was I couldn't see how to do that in one MSR rule.
But your suggesting I maybe able to do it by having multiple MSR rules all with the same trigger e.g. Motion has been detected.
-
Another example I have just come across.
I have a basic schedule in PLEG that turns off my outdoor garden lights at 23:59 pm every day.
In that single PLEG action I also have this little bit of LUA Code:
local mode = luup.attr_get "Mode" if (mode == "1") then luup.inet.wget("http://192.168.1.101:1880/scenetrigger?message=Schedule Turning Off Festoon Lights&ip=192.168.1.102") else end
IF Vera is in House Mode "HOME" (I am still awake or in the house) then it can send the HTTP Request / TTS announcement to the Google Home speaker via Node-Red.
However if the House Mode is something else other than "HOME" (I am either in bed already or not at home), then don't bother doing it.
I'm setting up this schedule in MSR now and in the "Set Reactions" I can't do this or I don't know how to do this, other than having this LUA code run actually on Vera still somehow.
I'd have to have two MSR Rules right ?
One that becomes TRUE when Vera is in HOME mode and then the HTTP Request is present in the "Set Reactions" actions area.
And another different rule that becomes TRUE for when Vera is NOT in HOME mode and no HTTP Request is even present in the "Set Reactions" actions area for that rule.
Thanks
-
Rule 1: time after 23:59; set reaction: turn off the garden lights
Rule 2: house mode == home AND Rule1 is true; set reaction: Request with URL -
OK thanks. I really don't fancy having to create two rules or many more in the case of the IP camera thing, for a lot of this stuff, so I either just won't bother with the TTS at all or I'll try out @therealdb idea of adding my LUA code snippets in to the Vera startup and a Library function and using a local .lua file to store the code.
I can then call that particular LUA code via a HTTP command sent from the single MSR rule to Vera.
He tells us how to do it on this new Github page.
-
T toggledbits locked this topic on