Trigger with condition to control template sensor update

I would appreciate any help with the template yaml below. The entity sensor.mySensor correctly appears on a dashboard but the condition block has no effect on the sensor output which updates whenever the trigger fires (every 30s here)

Any thoughts on what I am doing wrong?

The Jinja2 template editor shows the same behaviour: the output still updates even though the condition evaluates as ‘False’

The functionality to include conditions with triggers has recently been added to template sensors in Home Assistant. Has anyone else experienced problems with making the new functionality work correctly?

My version: Core
2025.3.3
Supervisor
2025.03.2
Operating System
14.2

============================================
YAML
template:

  • trigger:
    trigger: state
    entity_id: sensor.solar_load_power
    condition:
    • condition: template
      value_template: >
      {{ (states.input_boolean.mytoggle.state == “on”) }}
  • sensor:
    • name: “mySensor”
      unit_of_measurement: “kWh”
      state: >
      {% set result = states(‘sensor.solar_load_power’) | float(0) %}
      {{(result)}}

before we start - go reformat your code in your post - embed it inside preformat (three back-ticks) or use the preformatted text block under the gear in the editor.

It’s impossible to read the (very important) yaml spacing if you dont
How to format your code in forum posts - Community Guides - Home Assistant Community

I just performed a test and confirmed condition works correctly in a Trigger-based Template Sensor.

Try this version:

template:
  - trigger:
      - trigger: state
        entity_id: sensor.solar_load_power
    condition:
      - condition: state
        entity_id: input_boolean.mytoggle
        state: 'on'
    sensor:
      - name: mySensor
        unit_of_measurement: kWh
        state: "{{ trigger.to_state.state | float(0) }}"

I agree with NathanCu that it would be preferable for you to post your YAML as formatted code. It’s challenging for us to examine what you posted and confirm all of its syntax and indentation is correct. Refer to the linked guide in NathanCu’s post.

1 Like

Good advice. Thankyou. There was indeed a syntax error

1 Like

Helpful link, thankyou

1 Like