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.
- 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
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.
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.