Need Max Value for the day

I saw this thread Pulling Maximum Value and I attempted to make a sensor that pulls the max temperature my pool has reached for the day but following the Solution my sensor only matches that it currently shows.

  - trigger:
      - platform: time_pattern
        hours: "0"
        minutes: "0"
        id: "midnight"
      - platform: state
        entity_id: sensor.shelly_pool_temperature
        id: "change"
    sensor:
      - name: Pool Max Temp
        state: >
          {% set outt = states('sensor.shelly_pool_temperature')|float(None) %}
          {% set maxt = states('sensor.max_temp')|float(None) %}
          {% if  outt != None  and (trigger.id == 'midnight' or maxt == None
            or outt > maxt) %} {{ outt }}
          {% else %} {{ maxt }} {% endif %}
        unit_of_measurement: C

This is what I have created can anyone point out why its not holding the max temp and its just matching the current temp as you can see they are matching, where the Max Temp shoulnt drop until midnight where it drops to 0.

Any help would be senstational!

Change this:

to:

{% set maxt = states('sensor.pool_max_temp')|float(None) %}

Or better yet, change it to:

{% set maxt = this.state %}

1 Like

Urgh! Yep now I see what I did haha. Thanks!

1 Like

Asking for a newbie to HA. Where do Input this code?
Adjusting for my own sensors I tried putting in a helper template sensor via the UI. But it never shows a value. I tried putting it in configuration.y’all. No results either.

I do find many code examples like this. Allways with the same where-do-I-put-it effect. Tutorials mostly point to setup, but I’ve got it running inside a docker on a synology nas already for Andrew months now. It’s this gap in the middle that keeps eluding me.
Can you help me out?

Almost there I guess. I now have this in my configuration.yaml Key was prefixing it with the line ‘template:’ But … it now does not give any errors, the new sensor (Max…) shows up for use in the dashboards, … but it does not seem to receive any value.

Any suggestions?

template:
  - trigger:
    - platform: time
      at: '00:00:00'
    - platform: state
      entity_id: sensor.thermometer_woonkamer_temperatuur
  - sensor:
    - name: MaxTempWoonkamerVandaag
      unit_of_measurement: C
      device_class: temperature
      state: >
        {% set t_cur = states('sensor.thermometer_woonkamer_temperatuur') | float(0) %}
        {% set t_max = states('sensor.MaxTempWoonkamerVandaag') | float(0) %}
        {% if t_cur != None and (trigger.platform == time or t_max == None or t_cur > t_max) %} {{ t_cur }} {% else %} {{ t_max }} {% endif %}
      attributes:
        temperature_updated: "{{ now() | as_local }}"
template:
  - trigger:
      - platform: time
        at: '00:00:00'
      - platform: state
        entity_id: sensor.thermometer_woonkamer_temperatuur
    sensor:
      - name: MaxTempWoonkamerVandaag
        unit_of_measurement: '°C'
        device_class: temperature
        state: >
          {% set t_new = states('sensor.thermometer_woonkamer_temperatuur') | float(-99) %}
          {{ [t_new, this.state | float(-99)] | max if trigger.platform != 'time' else t_new }}
        attributes:
          temperature_updated: "{{ now() | as_local }}"

Initially its value will probably be unknown. When the value of sensor.thermometer_woonkamer_temperatuur changes, then it will report a numeric value.


NOTE

The example is based on a similar one I posted here in December 2022

First time working with templates and wanted to log the max output of my PV panels per day. Using the above as an example, I created a template for this, however the Trigger keeps showing as Undefined. What am I missing?

  • trigger:
    • platform: time
      at: “00:00:00”
    • platform: state
      entity_id: sensor.power_meter_zt223385000549w0916pv_power
      sensor:
    • name: “Max kWh”
      unit_of_measurement: “kWh”
      device_class: “energy”
      state: >
      {% set t_new = states(‘sensor.power_meter_zt223385000549w0916pv_power’) | float(-99) %}
      {{ [t_new, this.state | float(-99)] | max if trigger.platform != ‘time’ else t_new }}
      attributes:
      kWh_updated: “{{ now() | as_local }}”

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