Https binding get value

hello
i am at a wonder is it possible to have something in the binding to not get an error if the value is not to be found in the rest api that i am trying to pool ? sometimes that value shows up when its asked sometimes not depending on the state of the device.

thanks

I think you can use the technique described here, using REGEX

i saw the link but that is not what i am looking for. So image like this you have an rest api that gives you the title of the song but sometimes that title doesnt exist so the api will not give anything. Just for an ideea i am trying to replicate the functionality of the amplipi rest api interface in openhab using http binding link to the docs here …
https://api.amplipi.com/#overview

Then you’d better provide examples of the payload that you want and the payload that you want to ignore.

so when everything is filled i get this

{
  "id": 1,
  "name": "Input 2",
  "input": "stream=1007",
  "info": {
    "name": "Deep House Lounge - internet radio",
    "state": "playing",
    "artist": "cody p",
    "track": "awkward 007 mix",
    "station": "DEEP HOUSE LOUNGE - [www.deephouselounge.com]",
    "img_url": "https://secureimg.stitcher.com/feedimagesplain328/42300.jpg",
    "supported_cmds": [
      "play",
      "stop"
    ]
  }
}

and when there is nothing i get this

{
  "id": 1,
  "name": "Input 2",
  "input": "None",
  "info": {
    "name": "None",
    "state": "stopped",
    "img_url": "static/imgs/disconnected.png",
    "supported_cmds": []
  }
}

as you can see there are some things missing like artist track etc and that gives warning in openhab

this is what i have done so far i only need this because the amplipi binding doesnt provide them and my java is not there :slight_smile:

Thing http:url:music1 "music zone1" [
	baseURL="http://192.168.1.138",
	refresh=20] {
		Channels:
			Type string : artist_source1 "artist source 1" [stateExtension="/api/sources/0", stateTransformation="JSONPATH:$.info.artist"]
			Type string : track_source1 "track source 1" [stateExtension="/api/sources/0", stateTransformation="JSONPATH:$.info.track"]
            Type string : station_source1 "station source 1" [stateExtension="/api/sources/0", stateTransformation="JSONPATH:$.info.station"]
			Type string : status_source1 "status source 1" [stateExtension="/api/sources/0", stateTransformation="JSONPATH:$.info.state"]
			Type image : image_source1 "station image source 1" [stateExtension="/api/sources/0/image/400"]

}
String      Current_artist_source1    {channel="http:url:music1:artist_source1"}
String      Current_track_source1    {channel="http:url:music1:track_source1"}
String      Current_station_source1    {channel="http:url:music1:station_source1"}
String      State_station_source1    {channel="http:url:music1:status_source1"}
Image      Current_image_source1    {channel="http:url:music1:image_source1"}

The answer is in the post already linked.
Use REGEX to determine if text keyword “track” is present.
Chain to JSONPATH for field “track”
This only runs through if the field is present

1 Like

as usual thank you for pointing me i was reading that but did not understand anything so this is the final result like you said

			Type string : artist_source1 "artist source 1" [stateExtension="/api/sources/0",stateTransformation="REGEX:(.*artist.*)∩JSONPATH:$.info.artist"]
			Type string : track_source1 "track source 1" [stateExtension="/api/sources/0",stateTransformation="REGEX:(.*track.*)∩JSONPATH:$.info.track"]
            Type string : station_source1 "station source 1" [stateExtension="/api/sources/0",stateTransformation="REGEX:(.*station.*)∩JSONPATH:$.info.station"]
			Type string : status_source1 "status source 1" [stateExtension="/api/sources/0",stateTransformation="REGEX:(.*state.*)∩JSONPATH:$.info.state"]
			Type image : image_source1 "station image source 1" [stateExtension="/api/sources/0/image/400"]
1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.