I’m new to Home Assistant and I’m having a hard time getting a simple template to work and after hours of try-and-error and lots of googling i’m at the end of my wits.
Eventually, I even tried to use one of the examples provided by the documentation without success.
I really don’t know what I’m missing:
The configured state works when I test it in the developer tools
No errors are shown in the log
It works when I create the template through the UI
Whatever I try, when creating the template in a file, the resulting state is Unknown
Hi @jeffcrum
This solved it and it works as expected now. Thanks a lot!
I’m a little confused by this behaviour. So just for my understanding, considering this example from the documentation and paying attention to the intention of sensor (afaik, this is relevant for yaml) , I assumed there are 2 different types of sensors defined as a template, trigger-based and non-trigger-based. Is my assumption incorrect?
Or asked differently:
How can you concurrently define sensors that are trigger-based and those that are not trigger-based?
- trigger: #List item 1. Everything from here to the next list item depends on this trigger block.
- trigger:
sensor:
- name: ...
- sensor: #List item 2. There is no trigger defined, so these are state-based template sensors
- name: 'Sun Angle test'
unit_of_measurement: "°"
state: "{{ '%+.1f'|format(state_attr('sun.sun', 'elevation')) }}"
- name: "Sun State"
state: >
{% if is_state('sun.sun', 'above_horizon') %}
up
{% else %}
down
{% endif %}
- trigger: #List item 3. Everything from here to the next list item depends on this trigger block.
- trigger:
binary_sensor:
- name: ...
I’m migrating from openHAB and anticipate needing trigger-based sensors. But how I ended up today with this configuration has more to do with the migration approach I chose. Since I’m new to Home Assistant, I tend to start by copying the full configuration examples from the documentation to get a baseline.