Run scene via URL - with parameters

Hi,

I saw this thread (http://forum.micasaverde.com/index.php/topic,2013.msg98770.html#msg98770) which was exactly what I was looking for. RTS already said “no can’t do” but since it was 2 years ago, I would like to revisit this topic:

  1. I understand I can execute a scene via URL, like this - http://Vera_IP_adress:port/data_request?id=lu_action&output_format=xml&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=

  2. I want to pass in a Query String parameter and have it pass into the scene. For example - http://Vera_IP_adress:port/data_request?id=lu_action&output_format=xml&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=&input=123

  3. And then the Query String [“input”] can then be used in a scene. For example, whatever the integer value I pass in (123) will be used as the interval value for the Countdown timer, so sometimes I can set the timer to count down 60 seconds, sometimes 300 seconds.

As of now, is there a generic way that I can do this? Thank you.

No, this hasn’t changed:

  • the action invoked to run the scene has no optional parameter specified in the UPnP definition,
  • the scene code itself has no direct way to receive any parameters.

There are at least two options:

  • write your own plugin (hard)
  • add an HTTP request handler to the Lua startup code(a bit easier)

To demonstrate just how easy this is, if you run this code in Lua Startup:

function HTTP_user (_,p)
    luup.log ("HTTP_user: " .. tostring(p))
    for a,b in pairs (p) do global[a] = b end
    local out = {}
    for a,b in pairs (global) do out[#out+1] = a .. ' = ' .. b end
    return table.concat (out, '\n'), "text/plain"
end

global = {}  -- 'global' table, call it whatever you like
luup.register_handler ("HTTP_user", "user")

Then an HTTP request like:

http://VeraIP:3480/data_request?id=lr_user&a=42&b=something

will produce the response:

b = something
a = 42

and set the global table (named ‘global’ in this case) to contain those variables (all string values)

A further HTTP request:

http://VeraIP:3480/data_request?id=lr_user&c=something_else&a=1234

gives the response:

b = something
a = 1234
c = something_else

which has added a new variable and modified the value of another.

Scenes, of course, can access these variables through the global table. If you like, you could modify the HTTP handler to run a scene number as specified by a parameter.

Thank you @akbooer for the detail response! Looks great and I will give the HTTP handler a try.

Thanks for that info,
I still do have some issues in achieiving my goal… Maybe you can help ?

I’ve put your code in the startup lua but what I would like to do is to be able to launch a scene from an url, let say :
http://xxx.xxx.xxx.xxx:3480/data_request?id=action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=XX&Variable1=zzzz

and then that scene can use that Variable1 to do some stuff…

Any idea ?

Sadly, scenes don’t take parameters.

The easiest way to do this is to add a new request handler to Luup. Fortunately, this is very easy, and has been asked (and answered) several times previously:

2 Likes

Thanks ! Yes I saw that but my issue is that I have a few esp8266 4 button wifi remotes where I can program each button to trigger an url… (only one url per button…)
So what I wanted to do is that when I press a button, that triggers a scene with some variable returned from that remote (ie.: it’s ip and battery status) …

Then I have a pushover function that send me a notification from the Vera to my phone (that part works well already from a global function I placed in startup lua.)

So what I did was to change your code but that fails and I can’t find the issue…

here it is :

startup Lua:

function pushover (Title_PO, Message_PO, Priority_PO, URL_PO, URLTitle_PO, Sound_PO)
luup.call_action("urn:upnp-org:serviceId:IOSPush1", "SendPushOverNotification",{ Title=Title_PO, Message=Message_PO, Priority=Priority_PO, URL=URL_PO, URLTitle=URLTitle_PO, Sound=Sound_PO}, 152)
end

function HTTP_user (_,p)
luup.log ("HTTP_user: " .. tostring(p))
for a,b in pairs (p) do global[a] = b end
local out = {}
for a,b in pairs (global) do out[#out+1] = a .. ' = ' .. b end
return table.concat (out, '\n'), "text/plain"
PushMessage = (global["message"]) --looking for the message
pushover ("Vera notification",PushMessage, "2", " ", " ", "gamelan") -- Use pushover to send it
end

global = {}
luup.register_handler ("HTTP_user", "user")

So it doesn’t like :

        PushMessage = (global["message"])  
        pushover ("Vera notification",PushMessage, "2", " ", " ", "gamelan")

And the request looks like :

http://xxx.xxx.xxx.xxx:3480/data_request?id=lr_user&message=zzz.zzz.zzz.zzz

Is there any way I could make this to work ?

No, it won’t. You have that code after a return statement, so it can never be reached.


Edit: try something more like this…

function pushover (Title_PO, Message_PO, Priority_PO, URL_PO, URLTitle_PO, Sound_PO)
  luup.call_action("urn:upnp-org:serviceId:IOSPush1", "SendPushOverNotification",{ Title=Title_PO, Message=Message_PO, Priority=Priority_PO, URL=URL_PO, URLTitle=URLTitle_PO, Sound=Sound_PO}, 152)
end

function HTTP_user (_,p)
  local msg = p.message or ''
  pushover ("Vera notification",msg, "2", " ", " ", "gamelan") -- Use pushover to send it
  return msg, "text/plain"
end

luup.register_handler ("HTTP_user", "user")
1 Like

Again… Thanks man, your a code guru :slight_smile: