Daily max on numeric sensor: how to. in core

well, not final apparently, regular sensors didnt get reset because of below

Logger: homeassistant.helpers.template
Bron: helpers/template/init.py:685
Eerst voorgekomen: 00:00:00 (1 gebeurtenis)
Laatst gelogd: 00:00:00

Template variable error: ‘dict object’ has no attribute ‘to_state’ when rendering ‘{{trigger.to_state.state > trigger.from_state.state or trigger.id in [‘reset’,‘reset_manual’,‘trigger_manual’]}}’

this appears to be an error on the statistics (talking about dict object) effectively also blocking updating the regular sensor.
so will have to take them apart after all.

which I did, and statistics is working fine now, albeit with the known delay

but my state template trigger isnt 100%

it was not reset at midnight since a few days apparently… hadn’t noticed during beta

  - triggers:

      - trigger: time
        at: "00:00:00"
        id: reset # at midnight

      - trigger: state
        entity_id: input_button.trigger_reset
        id: reset_manual # to 0 manually

      - trigger: state
        entity_id: input_button.trigger_zp_opbrengst
        id: trigger_manual # to current state no matter the delta

      - trigger: state
        entity_id: sensor.zp_actuele_opbrengst
        id: update # regular update, only when increased

    conditions:
    # see: https://www.home-assistant.io/integrations/template/#conditions
    # also needs to be met before sensor updates are performed
    # so not only for the actions block
      - >
        {{trigger.to_state.state > trigger.from_state.state or
          trigger.id in ['reset','reset_manual','trigger_manual']}}

    sensor:
      - unique_id: zp_dagelijkse_maximale_opbrengst
        state: >
          {% set current = states('sensor.zp_actuele_opbrengst') | float(0) %}
          {% set previous = this.state | float(0) %}

          {% if trigger.id == 'reset' or trigger.id == 'reset_manual' %}
            0
          {% elif trigger.id == 'trigger_manual' %}
            {{current}}
          {% else %}
            {{[current, previous]|max}}
          {% endif %}
        <<: &power
          device_class: power
          state_class: measurement
          unit_of_measurement: W
        attributes:
          last_changed: >
            {{(this.last_changed|as_local).strftime('%X - %x')}}
          last_trigger: >
            {{trigger.id}}

all triggers work correctly, as you can also see in the history now, I rest using the input_button

why wont this reset during the night?

Could be your condition - I don’t think trigger.from_state exists in time trigger, I mean: what would that be, there’s no entity involved.

but the condition makes explicit?

or trigger.id in ['reset','reset_manual','trigger_manual']

which is the case for the midnight trigger.

Yes, what I meant is maybe it “blows” on the first part of the condition. I’d try reverting the order, make it explicit about when the value exists in trigger, and check log for errors

{{trigger.id in ['reset','reset_manual','trigger_manual'] or (trigger.id == '??' and  trigger.to_state.state > trigger.from_state.state)}}

O right, now I see what you mean.
I couldnt imagine tht would be the case really, but it wont harm to do as you say, let me try that and see what gives during the night.

having said that it would just as much blow the other way? it’s just 2 conditions or’ed

Not necessarily. x or y is already true when x is true, so the second condition is usually not checked at all in such a situation. I think jinja behaves this way too.

well so far so good, I flipped, and all 3 trigger.ids in the list work as expected.

You’d need to reverse the order of that if you want the or logic to handle that correctly.

EDIT: Seems slimak sorted you out and I missed that comment.

I think I might not be following this thread correctly, but you want to know the max output each day?

Last year I wondered the same – to see if my panels were dirty. And if I could get HA to alert me of that.

I first set up an automation to run right after midnight to get the max from the previous day using recorder.get_statistics as @petro showed above to alert me of that day’s output below some threshold. But then it just alerted about the previous day being cloudy even with me trying to account for that.

Then I set up a simple stats graph which is just the max per day, to look at once in a while:

So, what I came here to say, I finally physcially inspected my panels and they were very dirty. I spent a day cleaning them and, well, almost no change in output. :wink:

arghh… good to know.
so system deterioration, or probably to hot for them to perform optimized…

a graph is nice

but as I started this out with, Id like to have an entity with a state, not just a graph

seems to have helped :slight_smile:

let me cling that post of yours then as solution to this, although not forgetting the other help I got in this thread! thanks all! Petro, Didgeridrew,