Hi All,
I put the following into the template editor and it works fine. However, when I put it into configuration.yaml (extract below) I get unknown value for each sprinkler. In Python it’s simple, I must be missing something.
Most grateful for any assistance or a better approach to the issue.
Because you aren’t extracting the information from the rest sensor, your extracting from an unknown object named value_json.
try this:
Place the sn object into the attributes, then access that attribute from the states object in the value template. Just take a look at the documentation for rest sensors, this method is one of the examples below.
One needs to be careful what gets parsed into the REST sensor’s state since there is a character limit (255 or 256, I can never remember which.) In this case, if the JSON really is that small it probably doesn’t matter. But often it does. So it might be better to use "{{ value_json.nstations }}" or something like that.
I’ve also found that using states.sensor.xxx... in templates can sometimes fool the entity extraction logic. So it might be better in this case to use the state_attr function.
I implemented your suggested change and it worked perfectly, Many thanks.
On last question, I want sprinklers 1-8 to to be represent as Off/On on the front end, so I put them under binary_sensor: instead of sensor: for some reason they will only display as Off and won’t recognise a state change. Thanks again
For a binary template sensor, value_template has to return true for the state to be on. Anything else will cause the sensor to be off. Assuming the values can only be the numeric values 0 and 1 you should change it to:
Ok that worked, it recognises the state change, although it now displays True or False, would prefer On/OFF, I should be able to figure that one out.
Wow I’ve got a lot to learn, it’s a great product very impressed
Thanks again
Are you sure it’s under binary_sensor? It should be displaying on and off by default. Have you set a device class? That controls how a binary_sensor is displayed.
EDIT: Note that the actual state of a binary_sensor is always on or off.