Binary sensor templates should resolve to true or false. if the state == ‘on’ then the template evaluates to true, turning the binary sensor on. Any other value will result in the template evaluating to false which will turn off the binary sensor.
Error loading /Users/server/.homeassistant/configuration.yaml: while scanning for the next token found character '%' that cannot start any token in "/Users/server/.homeassistant/rest.yaml", line 6, column 10
In simple terms > indicates the template will be on more than one line. - removes the last carriage return and is almost never needed but seems to be included a lot by people here for some unknown reason. It’s not in any of the document examples.
Play with the radio button options here and observe the result on the lower right of the page:
I’ve just been steered onto using rest vs restful sensor to do exactly the same as above (ie. grabbing multiple values in a single call and creating multiple sensors).
It seems that restful sensor can do something similar via json_attributes, but they are still just attributes of a single sensor.
Given that the restful seems to be able to do everything that restful sensor can do, why even have restful sensor ? Whats it use case ?
Backwards compatibility for people who were using it before the new integration was made. There are a few integrations like this, e.g: template sensor platform vs template integration, legacy groups vs new groups.
One doubt I have regarding the rest platform, and the OP title ‘REST sensor with atributes’ is,
Why does Sensor allow for attributes to be defined, but binary_sensor doesn’t?
I want to have a connectivity binary_sensor setup, but I can’t show details of that connectivity in the same entity. Not sure if this comes after and architectural decision regarding binary_Sensors or just noone has had such request before (smells like a ‘WTH’ candidate then)?
You can create a Feature Request (search the category for an existing one first - duplicates will be linked to earlier requests and closed) but be aware that the devs are discouraging the use of attributes where a seperate sensor will do.
I suspect you could make a case for attributes for the template binary sensor as they don’t have an associated device the extra sensor could be attached to.
Further to the comments above, I’ve been experimenting with rest sensor but I am unable to get the value_template with multiple attributes to work - I am unable to set the “value_template” to anything other than “OK”, and this is all I can find in the documentation.
Here is my config.yaml entry:
rest:
- resource: http://my_HP:3000/planets # a VSOP87 planet positions server
method: GET
headers:
User-Agent: Home Assistant
Accept: application/json
scan_interval: 300
sensor:
- name: "My HP Sun"
unique_id: phil121
value_template: "OK"
json_attributes_path: "$.Sun"
json_attributes:
- "RA"
- "Dec"
- "Alt"
- "Az"
- "Rise"
- "Set"
- name: "My HP Mercury"
unique_id: phil122
value_template: "OK"
json_attributes_path: "$.Mercury"
json_attributes:
- "RA"
- "Dec"
- "Alt"
- "Az"
- "Rise"
- "Set"