Trigger-based Template Sensor is not created from a valid Modbus sensor

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 %}`

Things I have already tried:

  • Confirmed 100% that sensor.sma_lade_mode exists 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 packages directory.
  • Tried changing the unique_id and name.
  • Deleted sensor.sma_lade_mode from 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!

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

Are there any errors in your logs related to the template sensor?

There is nothing in the standard log related to the problem