Trigger Yaml doesn't fire. Probable user error

Hi all
I finally got this yaml to pass the restart check, but now it does not update despite the outdoor temperature increasing, and the template developer tools doesn’t mention the gw2000c_outdoor_temperature sensor. It says:-
This template listens for the following state changed events:

  • Entity: today_max_outdoor_temperature
    Apologies for this probable misunderstanding as its my first trigger based sensor.
  - triggers:
      - platform: time
        at: "00:00:00"
      - platform: template
        value_template: "{{ states('sensor.gw2000c_outdoor_temperature') < states('today_min_outdoor_temperature') }}"
    sensor:
        - name: Today min outdoor temperature
          unique_id: today_min_outdoor_temperature
          unit_of_measurement: "°C"
          device_class: temperature
          icon: mdi:thermometer-chevron-up
          state: "{{ states('sensor.gw2000c_outdoor_temperature')}}"
          attributes:
            datetime: "{{ now() }}"

One syntax correction and one template correction.

When performing an arithmetic comparison of two sensor values, the values must be converted into float or int (because by default all entity values are strings even when they appear to be numbers).

  - trigger:
      - platform: time
        at: "00:00:00"
      - platform: template
        value_template: "{{ states('sensor.gw2000c_outdoor_temperature') | float(0) < states('today_min_outdoor_temperature') | float0) }}"
    sensor:
      - name: Today min outdoor temperature
        unique_id: today_min_outdoor_temperature
        unit_of_measurement: "°C"
        device_class: temperature
        icon: mdi:thermometer-chevron-up
        state: "{{ states('sensor.gw2000c_outdoor_temperature') }}"
        attributes:
          datetime: "{{ now() }}"

This Trigger-based Template Sensor will trigger at midnight and whenever the Template Trigger’s value changes from false to true.

The problem with the design of your Template Trigger is that it will trigger when the outdoor temperature is less than the Template Sensor’s value and then never again as the outdoor temperature continues to decrease.

That’s because a Template Trigger fires when its template’s value changes from false to true. It first has to be false before it can become true. So if it becomes true and remains that way, never returning to false, there will be no further triggering.

If you want the daily minimum temperature, I suggest something like the following:

- trigger:
    - platform: time
      at: '00:00:00'
    - platform: state
      entity_id: sensor.gw2000c_outdoor_temperature
  sensor:
    - name: Today Min Outdoor Temperature
      unique_id: today_min_outdoor_temperature
      unit_of_measurement: '°C'
      device_class: temperature
      state: >
        {% set t_new = states('sensor.gw2000c_outdoor_temperature') | float(100) %}
        {{ [t_new, this.state | float(100)] | min if trigger.platform != 'time' else t_new }}
      attributes:
        datetime: "{{ now() | as_local }}"

This cannot possibly work, an entity always begins with a domain so should probably be sensor.today_min_outdoor_temperature

Thank you Taras; I knew I was doing something wrong, and yes its not the first time I have been bitten by the less than staying true, so I should have twigged.

Thanks again

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.