Recording the maximum of a sensor into another sensor

I have a sensor that updates around every second with the power consumed by my house.
I want to store the maximum into another sensor

At the moment I’ve created a number helper and an automation
The trigger is the state change of the sensor (so it’s triggered very often, nearly every second)
The condition is sensor>input number
The action is updating the input number with the value from the sensor

This seems very inefficient to me as the automation is triggered continuously, is there an alternative?

alias: Max Power House Inst
description: ""
triggers:
  - entity_id: sensor.prism_potenza_casa
    trigger: state
conditions:
  - condition: template
    value_template: >-
      {{ states('sensor.prism_potenza_casa') | float >
      states('input_number.max_house_power') | float }}
actions:
  - target:
      entity_id: input_number.max_house_power
    data:
      value: "{{ states('sensor.prism_potenza_casa') | float }}"
    action: input_number.set_value
mode: single

I know this one, not sure if this is more efficient
Statistics - Home Assistant

I have a whole bunch of these in the configuration.yaml, they reset every day at midnight - not sure, if this is the most efficient way either:

template:
  - trigger:
      - platform: time
        at: '00:00:00'
      - platform: state
        entity_id: sensor.temp
    sensor:
      - name: 'Daily Max Temp'
        unique_id: daily_max_temp'
        unit_of_measurement: '°F'
        state_class: measurement
        device_class: temperature
        state: >
          {% set t_new = states('sensor.temp') | float(0) %}
          {{ [t_new, this.state | float(0)] | max if trigger.platform != 'time' else t_new }}
1 Like

Exactly the point…does the OP want a max of all entries or just of the last X day(s)

I wanted to create a few of these but didn’t want to maintain that much YAML so I created a HACS helper integration to do it, you use an action to reset it whenever you want.