Rest API Sensor

Hi all, I’m new here and trying to connect a sensor to HA via the rest api.
In a normal browser, I can reach the sensor as follows:

http://192.168.111.171/api/v1/var/roomtemps/item3/status?username=username&password=password

I get the following result:

{
“sumstate”: {
“value”: “19.84;21.00;0.00;8;;0.00;0;0;70.40;;”
}
}

This is the described by the manufacturer:

“actTemp [°C]; setpointTemp [°C]; valve [%]; mode 1=Off|8=Comfort|16=Reduced|64=Manual|256=Standby; reserved Reserved; tempAdjustment [°C]; cooling 0=Off|1=On; elementInfo 0=Ok|1=ManualOff|2=ManualOn|3=Locked|4=Alarm; humidity [%rF]airQuality [ppm|%]; floorTemp [°C]”

How do I have to store this in the configuration.yaml correctly that I can read the values of the temperature and the humidity?

I tried the following without success:

sensor:

Thanks for your support

something like

value_template: '{{ value_json.sumstate.value[0] }}'

should return the first value of sumstate values

HI aceindy, thank you for your help, but i only get a 1, the correct value should be 19,8 °C

I would use something like this (add your password/username back in):

- platform: rest
  name: Room Temps
  resource: http://192.168.111.171/api/v1/var/roomtemps/item3/status
  value_template: "{{ now() }}"
  json_attributes:
    - sumstate

Then you could likely grab info from that using your known manufacturer description splitting the result at the semi-colons.

This way, the state is just a timestamp and the sensor has an attribute sumstate that has the value

The [0] would be incorrect you would need to use Jinja to parse the string apart at the semi-colons, they are not an array, just a string.

Probably:

value_template: '{{ value_json.sumstate.value }}'

Is closer but the state would just be the string. Your have to further process that string by splitting it. See my other post for a different recommendation but it all depends what you want to use the data for.

Hi, I want to read the temperature and in a second sensor the humidity

Still be specific. You want it in a sensor to? Display it? Run automations based on its value?
These are two very different things.

You can easily pass in the state of your generic sensor that gets the string value from the JSON into two other template sensors that grab the values you want. BUT, I would only do that if you want to take action based on their values. It you only want to display them, there are much better/cleaner/less complicated ways.

The example here: Template - Home Assistant

Shows nearly exactly what you want if you only want two sensors/two values. You just need to augment the Jinja to split the “value” at semi-colons and grab the value you want.

only want to display them

value_template: '{{ value_json.sumstate.value.split(";")[0] }}'

Also, please format your code and logs.

ah, yes, my bad… should have used split and take the first var from that :grin:

1 Like

Thanks it works :smiley:

Great! You could do something like this (of course use your own URL in the resource template):

resource_template: "http://192.168.2.245:8123/local/Testing/roomtemp.json"
sensor:
  - name: roomtemp_acttemp
    value_template: "{{ value_json.sumstate.value.split(';')[0] }}"
  - name: roomtemp_humidity
    value_template: "{{ value_json.sumstate.value.split(';')[8] }}"