#Automation only triggers once in the morning

1 messages · Page 1 of 1 (latest)

abstract siren
#

Hi all, i have created an automation with the purpose collecting the last known value, before it gets unavailable. Its the last set Load (percentage) of my solar inverter. I want to see the last set/known value because im reading this information using a modbus connection. When the sun is under; i see a Unavailable regarding this modbus-integration.
Today the Growatt_MTL_Load had his last update on 17:46 UTC+2, but my Automation triggered twice:

OnthoudenGrowattLoadAdress3 triggered by state of Growatt_MTL_Load
9:15:22 AM - 12 hours ago - Traces
OnthoudenGrowattLoadAdress3 triggered by state of Growatt_MTL_Load
9:05:17 AM - 12 hours ago - Traces

This 09:05 is the first moment that the Growatt_MTL_Load sensor received '100'..

Im new to ha and automation, so no idea if i did something wrong, or if its valid. I made everything in de gui.
Automation:

alias: OnthoudenGrowattLoadAdress3
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.growatt_mtl_load
conditions:
  - condition: template
    value_template: "{{ trigger.to_state.state not in ['unknown', 'unavailable'] }}"
actions:
  - action: input_number.set_value
    metadata: {}
    target:
      entity_id: input_number.growattloadlastknown
    data:
      value: "{{ states('sensor.growatt_mtl_load') }}"
mode: single
mighty spoke
#

There's a potential race condition in that automation because the state of the source sensor may have changed between the time the automation triggered and setting the value of the input_number

#

you can avoid that by using

      value: "{{ trigger.to_state.state }}"
#

Otherwise, I can't really say anything about the problem, if there's a problem at all. If you're concerned about the value in the input_number or whether the automation should have triggered, you can look at the trace for the automation and it will tell you

abstract siren
mighty spoke
#
  - action: input_number.set_value
    metadata: {}
    target:
      entity_id: input_number.growattloadlastknown
    data:
      value: "{{ trigger.to_state.state }}"
abstract siren
#

Oke it had one trigger, in the morning. It went from unavailable to 100 and the input number got set.
I didn’t change the percentage today, so it never changed.
At 17:46 the sensor became unavailable.

sage compass
#

So that's what you want, right?

abstract siren
sage compass
#

Might have picked the has_value filter instead of unknown/unavailable checking but should work fine if you use trigger.to_state.state.

Little bit more advanced would to change it into a trigger based template sensor.

abstract siren
mighty spoke
sage compass
#

Yep, although I wanted to write is_number but pretty much all the same 😅