Value hold helper

Hello,

I am using two Hoymiles inverters, read-out by an OpenDTU and connected to HA via MQTT. One inverter is connected to a battery, that discharges every evening.

My problem is to build the daily total yield. The inverter (or OpenDtu) without battery does shortly send a daily yield of 0 Wh, just after the real max daily value and then shuts off and restarts counting on the next day.

How could I use a helper or template-sensor to cutoff this decrease to 0, so just hold the daily max value and only restart counting from 0 at 0:00?

You would need a triggered template.
I think this could work.

template:
  - trigger:
    - trigger: time
      id: reset
      at: "00:00:00"
    - trigger: state
      id: sensor
      entity_id: sensor.opendtu 
    sensor:
      - name: "total yield"
        unique_id: "total yield"
        state: >- 
                {%- if trigger.id == "sensor" and trigger.to_state.state != 0 -%}
                    {{ trigger.to_state.state }}
                {%- elif if trigger.id == "sensor" and trigger.to_state.state != 0 -%}
                    {{ states('sensor.total_yield') }}
                {%- elif if trigger.id == "reset" -%}
                0
                {%- endif -%}
                

Remember to change the entity ids.

And this needs to go in configuration.yaml