6 posts / 0 new
Last post
preed
Possible to assign multiple actions to a rule.

Per the hue api is it possible to have mutiple actions ( max 8 ) per rule. Though no matter what I try I cannot get the assigment to take. 

I've tried to PUT this json to my bridge, but just get 'bad json' error. Anyone else had any luck with this?

example json:

PUT --> /api/newdeveloper/rules/3

{
    "actions": [
        {
            "address": "/groups/5/action",
            "method": "PUT",
            "body": {
                "on": True
            }
        },

        {
            "address": "/groups/6/action",
            "method": "PUT",
            "body": {
                "on": False

            }
        }

    ]
}

Michel
If you are sending the exact

If you are sending the exact message you posted here to the bridge then it is indeed invalid JSON.

The True and False should be lowercase (so true and false).
Otherwise I see no issues with it.

When I get bad JSON messages I go to a site like http://jsonlint.com/ that can validate JSON to (more) easily pinpoint the issue.

preed
Update

Thanks, though I'm still getting a json error after correcting the true/false values. A different one though. I believe those True and False bool values snuck in there as I was moving from using the a python api wrapper to just using the rest web interface directly. The json itself if valid when tested against the linter above. I'm probably overlooking something really simple again...

 

So this works:

{
    "actions": [
        {
            "address": "/groups/5/action",
            "method": "PUT",
            "body": {
                "on": true
            }
        }

]

}

 

 

but this doesn't work, return a different json error, "Bad JSON: [". All I'm doing is extending the list to contain one more entry below. 

{
    "actions": [
        {
            "address": "/groups/5/action",
            "method": "PUT",
            "body": {
                "on": true
            }
        },
        {
           "address": "/groups/6/action",
           "method": "PUT",
           "body": {
                         "on": false
           }
     }]
}

 

 

preed
SOLVED

I ended up just creating a new rule with two or more actions. From my troubleshooting it appears that you cannot update a single action rule to a multiple action rule. 

Michel
That is really weird. It

That is really weird. It works fine here, maybe it is related to the swversion?
I am on "swversion":"01028090"

I create a rule with POST on /api/#username#/rules
{
    "name": "Rule name",
    "conditions": [
        {
            "address": "/sensors/1/state/daylight",
            "operator": "eq",
            "value": "true"
        }
    ],
    "actions": [
        {
            "address": "/groups/5/action",
            "method": "PUT",
            "body": {
                "on": false
            }
        }
    ]
}

and then change it with PUT on /api/#username#/rules/23
{
    "actions": [
        {
            "address": "/groups/5/action",
            "method": "PUT",
            "body": {
                "on": false
            }
        },
        {
            "address": "/groups/6/action",
            "method": "PUT",
            "body": {
                "on": true
            }
        }
    ]
}

kyle87
This online tool might help

This online tool might help you validate your JSON: JSON formatter

Log in or register to post comments