Hello,
I have a strange issue where a trigger-based template sensor is not being created, even though its source entity exists and has a valid state.
The Source Sensor (from Modbus YAML): This sensor works and shows a state (e.g., 16777213) in Developer Tools.
YAML- name: "SMA Lade Mode" unique_id: sma_lade_mode slave: 3 address: 40151 input_type: holding data_type: int32 scan_interval: 10
The Template Sensor (placed in a file under /packages): This sensor is never created. It does not appear in Developer Tools.
`YAMLtemplate:
- trigger:
- platform: state
entity_id: sensor.sma_lade_mode
sensor: - name: “SMA Control State Text”
unique_id: sma_control_state_text_test
state: >
{% set mode = trigger.to_state.state | int(0) %}
{% if mode == 802 %}
External Control
{% elif mode == 803 or mode == 16777213 %}
Automatic
{% else %}
Unknown ({{ mode }})
{% endif %}`
- platform: state
Things I have already tried:
- Confirmed 100% that
sensor.sma_lade_modeexists and has a state. - Tried both a normal template sensor and the trigger-based one above.
- Confirmed there are no YAML syntax or indentation errors.
- Isolated the template sensor in its own new file in the
packagesdirectory. - Tried changing the
unique_idandname. - Deleted
sensor.sma_lade_modefrom the entity registry and let Home Assistant recreate it on restart. - Even a minimal template with just
state: "{{ trigger.to_state.state }}"fails to be created.
Other template sensors in my system work fine. It seems to be a specific issue with this Modbus sensor as a source for templates.
Any ideas what could cause this bug? Thanks!