Hi. I’m pretty new to this whole yaml/HA malarky and have watched countless YT vids and searched on here and yet… I am stil stuck, so help me obi wan…
Ok what I’m trying to do. Is there are two sensors sensor.outdoor_temperature and sensor.outdoor_temperature_2 and only one of them will have a float value, while the other will have a value of unavailable.
What I want to do is If sensor.outdoor_temperature = unavailable then set a new custom sensor sensor.njs_outside_temp to sensor.outdoor_temperature_2 else set sensor.njs_outside_temp to sensor.outdoor_temperature
In every other coding language I know C, VB, heck even cobol dead easy. But this got me stumped. So in my sensors.yaml I have gotten the condition statement to parse but am at a total loss on how to assign the values. The closest I have gotten is
sensors: ```
#custom sensors that work...
```- sensor:
- name: njs_outside_temp
unique_id: njs_outside_temp
state: >
{% if is_states('sensor.outdoor_temperature', 'unknown') %}
{{ states('sensor.outdoor_temperature') }}
{% else %}
{{ states('sensor.outdoor_temperature_2') }}
{% endif %} ```
Which gives a "Configuration warnings
Invalid config for 'sensor' at Sensors.yaml, line 70: required key 'platform' not provided"
Such a simple thing to ask/do right.. Yet this is proving my nemesis. Hope you can help
Getting much closer now. Thank you. Only issue remaining is that the value of njs_outside_temp is output as “state: > 10.78” . where 10.78 is the what it should be.
The platform: template Sensors: part is defined in my sensors.yaml file, which is included from configuration. yaml
you are still mixing up the legacy template sensor syntax with the modern legacy sensor syntax.
seeing that most of your syntax is the legacy syntax we’ll stick to that.
“state:” isn’t a valid option for the legacy syntax so the template engine is assuming it’s part of the value_template since everything there is enclosed on quotes.