Hi all,
I have a dimmer item that should control the volume of my Raumfeld devices. There is a HTTP interface (node-raumserver) to do that. It can return the state of the device in JSON format. I’ll append a sample JSON return value. My expression to get the volume is this:
$..rooms[?(@.name=='Küche')].volume
It works fine with the online JSON testers, but does not return a value inside openHAB. Neither within the item nor within a rule.
Item configuration:
Dimmer rmf_kue_vol_2 "Laustärke Küche 2" (gRaumfeld) [ "Lighting" ] { http="<[http://192.168.178.8:8080/raumserver/controller/getRendererState?listAll=true:5000:JSONPATH($..rooms[?(@.name=='Küche')].volume)] >[CHANGED:POST:http://192.168.178.8:8080/raumserver/controller/setVolume?id=Küche&scope=room&value=%2]" }
Rule extract:
var String json = sendHttpGetRequest("http://192.168.178.8:8080/raumserver/controller/getRendererState?listAll=true")
var String value_kue = transform("JSONPATH", "$..rooms[?(@.name=='Küche')].volume", json)
I logged the return value inside the rule, it is “null”.
But when I do not use expressions to filter the JSON data, it works:
$.data[0].rooms[0].volume
I can see from the openhab.log, that the matching is correct:
2017-05-10 07:46:29.569 [DEBUG] [ayway.jsonpath.internal.CompiledPath] - Evaluating path: $['name']
2017-05-10 07:46:29.570 [DEBUG] [com.jayway.jsonpath.Criteria ] - [Küche] EQ [Küche] => true
2017-05-10 07:46:29.571 [DEBUG] [ayway.jsonpath.internal.CompiledPath] - Evaluating path: $['name']
2017-05-10 07:46:29.572 [DEBUG] [com.jayway.jsonpath.Criteria ] - [Wohnzimmer] EQ [Küche] => false
2017-05-10 07:46:29.574 [DEBUG] [ayway.jsonpath.internal.CompiledPath] - Evaluating path: $['name']
2017-05-10 07:46:29.576 [DEBUG] [com.jayway.jsonpath.Criteria ] - [Wohnzimmer] EQ [Küche] => false
2017-05-10 07:46:29.577 [DEBUG] [ayway.jsonpath.internal.CompiledPath] - Evaluating path: $['name']
2017-05-10 07:46:29.578 [DEBUG] [com.jayway.jsonpath.Criteria ] - [Küche] EQ [Küche] => true
What am I doing wrong? How do I get this to work?
Many thanks in advance.
Example JSON:
{
"requestUrl": "/raumserver/controller/getRendererState?listAll=true",
"action": "getRendererState",
"error": false,
"msg": "",
"data": [{
"mute": 0,
"InstanceID": 0,
"CurrentTrackMetaData": "",
"CurrentRecordQualityMode": "NOT_IMPLEMENTED",
"AbsoluteTimePosition": "00:00:00",
"SecondsUntilSleep": "0",
"CurrentTrack": "0",
"AVTransportURIMetaData": "",
"PossiblePlaybackStorageMedia": "NETWORK",
"TransportPlaySpeed": "1",
"CurrentTrackDuration": "00:00:00",
"PossibleRecordQualityModes": "NOT_IMPLEMENTED",
"TransportError": "",
"PossibleRecordStorageMedia": "NONE",
"AVTransportURI": "",
"RelativeTimePosition": "00:00:00",
"RelativeCounterPosition": "1",
"CurrentPlayMode": "NORMAL",
"Bitrate": "0",
"TransportState": "NO_MEDIA_PRESENT",
"AbsoluteCounterPosition": "1",
"CurrentTransportActions": "",
"RoomStates": "uuid:7a2565a9-a03f-4bdb-aa29-6a4416568b6a=STOPPED,uuid:1341d05b-496a-4c78-9282-8de75310836f=STOPPED",
"ContentType": "",
"NumberOfTracks": "0",
"SleepTimerActive": "0",
"TransportStatus": "OK",
"CurrentTrackURI": "",
"RoomVolumes": "uuid:7a2565a9-a03f-4bdb-aa29-6a4416568b6a=31,uuid:1341d05b-496a-4c78-9282-8de75310836f=35",
"Volume": "35",
"Mute": "0",
"RoomMutes": "uuid:7a2565a9-a03f-4bdb-aa29-6a4416568b6a=0,uuid:1341d05b-496a-4c78-9282-8de75310836f=0",
"rooms": [{
"roomUDN": "uuid:7a2565a9-a03f-4bdb-aa29-6a4416568b6a",
"transportState": "STOPPED",
"online": true,
"volume": "31",
"mute": "0",
"name": "Wohnzimmer",
"udn": "uuid:7a2565a9-a03f-4bdb-aa29-6a4416568b6a",
"powerState": "ACTIVE",
"renderer": [{
"udn": "uuid:23edaa33-b6db-4a29-b298-99a555a7f45b",
"name": "Connector Wohnzimmer"
}]
},
{
"roomUDN": "uuid:1341d05b-496a-4c78-9282-8de75310836f",
"transportState": "STOPPED",
"online": true,
"volume": "35",
"mute": "0",
"name": "Küche",
"color": "#C64D51",
"udn": "uuid:1341d05b-496a-4c78-9282-8de75310836f",
"renderer": [{
"udn": "uuid:48c57453-aa3c-48c1-a3a9-875cc5c436f0",
"name": "Speaker Küche"
}]
}],
"udn": "uuid:2ee4da6f-f436-4309-9043-a08f95980dfd",
"mediaItem": null,
"friendlyName": "Wohnzimmer,Küche",
"host": "192.168.178.21",
"manufacturer": "Raumfeld GmbH",
"modelNumber": "2"
},
{
"InstanceID": 0,
"AVTransportURIMetaData": "",
"CurrentTrackDuration": "NOT_IMPLEMENTED",
"PowerState": "IDLE",
"AVTransportURI": "",
"CurrentPlayMode": "NORMAL",
"TransportState": "NO_MEDIA_PRESENT",
"CurrentTransportActions": "",
"TransportStatus": "OK",
"LowDB": "0.000000",
"Mute": "0",
"MidDB": "0.000000",
"Volume": "31",
"VolumeDB": "-10496",
"HighDB": "2.277344",
"rooms": [{
"name": "Wohnzimmer",
"udn": "uuid:7a2565a9-a03f-4bdb-aa29-6a4416568b6a",
"powerState": "ACTIVE",
"renderer": [{
"udn": "uuid:23edaa33-b6db-4a29-b298-99a555a7f45b",
"name": "Connector Wohnzimmer"
}]
}],
"udn": "uuid:23edaa33-b6db-4a29-b298-99a555a7f45b",
"mediaItem": null,
"friendlyName": "Connector Wohnzimmer",
"host": "192.168.178.21",
"manufacturer": "Raumfeld GmbH",
"modelNumber": "2"
},
{
"InstanceID": 0,
"AVTransportURIMetaData": "",
"TransportStatus": "OK",
"CurrentTrackDuration": "NOT_IMPLEMENTED",
"AVTransportURI": "",
"TransportState": "NO_MEDIA_PRESENT",
"CurrentPlayMode": "NORMAL",
"CurrentTransportActions": "",
"LowDB": "2.925781",
"Mute": "0",
"MidDB": "0.000000",
"Volume": "35",
"VolumeDB": "-10112",
"HighDB": "1.144531",
"rooms": [{
"name": "Küche",
"color": "#C64D51",
"udn": "uuid:1341d05b-496a-4c78-9282-8de75310836f",
"renderer": [{
"udn": "uuid:48c57453-aa3c-48c1-a3a9-875cc5c436f0",
"name": "Speaker Küche"
}]
}],
"udn": "uuid:48c57453-aa3c-48c1-a3a9-875cc5c436f0",
"mediaItem": null,
"friendlyName": "Speaker Küche",
"host": "192.168.178.22",
"manufacturer": "Raumfeld GmbH",
"modelNumber": "1"
}]
}