Hi! I’ve finally trying to get rid of an annoying error that appears on HASS log at startup.
I have a serial sensor:
sensor:
- platform: serial
name: bedroom
serial_port: /dev/ttyS0
That presents data like this:
{"lights":[0,1,-9],"environmental":[88,-9,-9]}
The environmental
JSON tag is temperature (first value), humidity (second value), pressure (third value).
To extract the humidity value of bedroom
sensor I do:
- platform: template
humid_bedroom:
device_class: humidity
friendly_name: "Bedroom humidity"
unit_of_measurement: '%'
value_template: >-
{% if states.sensor.bedroom.attributes.environmental[1]|float > 0 %}
{{states.sensor.bedroom.attributes.environmental[1]|float|round(1)}}
{% endif %}
The conditional on value_template
exists because, sometimes, the sensor generate negative values for humidity, and this is not good.
The problem is that, at startup, bedroom
is not populated (because the serial sensors takes sometime to load), and the conditional produces an error on HASS log. This behavior is documented on the “Warning” that exists on https://www.home-assistant.io/docs/configuration/templating/#states.
I’ve tried using all statements suggested on the Warning indicated before, without success. I can’t figure how to test an specific element of a JSON tag array with those functions.
It is possible to do this test without errors on HASS log?
Thanks in advance.
Cheers!