We have moved at community.getvera.com

Author Topic: Scene manipulation with HTTP requests  (Read 10883 times)

Offline mikkelj

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Scene manipulation with HTTP requests
« on: April 14, 2011, 10:07:01 am »
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:

Code: [Select]
...
    "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:

Quote
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
« Last Edit: April 14, 2011, 10:14:48 am by mikkelj »

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Scene manipulation with HTTP requests
« Reply #1 on: April 14, 2011, 12:10:16 pm »
My guess:

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

Use at your own risk. Experimenting with ModifyUserData is dangerous. Backup your user_data.json.lzo ...
« Last Edit: April 14, 2011, 03:23:30 pm by Ap15e »

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Scene manipulation with HTTP requests
« Reply #2 on: April 15, 2011, 04:35:57 am »
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?

Offline mikkelj

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Re: Scene manipulation with HTTP requests
« Reply #3 on: April 15, 2011, 04:39:05 am »
Use at your own risk. Experimenting with ModifyUserData is dangerous. Backup your user_data.json.lzo ...

Thank you :) 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&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&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...  :'(

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



EDIT:

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?

I wanna be able to modify the events remotely.

Maybe I should give some background info :) 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.

« Last Edit: April 15, 2011, 04:49:59 am by mikkelj »

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Scene manipulation with HTTP requests
« Reply #4 on: April 15, 2011, 05:06:14 am »
ModifyUserData is an UPnP action provided by the UPnP service urn:micasaverde-com:serviceId:HomeAutomationGateway1.

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

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

Offline mikkelj

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Re: Scene manipulation with HTTP requests
« Reply #5 on: April 15, 2011, 05:09:28 am »
ModifyUserData is an UPnP action provided by the UPnP service urn:micasaverde-com:serviceId:HomeAutomationGateway1.

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

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

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

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"}}}]}
Code: [Select]
<?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 :D

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

Offline mikkelj

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Re: Scene manipulation with HTTP requests
« Reply #6 on: April 15, 2011, 05:20:20 am »
Thank you guys for your help.

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

Yes I am :) 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:

Code: [Select]
{
    "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 :)
« Last Edit: April 15, 2011, 05:22:52 am by mikkelj »

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Scene manipulation with HTTP requests
« Reply #7 on: April 15, 2011, 05:28:41 am »
Quote
Am I supposed to send back the whole shebang instead of just the parts of the scene I wanna change?

According to http://wiki.micasaverde.com/index.php/ModifyUserData the default action is 'merge' ...

BTW, it might be necessary to restart the LuaUPnP engine to activate the changes.
« Last Edit: April 15, 2011, 05:33:33 am by Ap15e »

Offline mikkelj

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Re: Scene manipulation with HTTP requests
« Reply #8 on: April 15, 2011, 05:52:08 am »
Quote
Am I supposed to send back the whole shebang instead of just the parts of the scene I wanna change?

According to http://wiki.micasaverde.com/index.php/ModifyUserData the default action is 'merge' ...

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

My boss had a correspondance with a guy from Mios:

Quote
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 :) 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?

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Scene manipulation with HTTP requests
« Reply #9 on: April 15, 2011, 07:39:28 am »
Yes, please add your findings to the wiki.
« Last Edit: April 15, 2011, 08:56:41 am by Ap15e »

Offline mikkelj

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Re: Scene manipulation with HTTP requests
« Reply #10 on: April 15, 2011, 09:39:29 am »
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.

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Scene manipulation with HTTP requests
« Reply #11 on: April 15, 2011, 11:57:18 am »
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.

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.

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Scene manipulation with HTTP requests
« Reply #12 on: April 15, 2011, 01:43:59 pm »
Not being able to edit the wiki seems to be a common problem. I had the same problem some time ago.

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Scene manipulation with HTTP requests
« Reply #13 on: April 15, 2011, 02:16:48 pm »
@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)

Offline mikkelj

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Re: Scene manipulation with HTTP requests
« Reply #14 on: April 16, 2011, 11:16:58 am »
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.

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 :)