Does anyone know if it is possible to access these modes using Lua? I am thinking it is, and it would be good if we could as not all interfaces have these modes.
Sent from my iPad using Tapatalk
Does anyone know if it is possible to access these modes using Lua? I am thinking it is, and it would be good if we could as not all interfaces have these modes.
Sent from my iPad using Tapatalk
Seems to be a variable on device 0: http://forum.micasaverde.com/index.php/topic,26785.msg191194.html#msg191194
There doesn’t seem to be a way to access Mode through a direct luup.variable_get(…) but this works:
local res, mode = luup.inet.wget("http://127.0.0.1:3480/data_request?id=variableget&Variable=Mode",5)
if (mode == "1") then ...
Thanks. Would like to set it with a scene as only the vera app on io sthat seems to allow you to set the mode. Need to create scenes to set
Sent from my iPad using Tapatalk
You can do that by adding this to the scene’s Luup:
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","SetHouseMode", {Mode = value}, 0)
Where value is 1 for Home, 2 for Away, 3 for Night or 4 for Vacation.
Thanks! Works great. I had pretty much the same code in, but must of been a typo somewhere. I have to try the test environment as I think that will help locate the issues. I am used to programming mostly in IDE’s.
Sent from my iPad using Tapatalk
If you prefer to work with an IDE, take a look at ZeroBrane Studio for Vera. This is an easy-to-use tool that executes the Lua right on Vera so supports all the luup calls. There is a one-time licence fee but I think it is good value.
If you prefer free, you might like LuaTest. It is by no means an IDE but it can help debug Lua for scenes and it does run under UI7.
Thanks for the info. I will take a look!
Sent from my iPad using Tapatalk
You can do that by adding this to the scene’s Luup:
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","SetHouseMode", {Mode = value}, 0)
Where value is 1 for Home, 2 for Away, 3 for Night or 4 for Vacation.[/quote]
Is this still valid?
I try…
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","SetHouseMode", {Mode = value}, 2)
and my Vera does not switch to Away :-).
The 0 you changed to 2 is the device number. Change it back to 0 and then ensure that the value of variable “value” is actually 2.
You can do that by adding this to the scene’s Luup:
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","SetHouseMode", {Mode = value}, 0)
Where value is 1 for Home, 2 for Away, 3 for Night or 4 for Vacation.[/quote]
Is this still valid?
I try…
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","SetHouseMode", {Mode = value}, 2)
and my Vera does not switch to Away :-).[/quote]
SOLVED!
Using luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”,“SetHouseMode”, {Mode = value}, 2) didn’t appear to work, so I used the URL alternative discussed in the wiki page:
You can test the URL with a browser to confirm the syntax is valid (you get some noise, but look at the bottom of the page, it should say “OK”)
Next, wrap luup.init.wget around the URL for valid LUUP code:
luup.inet.wget(“http://192.168.1.91/port_3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=SetHouseMode&Mode=2”)
Works great!
That explains things, thank you!
It might make more sense to document the syntax as:
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”,“SetHouseMode”, {Mode = }, )
In this context, is not variable. It MUST always be 0, because this is an action on the gateway device (ie. Vera itself), that is, device 0.
Can someone please explain me why this code is not working?
--mode = luup.variable_get("urn:micasaverde-com:serviceId:HomeAutomationGateway1","Mode",0)
mode = luup.inet.wget("http://127.0.0.1:3480/data_request?id=variableget&Variable=Mode",0)
if (mode==1) then
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","SetHouseMode", {Mode = 2}, 0)
elseif (mode==2) then
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","SetHouseMode", {Mode = 3}, 0)
end
(tried get variable_get but hthis also does not work, the wget in a browser gives a correct result back (change the IP to vera ip))
I am looking a way to switch the house mode with one scene, when it iws in mode 1 it needs to go in mode 2, when it is mode 2 and the scene is rn it should go in mode 1.
The code itself gives no error in the luup test but it does not execute/change the house mode, using a real scene also does not change it.
The easiest way to access Mode is
local mode = luup.attr_get "Mode"
The problem with your luup.inet.wget() call is that it actually returns two parameters, the first one is a status with value 0 if successful. So really you would have needed:
local status, mode = luup.inet.wget("http://127.0.0.1:3480/data_request?id=variableget&Variable=Mode",0)
Also, in both cases, you should coerce to a number before doing the check
if (tonumber(mode)==1) then
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.
Can this be used to trigger a scene when changing to HOME mode but only if coming from AWAY mode?
I’m trying to trigger the Garage Door Open scene upon arriving from somewhere and using geofencing to determine I’ve arrived. That determination triggers the change from AWAY to HOME and, subsequently would be good time to have the garage door open.
I don’t want it to open in any other mode, however, when changing to HOME (such as NIGHT or VACA.)
Any feedback would be appreciated!
You’d have to use a global variable to save the previous value of the Mode and do a test against that.
I don’t know whether of not the House Modes plugin supports such filtering, as an alternative.
The easiest way to access Mode islocal mode = luup.attr_get “Mode”
This was not always available … early there was a bug in luup.attr_get … They fixed in about mid year … after the House Modes plugin was released.
This was in response to a request I made … I thought it was overly expensive to make an http request for something that was already internally available.
At that time they made many of the top level entries in the user_data structure available via luup.attr_get.
At the same time I asked for an luup.attr_watch function as well … they said they would consider … but I have not seen it yet.
[quote author=akbooer link=topic=26903.msg249556#msg249556 date=1442871634]
You’d have to use a global variable to save the previous value of the Mode and do a test against that.
My concern there is losing the global upon nightly LUA reboot. However, what about using a virtual switch? When mode goes to AWAY the switch is set to ON. When coming back home the mode change of AWAY to HOME turns OFF the switch. The combination of mode = HOME and switch = OFF should be enough to trigger, no?
Problem is I’m not sure how to write up the LUUP code to say MODE SWITCH status’. Using GUI triggers is one or the other, right?
If you want “AND” conditions to trigger you are either going to,have to,use some LUA code (see threads on conditional execution of a scene) or use PLEG. The Vera Scenes do not support AND in the UI.
Best Home Automation shopping experience. Shop at Ezlo!
© 2024 Ezlo Innovation, All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules