Scene manipulation with HTTP requests

Hi guys,

I’ve been reading through the wiki and grinding the search-function, but I can’t figure this one out myself. I want to modify some properties of a scene. Consider a simple example:

I have a scene that turns on the heat, whenever the temperature drops to say 15C.

The property of the scene looks like this:

http://img402.imageshack.us/img402/9703/screenshotevent.jpg
(Can I embed images in my post? Usually [img] works, but not here)

… and the JSON data for this event looks like this:

... "scenes": [ { "name": "Heat ON", "posx": 0, "posy": 0, "Device_Num_56": { "event_2_1": { "name": "Heat on", "Enabled": "1", "argument_1": "15", "LastEval": 0 } }, "id": 1, "Timestamp": 1299829983, "room": 0 } ], ...

I wanna modify those 15 degrees, but I can’t get my head around it >:(

Now this is what I know:

Assuming my scene has the number 1

If I want to run a scene I do it like this:
http://ip:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=1

If I want to rename a scene, I can do it like this:
http://ip:3480/data_request?id=scene&action=rename&scene=1&name=NEW_SCENE_NAME

According to the wiki, I’m supposed to use an action called ModifyUserData, to modify the variable argument_1.

I got this from a colleague, but I can’t modify it to work:

http://ip:3480/data_request?id=lu_action&DeviceNum=0&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=ModifyUserData&inUserData= { "devices": { "devices_19": { "states": { "states_25": { "value": "2,1d,5,3,1d,40" } } } }, "scenes": {
},
"sections": {
    
},
"rooms": {
    
},
"users": {
    
} 

}


(I’ve inserted a newline and indented the JSON for readability)

Can any of you guys point me in the right direction - I think I’m close! ;D

Regards
/Mikkel

My guess:

{
  "scenes": [ {
                "name": "Heat ON",
                "Device_Num_56": {
                                   "event_2_1": {
                                                  "argument_1": "25"
                                                } 
                                 }
              } 
            ]
}

Use at your own risk. Experimenting with [tt]ModifyUserData[/tt] is dangerous. Backup your [tt]user_data.json.lzo[/tt] …

Do you want to modify it dynamically, based on a certain event?

If not, why don’t you edit the event and modify that value by hand?

Thank you :slight_smile: The JSON looks solid, and validates properliy - however I’m having trouble with my request…

Trying: http://ip:3480/data_request?id=lu_action&DeviceNum=56&scene=1&action=ModifyUserData&inUserData={“scenes”:[{“name”:“HeatON”,“Device_Num_56”:{“event_2_1”:{“argument_1”:“25”}}}]}

Yields: “error: no service/action”

Of course, I’m not stating any service ID’s like my colleague did in his example:

http://ip:3480/data_request?id=lu_action&DeviceNum=0&[u]serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1[/u]&action=ModifyUserData&inUserData=JSON_CODE_GOES_HERE

But then again - what serviceID am I supposed to give? I can’t find any useful serviceID when looking in UI4, and I’m not sure where to look, in the user_data or lu_sdata output. user_data is 5500+ lines big, so trying to get an overview of all the objects seems a bit futile. I’ve grepped the file for serviceID’s and some other keywords I thought relevant, but to no avail… :cry:

The documentation of the LuuP actions and the parameters they take are somewhat sparse…

EDIT:

[quote=“mcvflorin, post:3, topic:168136”]Do you want to modify it dynamically, based on a certain event?

If not, why don’t you edit the event and modify that value by hand?[/quote]

I wanna be able to modify the events remotely.

Maybe I should give some background info :slight_smile: I work for a small company specialized in home automation, developing software for the Vera among other things. The above mentioned scenario is a real world Use Case: One of our customers wants to control the thermostat in a set of houses. I wanna make a tool/script to automate that process, so the customer doesn’t have to manually log into all the Vera boxes and configure the scenes by hand.

[tt]ModifyUserData[/tt] is an UPnP action provided by the UPnP service [tt]urn:micasaverde-com:serviceId:HomeAutomationGateway1[/tt].

[tt]http://ip:3480/data_request?id=lu_action&DeviceNum=0&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=ModifyUserData&inUserData=…[/tt] is the correct syntax.

Do not experiment with a live system. You have been warned.

[quote=“Ap15e, post:5, topic:168136”][tt]ModifyUserData[/tt] is an UPnP action provided by the UPnP service [tt]urn:micasaverde-com:serviceId:HomeAutomationGateway1[/tt].

[tt]http://ip:3480/data_request?id=lu_action&DeviceNum=0&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=ModifyUserData&inUserData=…[/tt] is the correct syntax.

Do not experiment with a live system. You have been warned.[/quote]

