[solved] Hue Motion Sensor (ON/OFF State)

Hi there

i want to know (and later switch) the status of an Hue Motion Sensor.

as Example the Hue Battery status:

Number KuecheHueBattery "Batterie [%.0f %%]"                    <batterylevel> (Kueche, gMotion) 
                { http="<[]" }


(function(i) {
    var json = JSON.parse(i);
    return ((json['config']['battery']));

that works…

now i try the same syntax for my Sensor Status:

Number HueMoetionSensorKueche "Hue Sensor Küche [%s]"                          (Kueche, gMotion)
                { http="<[]"}


(function(i) {
    var json = JSON.parse(i);
    return ((json['config']['on']));

thats the Hue API view…


why is this not working? The Log stay blank.


i try’d also:

(function(i) {
    var json = JSON.parse(i);
    return ((json['config']['on'])) == true ? "ON" : "OFF";

didn’t work too

I’m not sure, what you would like to achieve. Would you like to check, if there is motion?

Then you need to check for “state -> presence” not “config -> on”.

So your JS-file should look like this:

(function(i) {
    var json = JSON.parse(i);
    return json['state']['presence'];

And I think your item should be a String instead a Number.

String HueMoetionSensorKueche "Hue Sensor Küche [%s]"                          (Kueche, gMotion)
                { http="<[]"}



sorry, to get no confuse i delete this post…

-> With String it works for the state.


but when i use a switch:


Why the switch does not get the right state?

This could be a way, if the one you are trying to achieve is not working:
You could create a rule that changes the state of the item in the hue bridge via a shell script. Something like that:

Switch HueSensorKueche "Hue Sensor Küche"

and a rule like this:

rule "Switch hue motion sensor on and off"
        Item HueSensorKueche changed
 if  (HueSensorKueche.state == ON) {
    executeCommandLine("sh /path/here/hue-switch-ON.sh")

else {
   executeCommandLine("sh /path/here/hue-switch-OFF.sh")


The shell scripts basically trigger a curl command to make the change like this:

curl -H "Accept: application/json" -X PUT --data '{"config": {"on": true}}' http://192.168.x.x/api/xxxxxxxxxxxxxxxx/sensors/26


curl -H "Accept: application/json" -X PUT --data '{"config": {"on": false}}' http://192.168.x.x/api/xxxxxxxxxxxxxxxx/sensors/26

It’s not very elegant and the other way is better, but it does the job (in case nothing else works).

Thank you for you help and work.

The Switch allready runs.

Switch HueMotionSwitch "Hue Sensor Switch"                                     (Kueche, gMotion) 
var Sensor = 25

rule "Switch Hue Motion Sensor ON / OFF"
    Item HueMotionSwitch changed
    val url = "" + Sensor + "/config"
    var String body = ""
    if( HueMotionSwitch.state != ON ) {
        body = '{"on":false}'
    } else {
        body = '{"on":true}'
    logInfo("HueSensorKueche", "Send command '{}' to {}", body, url)
    sendHttpPutRequest(url, "application/json", body)

The Problem is the Switch get not the actual state from the switch.

When i turn the switch, then the state are good, but when i refresh the sitemap then the actual state is not given.

i search the forum, but i can’t get the solution. i think i need a rule to call the state, but i have no idea how to do.

Don’t know if this the right way, but this does update the switch in my case

rule "Hue Sensor Status abfragen"
    Item HueMoetionSensorKueche changed
    if (previousState == NULL) {

thanks for the help