I was just writing a new post, when I saw you beat me to it :slight_smile:

Removing DeviceNum=56 and adding serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 gave a result:

http://ip:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&scene=1&action=ModifyUserData&inUserData={“scenes”:[{“name”:“HeatON”,“Device_Num_56”:{“event_2_1”:{“argument_1”:“25”}}}]}

<?xml version="1.0"?> <u:ModifyUserDataResponse xmlns:u="urn:micasaverde-com:serviceId:HomeAutomationGateway1"> <UserData>{}</UserData> </u:ModifyUserDataResponse>

… and now the scene is gone. Well, at least the command worked :smiley:

Am I supposed to send back the whole shebang instead of just the parts of the scene I wanna change?

Thank you guys for your help.

Yes I am :slight_smile: Sending the whole scene back, with whatever changes made, works great!

http://ip:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&scene=1&action=ModifyUserData&inUserData={“scenes”:[{“name”:“HeatON”,“posx”:0,“posy”:0,“Device_Num_56”:{“event_2_1”:{“name”:“Heaton”,“Enabled”:“1”,“argument_1”:“25”,“LastEval”:0}},“id”:1,“Timestamp”:1299829983,“room”:0}]}

And the JSON indented:

{ "scenes": [ { "name": "HeatON", "posx": 0, "posy": 0, "Device_Num_56": { "event_2_1": { "name": "Heaton", "Enabled": "1", "argument_1": "25", "LastEval": 0 } }, "id": 1, "Timestamp": 1299829983, "room": 0 } ] }

I get the same XML response though, but now my data is changed :slight_smile:

Am I supposed to send back the whole shebang instead of just the parts of the scene I wanna change?

According to [tt]http://wiki.micasaverde.com/index.php/ModifyUserData[/tt] the default action is ‘merge’ …

BTW, it might be necessary to restart the LuaUPnP engine to activate the changes.

[quote=“Ap15e, post:8, topic:168136”]

Am I supposed to send back the whole shebang instead of just the parts of the scene I wanna change?

According to [tt]http://wiki.micasaverde.com/index.php/ModifyUserData[/tt] the default action is ‘merge’ …

BTW, it might be necessary to restart the LuaUPnP engine to activate the changes.[/quote]

My boss had a correspondance with a guy from Mios:

Regarding changing the scene in your backend, what you have to do is send the ModifyUserData command from the API, passing in the exact same JSON structure as the scene current has (as retrieved by the user_data request), but changing the 1 paramater you want. ModifyUserData takes a JSON structure as an input, and it merges the new JSON object in with the existing one. The only thing is that, as I recall, when you pass in a scene it replaces the existing scene object, so you have to send the entire scene in again. We don't have a programmatical way of changing the events without resending the scene. We will be adding this for our new UI5, but it's still a few months away.

So the semantics of “merging” seems to be a bit muddy :slight_smile: But thanks a lot for your help - I couldn’t have done it without you. Can I add an example to the wiki, so others won’t have to ask the same question?

Yes, please add your findings to the wiki.

Unfortunately I’m not allowed to do so. I can’t even write in the discussion’s section it seems.

Unfortunately I’m not allowed to do so. I can’t even write in the discussion’s section it seems.[/quote]

Why? We have all requested Wiki accounts and gotten them. If you’re not being permitted to have an account, please let us know who’s given you the rejection notice, and we’ll get it sorted.

It’s very important that this type of knowledge get captured for others to consume.

Not being able to edit the wiki seems to be a common problem. I had the same problem some time ago.

@Ap15e,
They went through a period where they were being spammed by link promoters in the Wiki, and I asked them to require validation prior to letting in an Editor, since there really weren’t that many of us anyhow.

It’s possible they missed a few in this validation process, so let’s get them listed/verified so that those that want to edit can do so.

…without the link promoters wreaking havoc, of course… 8)

[quote=“guessed, post:12, topic:168136”]Why? We have all requested Wiki accounts and gotten them. If you’re not being permitted to have an account, please let us know who’s given you the rejection notice, and we’ll get it sorted.

It’s very important that this type of knowledge get captured for others to consume.[/quote]

I haven’t been rejected. I only just created a user for the wiki pages friday, so I’m sure I’ll be granted permission with time :slight_smile:

Sorry for bumping an old topic…

Is it possible to be granted some privileges on the Wiki? I’d like to add some more explicit examples for the LuuP HTTP requests… I’m writing all these examples down for documentation of my own - figured I might as well contribute to the overall documentation of the system?

Have a nice weekend 8)

/Mikkel

I PM’d @mcvovidiu to see why they haven’t approved your Wiki account yet. Hopefully we’ll hear back from them shortly.