Restart trigger timer if automation failed to succeed due to condition

Hi all, I’ve read so many posts in the last days, and none answered my problem…
I am trying to start my wallbox when the sun is shining long enough; works fine. I am then trying to raise the ampere (via API) if the PV is producing enough power for e.g. 10 minutes. However, it should only raise the ampere if the battery state of charge is higher than 80%.
Programmatically, everything works as intended. However:
When automation is triggered (a lot of sun), and the condition is -not- met, the ampere won’t be increased. What is the best way to now restart the duration to wait and see, if the sun is still there. Create a new timer, that resets after 10 minutes and triggers the automation every time again?
Currently it’s like this:

alias: Wallbox Increase to 16A
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.pv_production
    for:
      hours: 0
      minutes: 10
      seconds: 0
    above: 4800
condition:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.battery_soc
        above: 80
      - condition: numeric_state
        entity_id: sensor.battery_load
        below: -1600
action:
  - service: wallbox.set_ampere
    metadata: {}
    data:
      current_p1: 16
      current_p2: 16
      current_p3: 16
      time_to_live: 0
      device_id: #deleted
mode: restart #tried a couple of modes here, but then i saw the documentation for that, and it doesnt fulfill my needs

Thank you very much

You will need a helper timer along with a second automation.

Can’t be done in a single automation.

The problem is that numeric_state conditions don’t support holding state (meaning you can’t use the for: option with them).

If they did, you would simply use 3 triggers and 3 conditions. That way when any of the 3 become true, the automation will check to see if the others are already true and continue along if they are.

If you configured it that way now, when either the battery_soc or battery_load conditions become true, it would check if pv_production is above 4800 but it wouldn’t verify for how long it has been above 4800.

If you need that confirmation, then I would create a template binary sensor that turns on when production has been > 4800 for 10 minutes. Then you can reference that binary_sensor and you don’t need to hold state in the automation.

To create the template sensor you can just copy the example in the docs of a “washing machine running” sensor. You’ll want delay_on instead of delay_off and modify the values and change the reference sensor.

ok, i have an automation-only solution for you… this is tricky and there are some super tiny race conditions where it will fail, but i’m talking milliseconds so i personally wouldn’t worry about them.

i’d love others here to audit me and make sure i’m not screwed up on this since i haven’t actually tested it…

here’s the code:

alias: Wallbox Increase to 16A
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.pv_production
    for:
      hours: 0
      minutes: 10
      seconds: 0
    above: 4800
condition: []
action:
  - wait_template: |-
      {{ states('sensor.pv_product') | int < 4800 or
        ( states('sensor.barrery_soc') | int > 80 or states('sensor.battery_load') | int < -1600 ) }}
    continue_on_timeout: true
  - if:
      - condition: template
        value_template: "{{ states('sensor.pv_production') | int > 4800 }}"
    then:
      - service: wallbox.set_ampere
        metadata: {}
        data:
          current_p1: 16
          current_p2: 16
          current_p3: 16
          time_to_live: 0
          device_id: null

the trick is that once the trigger is hit, i’m going to wait for the trigger to not be true, or i’m going to wait for the condition to become true. if the trigger is no longer true then the automation needs to end (which i’ve done by checking the “if” to see if the trigger numeric_state is still held or not… if that happens then the automation bails and the 10 minute starts over. if the trigger state is still true then it must have passed the wait because the coondition became true. in which case run the action.

tagging @jeffcrum @mekaneck to check me here and call bs on me if i’m wrong.

note that generally speaking, infinite waits like this are no-no’s because it can get interrupted by home assistant restart. however if that happens in this case i think it’s non-catestrophic and might even restart the 10 min timeout which would be ideal.

Looks good to me.

But one thing to note is that for the numeric state trigger, the sensor has to cross the threshold in order to trigger. If the threshold has been crossed and this automation is running, or the 10 minute state hold is underway, and then HA is restarted or automations are reloaded, the 10 minute timer doesn’t start again until pv_production falls below 4800 and then rises again.

A template sensor will start the 10 minute delay immediately after restart if the condition is already true.

You could still do something like that all inside the automation but you’d have to trigger on any state change of pv_production and inside your wait template you’d also have to verify that it has been at least 10 minutes since the trigger was fired.

I agree with your suggested approach (create a separate entity to monitor pv_production) but I believe a Trigger-based Template Binary Sensor might be what’s needed here because its state is restored after a restart.

Here’s my understanding of how it works:

A Template Binary Sensor doesn’t retain its previous state on restart and must be recalculated. In this particular case, the delay_on option is employed. If the Template Binary Sensor’s state is on before restart, after restart it will not be immediately restored to on but only after delay_on is fulfilled. While time passes (10 minutes) for delay_on’s conditions to be met (pv_production exceeds 4800), its state will default to off.

In contrast, a Trigger-based Template Binary Sensor whose state is on before restart will be immediately restored to on after restart.

1 Like

yes good point. A trigger-based template binary_sensor would be the best approach to make this robust against restarts. Then using numeric_state triggers would be fine. I think this is what you’re suggesting:

template:
  - trigger:
      - platform: numeric_state
        entity_id: sensor.pv_production
        above: 4800
        for:
          minutes: 10
        id: 'on'
      - platform: numeric_state
        entity_id: sensor.pv_production
        below: 4800
        id: 'off'
    binary_sensor:
      - name: PV Production Above 4800
        state: "{{ trigger.id }}"
1 Like

Exactly.

It’ll make it easy to create an automation that employs a matching set of 3 triggers and 3 conditions (like you suggested in your first post).

1 Like

thinking through it more, I think my suggestion of numeric_state is best avoided here. There’s edge cases where the threshold is crossed either direction during restart, or going above within 10 minutes before restart. In those cases the sensor won’t update with the right state until the threshold is crossed again. The trigger-based template sensor is still the right method though.

template:
  - trigger:
      - platform: state
        entity_id: sensor.pv_production
        not_to:
          - unavailable
          - unknown
    binary_sensor:
      - name: PV Production Above 4800
        state: "{{ trigger.to_state.state | float(0) > 4800 }}"
        delay_on: "0:10:00"
3 Likes

Thanks for all the input and different approaches. I now programmed a template as mekaneck said; it works fine. Now I am trigger the automation with the binary sensor and it’s exactly behaving as intended.

1 Like

I have to bump this again… with bigger values it apparently does not work flawlessly… somehow the binary sensor stays off the whole day, even though it has been over 5000 e.g. for 10 minutes. where does this come from? maybe due to the change ov value quite often and not staying in a definite state like “on”? for lower values (like 1000) it works better, but not flawless. hence i think that there might be an unknown state in between or so…
i was considering maybe to turn the whole thing around and make a script out of it e.g.
I need a mechanism to check if it has been above 10 minutes (and afterwards check on each new value again) and then check the conditions… so even when it’s 10:01, 10:02 etc.
thank you very much :slight_smile:

There’s something you’re not telling us about the sensor value. Can you share a history graph of the pv_production sensor and the binary template sensor at a time when it was acting incorrectly?

The only thing I can assume is that the pv_production sensor sometimes contains a value that can’t be converted to a float, and therefore the code defaults to zero.

If that is what is happening, you could just ignore the non-number states:

template:
  - trigger:
      - platform: state
        entity_id: sensor.pv_production
        not_to:
          - unavailable
          - unknown
    binary_sensor:
      - name: PV Production Above 4800
        state: "{{ this.state if not is_number(trigger.to_state.state) else trigger.to_state.state | float > 4800 }}"
        delay_on: "0:10:00"

Here is my code:

template:
  - trigger:
      - platform: state
        entity_id: sensor.fems_produktion
        not_to:
          - unavailable
          - unknown
    binary_sensor:
      - name: PV Produktion Über 4800 für 10 Minuten
        state: "{{ trigger.to_state.state | float(0) > 4800 }}"
        delay_on: "0:10:00"

and i extracted the sensor and the values of a day, that has produced enough kw, ill quote some. there are not zeros etc. in between:

binary_sensor.pv_produktion_uber_4800_fur_10_minuten,off,2024-08-12T22:00:00.000Z

sensor.fems_produktion,6059,2024-08-13T15:33:57.013Z
sensor.fems_produktion,6054,2024-08-13T15:34:00.014Z
sensor.fems_produktion,6020,2024-08-13T15:34:03.007Z
sensor.fems_produktion,5988,2024-08-13T15:34:06.041Z
sensor.fems_produktion,6036,2024-08-13T15:34:09.044Z
sensor.fems_produktion,6023,2024-08-13T15:34:12.010Z
sensor.fems_produktion,6020,2024-08-13T15:34:15.030Z
sensor.fems_produktion,6003,2024-08-13T15:34:18.012Z
sensor.fems_produktion,6036,2024-08-13T15:34:21.010Z
sensor.fems_produktion,6021,2024-08-13T15:34:24.049Z
sensor.fems_produktion,6055,2024-08-13T15:34:27.013Z
sensor.fems_produktion,6060,2024-08-13T15:34:30.019Z
sensor.fems_produktion,6061,2024-08-13T15:34:33.064Z
sensor.fems_produktion,6065,2024-08-13T15:34:36.053Z
sensor.fems_produktion,6077,2024-08-13T15:34:39.008Z
sensor.fems_produktion,6076,2024-08-13T15:34:45.013Z
sensor.fems_produktion,6060,2024-08-13T15:34:48.044Z
sensor.fems_produktion,6025,2024-08-13T15:34:51.008Z
sensor.fems_produktion,6076,2024-08-13T15:34:54.012Z
sensor.fems_produktion,6053,2024-08-13T15:34:57.008Z
sensor.fems_produktion,6076,2024-08-13T15:35:00.013Z
sensor.fems_produktion,6026,2024-08-13T15:35:03.010Z
sensor.fems_produktion,6076,2024-08-13T15:35:06.012Z
sensor.fems_produktion,6042,2024-08-13T15:35:09.082Z
sensor.fems_produktion,6059,2024-08-13T15:35:12.020Z
sensor.fems_produktion,6051,2024-08-13T15:35:18.007Z
sensor.fems_produktion,6035,2024-08-13T15:35:21.050Z
sensor.fems_produktion,6059,2024-08-13T15:35:24.042Z
sensor.fems_produktion,6069,2024-08-13T15:35:27.009Z
sensor.fems_produktion,6037,2024-08-13T15:35:30.008Z
sensor.fems_produktion,6087,2024-08-13T15:35:33.012Z
sensor.fems_produktion,6057,2024-08-13T15:35:36.009Z
sensor.fems_produktion,6107,2024-08-13T15:35:39.046Z
sensor.fems_produktion,6075,2024-08-13T15:35:42.016Z
sensor.fems_produktion,6062,2024-08-13T15:35:45.009Z
sensor.fems_produktion,6090,2024-08-13T15:35:48.019Z
sensor.fems_produktion,6114,2024-08-13T15:35:51.060Z
sensor.fems_produktion,6115,2024-08-13T15:35:54.047Z
sensor.fems_produktion,6099,2024-08-13T15:35:57.047Z
sensor.fems_produktion,6106,2024-08-13T15:36:00.010Z
sensor.fems_produktion,6115,2024-08-13T15:36:03.008Z
sensor.fems_produktion,6099,2024-08-13T15:36:06.014Z
sensor.fems_produktion,6073,2024-08-13T15:36:09.044Z
sensor.fems_produktion,6072,2024-08-13T15:36:12.011Z
sensor.fems_produktion,6049,2024-08-13T15:36:15.019Z
sensor.fems_produktion,6067,2024-08-13T15:36:18.014Z
sensor.fems_produktion,6034,2024-08-13T15:36:21.009Z
sensor.fems_produktion,6007,2024-08-13T15:36:24.042Z
sensor.fems_produktion,6032,2024-08-13T15:36:27.006Z
sensor.fems_produktion,6050,2024-08-13T15:36:30.011Z
sensor.fems_produktion,6026,2024-08-13T15:36:33.007Z
sensor.fems_produktion,6075,2024-08-13T15:36:36.010Z
sensor.fems_produktion,6024,2024-08-13T15:36:39.044Z
sensor.fems_produktion,6056,2024-08-13T15:36:42.014Z
sensor.fems_produktion,6088,2024-08-13T15:36:45.010Z
sensor.fems_produktion,6064,2024-08-13T15:36:48.022Z
sensor.fems_produktion,6096,2024-08-13T15:36:51.050Z
sensor.fems_produktion,6071,2024-08-13T15:36:54.048Z
sensor.fems_produktion,6061,2024-08-13T15:36:57.007Z
sensor.fems_produktion,6108,2024-08-13T15:37:00.056Z
sensor.fems_produktion,6105,2024-08-13T15:37:03.014Z
sensor.fems_produktion,6143,2024-08-13T15:37:06.012Z
sensor.fems_produktion,6149,2024-08-13T15:37:09.046Z
sensor.fems_produktion,6115,2024-08-13T15:37:12.055Z
sensor.fems_produktion,6092,2024-08-13T15:37:15.007Z
sensor.fems_produktion,6093,2024-08-13T15:37:18.012Z
sensor.fems_produktion,6107,2024-08-13T15:37:21.032Z
sensor.fems_produktion,6083,2024-08-13T15:37:24.047Z
sensor.fems_produktion,6131,2024-08-13T15:37:27.009Z
sensor.fems_produktion,6123,2024-08-13T15:37:30.010Z
sensor.fems_produktion,6155,2024-08-13T15:37:33.060Z
sensor.fems_produktion,6137,2024-08-13T15:37:36.056Z
sensor.fems_produktion,6096,2024-08-13T15:37:39.044Z
sensor.fems_produktion,6110,2024-08-13T15:37:42.046Z
sensor.fems_produktion,6125,2024-08-13T15:37:45.009Z
sensor.fems_produktion,6118,2024-08-13T15:37:48.040Z
sensor.fems_produktion,6097,2024-08-13T15:37:51.009Z
sensor.fems_produktion,6081,2024-08-13T15:37:54.047Z
sensor.fems_produktion,6074,2024-08-13T15:37:57.009Z
sensor.fems_produktion,6076,2024-08-13T15:38:00.049Z
sensor.fems_produktion,6042,2024-08-13T15:38:03.009Z
sensor.fems_produktion,6059,2024-08-13T15:38:06.015Z
sensor.fems_produktion,6079,2024-08-13T15:38:09.044Z
sensor.fems_produktion,6102,2024-08-13T15:38:12.007Z
sensor.fems_produktion,6127,2024-08-13T15:38:15.008Z
sensor.fems_produktion,6111,2024-08-13T15:38:18.025Z
sensor.fems_produktion,6158,2024-08-13T15:38:21.010Z
sensor.fems_produktion,6134,2024-08-13T15:38:24.045Z
sensor.fems_produktion,6155,2024-08-13T15:38:27.006Z
sensor.fems_produktion,6141,2024-08-13T15:38:30.008Z
sensor.fems_produktion,6097,2024-08-13T15:38:36.007Z
sensor.fems_produktion,6163,2024-08-13T15:38:39.043Z
sensor.fems_produktion,6147,2024-08-13T15:38:42.010Z
sensor.fems_produktion,6097,2024-08-13T15:38:45.007Z
sensor.fems_produktion,6110,2024-08-13T15:38:48.006Z
sensor.fems_produktion,6115,2024-08-13T15:38:51.027Z
sensor.fems_produktion,6112,2024-08-13T15:38:54.041Z
sensor.fems_produktion,6122,2024-08-13T15:38:57.006Z
sensor.fems_produktion,6089,2024-08-13T15:39:00.045Z
sensor.fems_produktion,6094,2024-08-13T15:39:03.016Z
sensor.fems_produktion,6103,2024-08-13T15:39:06.037Z
sensor.fems_produktion,6069,2024-08-13T15:39:09.043Z
sensor.fems_produktion,6070,2024-08-13T15:39:12.008Z
sensor.fems_produktion,6077,2024-08-13T15:39:15.006Z
sensor.fems_produktion,6027,2024-08-13T15:39:18.022Z
sensor.fems_produktion,5980,2024-08-13T15:39:21.011Z
sensor.fems_produktion,5923,2024-08-13T15:39:24.026Z
sensor.fems_produktion,5903,2024-08-13T15:39:27.033Z
sensor.fems_produktion,5863,2024-08-13T15:39:30.009Z
sensor.fems_produktion,5920,2024-08-13T15:39:33.052Z
sensor.fems_produktion,5928,2024-08-13T15:39:36.007Z
sensor.fems_produktion,5916,2024-08-13T15:39:39.007Z
sensor.fems_produktion,5955,2024-08-13T15:39:42.030Z
sensor.fems_produktion,5912,2024-08-13T15:39:45.006Z
sensor.fems_produktion,5893,2024-08-13T15:39:48.055Z
sensor.fems_produktion,5855,2024-08-13T15:39:51.009Z
sensor.fems_produktion,5886,2024-08-13T15:39:54.007Z
sensor.fems_produktion,5854,2024-08-13T15:39:57.014Z
sensor.fems_produktion,5887,2024-08-13T15:40:00.007Z
sensor.fems_produktion,5941,2024-08-13T15:40:03.030Z
sensor.fems_produktion,5945,2024-08-13T15:40:06.006Z
sensor.fems_produktion,5914,2024-08-13T15:40:09.042Z
sensor.fems_produktion,5935,2024-08-13T15:40:12.008Z
sensor.fems_produktion,5998,2024-08-13T15:40:15.036Z
sensor.fems_produktion,5991,2024-08-13T15:40:18.005Z
sensor.fems_produktion,5992,2024-08-13T15:40:21.013Z
sensor.fems_produktion,5972,2024-08-13T15:40:24.037Z
sensor.fems_produktion,5953,2024-08-13T15:40:27.007Z
sensor.fems_produktion,5920,2024-08-13T15:40:30.007Z
sensor.fems_produktion,5904,2024-08-13T15:40:33.025Z
sensor.fems_produktion,5863,2024-08-13T15:40:36.033Z
sensor.fems_produktion,5788,2024-08-13T15:40:39.039Z
sensor.fems_produktion,5721,2024-08-13T15:40:42.010Z
sensor.fems_produktion,5735,2024-08-13T15:40:45.006Z
sensor.fems_produktion,5688,2024-08-13T15:40:48.009Z
sensor.fems_produktion,5679,2024-08-13T15:40:51.008Z
sensor.fems_produktion,5726,2024-08-13T15:40:54.045Z
sensor.fems_produktion,5761,2024-08-13T15:40:57.009Z
sensor.fems_produktion,5730,2024-08-13T15:41:00.063Z
sensor.fems_produktion,5748,2024-08-13T15:41:03.008Z
sensor.fems_produktion,5762,2024-08-13T15:41:06.005Z
sensor.fems_produktion,5739,2024-08-13T15:41:09.043Z
sensor.fems_produktion,5769,2024-08-13T15:41:12.008Z
sensor.fems_produktion,5814,2024-08-13T15:41:15.008Z
sensor.fems_produktion,5787,2024-08-13T15:41:18.022Z
sensor.fems_produktion,5761,2024-08-13T15:41:21.009Z
sensor.fems_produktion,5736,2024-08-13T15:41:24.065Z
sensor.fems_produktion,5702,2024-08-13T15:41:27.006Z
sensor.fems_produktion,5658,2024-08-13T15:41:30.016Z
sensor.fems_produktion,5647,2024-08-13T15:41:33.012Z
sensor.fems_produktion,5711,2024-08-13T15:41:36.009Z
sensor.fems_produktion,5698,2024-08-13T15:41:39.043Z
sensor.fems_produktion,5735,2024-08-13T15:41:42.010Z
sensor.fems_produktion,5805,2024-08-13T15:41:45.010Z
sensor.fems_produktion,5785,2024-08-13T15:41:48.005Z
sensor.fems_produktion,5818,2024-08-13T15:41:51.016Z
sensor.fems_produktion,5792,2024-08-13T15:41:54.044Z
sensor.fems_produktion,5809,2024-08-13T15:41:57.009Z
sensor.fems_produktion,5759,2024-08-13T15:42:00.009Z
sensor.fems_produktion,5735,2024-08-13T15:42:03.008Z
sensor.fems_produktion,5749,2024-08-13T15:42:06.007Z
sensor.fems_produktion,5706,2024-08-13T15:42:09.045Z
sensor.fems_produktion,5673,2024-08-13T15:42:12.014Z
sensor.fems_produktion,5627,2024-08-13T15:42:15.009Z
sensor.fems_produktion,5586,2024-08-13T15:42:18.009Z
sensor.fems_produktion,5541,2024-08-13T15:42:21.008Z
sensor.fems_produktion,5580,2024-08-13T15:42:24.056Z
sensor.fems_produktion,5557,2024-08-13T15:42:27.011Z
sensor.fems_produktion,5574,2024-08-13T15:42:30.013Z
sensor.fems_produktion,5559,2024-08-13T15:42:33.014Z
sensor.fems_produktion,5625,2024-08-13T15:42:36.013Z
sensor.fems_produktion,5610,2024-08-13T15:42:39.079Z
sensor.fems_produktion,5564,2024-08-13T15:42:42.012Z
sensor.fems_produktion,5593,2024-08-13T15:42:45.011Z
sensor.fems_produktion,5604,2024-08-13T15:42:48.013Z
sensor.fems_produktion,5644,2024-08-13T15:42:51.013Z
sensor.fems_produktion,5679,2024-08-13T15:42:54.071Z
sensor.fems_produktion,5713,2024-08-13T15:42:57.033Z
sensor.fems_produktion,5688,2024-08-13T15:43:00.034Z
sensor.fems_produktion,5698,2024-08-13T15:43:03.012Z
sensor.fems_produktion,5611,2024-08-13T15:43:06.015Z
sensor.fems_produktion,5641,2024-08-13T15:43:09.039Z
sensor.fems_produktion,5636,2024-08-13T15:43:12.006Z
sensor.fems_produktion,5612,2024-08-13T15:43:15.004Z
sensor.fems_produktion,5644,2024-08-13T15:43:18.003Z
sensor.fems_produktion,5666,2024-08-13T15:43:21.020Z
sensor.fems_produktion,5658,2024-08-13T15:43:24.005Z
sensor.fems_produktion,5632,2024-08-13T15:43:27.005Z
sensor.fems_produktion,5659,2024-08-13T15:43:30.009Z
sensor.fems_produktion,5624,2024-08-13T15:43:33.054Z
sensor.fems_produktion,5632,2024-08-13T15:43:36.018Z
sensor.fems_produktion,5587,2024-08-13T15:43:39.587Z
sensor.fems_produktion,5616,2024-08-13T15:43:42.010Z
sensor.fems_produktion,5565,2024-08-13T15:43:45.009Z
sensor.fems_produktion,5517,2024-08-13T15:43:48.059Z
sensor.fems_produktion,5485,2024-08-13T15:43:51.013Z
sensor.fems_produktion,5446,2024-08-13T15:43:54.029Z
sensor.fems_produktion,5435,2024-08-13T15:43:57.007Z
sensor.fems_produktion,5468,2024-08-13T15:44:00.009Z
sensor.fems_produktion,5496,2024-08-13T15:44:03.044Z
sensor.fems_produktion,5504,2024-08-13T15:44:06.020Z
sensor.fems_produktion,5507,2024-08-13T15:44:09.015Z
sensor.fems_produktion,5517,2024-08-13T15:44:12.011Z
sensor.fems_produktion,5503,2024-08-13T15:44:15.020Z
sensor.fems_produktion,5449,2024-08-13T15:44:18.065Z
sensor.fems_produktion,5463,2024-08-13T15:44:21.020Z
sensor.fems_produktion,5454,2024-08-13T15:44:24.013Z
sensor.fems_produktion,5399,2024-08-13T15:44:27.011Z
sensor.fems_produktion,5384,2024-08-13T15:44:30.015Z
sensor.fems_produktion,5392,2024-08-13T15:44:33.041Z
sensor.fems_produktion,5367,2024-08-13T15:44:36.012Z
sensor.fems_produktion,5336,2024-08-13T15:44:39.012Z
sensor.fems_produktion,5321,2024-08-13T15:44:42.013Z
sensor.fems_produktion,5282,2024-08-13T15:44:45.012Z
sensor.fems_produktion,5264,2024-08-13T15:44:48.051Z
sensor.fems_produktion,5227,2024-08-13T15:44:51.023Z
sensor.fems_produktion,5279,2024-08-13T15:44:54.007Z
sensor.fems_produktion,5321,2024-08-13T15:44:57.017Z
sensor.fems_produktion,5377,2024-08-13T15:45:00.009Z
sensor.fems_produktion,5446,2024-08-13T15:45:03.016Z
sensor.fems_produktion,5472,2024-08-13T15:45:06.010Z
sensor.fems_produktion,5453,2024-08-13T15:45:09.050Z
sensor.fems_produktion,5408,2024-08-13T15:45:12.010Z
sensor.fems_produktion,5367,2024-08-13T15:45:15.012Z
sensor.fems_produktion,5327,2024-08-13T15:45:18.018Z
sensor.fems_produktion,5318,2024-08-13T15:45:21.010Z
sensor.fems_produktion,5321,2024-08-13T15:45:24.098Z
sensor.fems_produktion,5381,2024-08-13T15:45:27.010Z
sensor.fems_produktion,5361,2024-08-13T15:45:30.013Z
sensor.fems_produktion,5346,2024-08-13T15:45:33.008Z
sensor.fems_produktion,5404,2024-08-13T15:45:36.010Z
sensor.fems_produktion,5418,2024-08-13T15:45:39.044Z
sensor.fems_produktion,5416,2024-08-13T15:45:42.012Z
sensor.fems_produktion,5449,2024-08-13T15:45:45.013Z
sensor.fems_produktion,5463,2024-08-13T15:45:48.020Z
sensor.fems_produktion,5455,2024-08-13T15:45:51.010Z
sensor.fems_produktion,5465,2024-08-13T15:45:54.047Z
sensor.fems_produktion,5475,2024-08-13T15:45:57.009Z
sensor.fems_produktion,5438,2024-08-13T15:46:00.009Z
sensor.fems_produktion,5474,2024-08-13T15:46:03.013Z
sensor.fems_produktion,5461,2024-08-13T15:46:06.009Z
sensor.fems_produktion,5433,2024-08-13T15:46:09.045Z
sensor.fems_produktion,5405,2024-08-13T15:46:12.011Z
sensor.fems_produktion,5414,2024-08-13T15:46:15.011Z
sensor.fems_produktion,5377,2024-08-13T15:46:18.018Z
sensor.fems_produktion,5368,2024-08-13T15:46:21.017Z
sensor.fems_produktion,5412,2024-08-13T15:46:24.079Z
sensor.fems_produktion,5459,2024-08-13T15:46:27.015Z
sensor.fems_produktion,5431,2024-08-13T15:46:30.032Z
sensor.fems_produktion,5439,2024-08-13T15:46:33.016Z
sensor.fems_produktion,5449,2024-08-13T15:46:36.011Z
sensor.fems_produktion,5434,2024-08-13T15:46:39.046Z
sensor.fems_produktion,5431,2024-08-13T15:46:42.011Z
sensor.fems_produktion,5402,2024-08-13T15:46:45.009Z
sensor.fems_produktion,5397,2024-08-13T15:46:48.010Z
sensor.fems_produktion,5378,2024-08-13T15:46:51.013Z
sensor.fems_produktion,5336,2024-08-13T15:46:54.047Z
sensor.fems_produktion,5249,2024-08-13T15:46:57.011Z
sensor.fems_produktion,5259,2024-08-13T15:47:00.011Z
sensor.fems_produktion,5213,2024-08-13T15:47:03.015Z
sensor.fems_produktion,5207,2024-08-13T15:47:06.012Z
sensor.fems_produktion,5225,2024-08-13T15:47:09.044Z
sensor.fems_produktion,5222,2024-08-13T15:47:12.012Z
sensor.fems_produktion,5230,2024-08-13T15:47:15.017Z
sensor.fems_produktion,5184,2024-08-13T15:47:21.011Z
sensor.fems_produktion,5221,2024-08-13T15:47:24.044Z
sensor.fems_produktion,5209,2024-08-13T15:47:27.013Z
sensor.fems_produktion,5176,2024-08-13T15:47:30.009Z
sensor.fems_produktion,5185,2024-08-13T15:47:33.012Z
sensor.fems_produktion,5191,2024-08-13T15:47:36.019Z
sensor.fems_produktion,5206,2024-08-13T15:47:39.045Z
sensor.fems_produktion,5213,2024-08-13T15:47:42.015Z
sensor.fems_produktion,5199,2024-08-13T15:47:45.009Z
sensor.fems_produktion,5169,2024-08-13T15:47:48.012Z
sensor.fems_produktion,5177,2024-08-13T15:47:51.015Z
sensor.fems_produktion,5169,2024-08-13T15:47:54.055Z
sensor.fems_produktion,5093,2024-08-13T15:47:57.008Z

(more than 10 minutes)

thank you so much for the quick responses again :open_mouth:

the binary sensor did not change, thats why i just pasted the one existing line in the csv

Have there been no updates to the template sensor since the 12th?

Check if you have multiple sensors named binary_sensor.pv_produktion_uber_4800_fur_10_minuten but ending with _2 or _3 etc. Also restart and then check your logs for any errors.

apparently there were no updates, i can restart again, i am checking available variables with the dev tools → states
the pv sensor is updated all 3 seconds using rest.

maybe it’s coming from that conversion?

    - name: "FEMS Produktion Summe"
      value_template: '{{value_json | selectattr("address", "equalto", "_sum/ProductionActiveEnergy") | map(attribute="value") | first }}'
      unit_of_measurement: "Wh"
      device_class: power
      state_class: measurement
      unique_id: "fems/_sum/ProductionActiveEnergy"

I don’t see how it is related to the definition of that sensor, did you mean to paste the config for FEMS Produktion instead of FEMS Produktion Summe ?

Unrelated, but the device_class of that sensor should be energy instead of power. You should see errors in your logs about that.

Which makes me wonder if you have other errors you are ignoring as well?

Thanks, that’s correct indeet. I just refered to it as I wasn’t sure if the state_class etc . might be relevant when casting.
however, i looked at the logs; today morning when i tested a little bit, there was an error for the template, but that was due to sorting it out into a templates.yaml. when i reboot now, i don’t get any errors etc.
i also tried leaving away the “delay_on” and also changed the minutes from “0:10:00” to `minutes: 2" e.g. It seems to work when i leave it away (so it changes instantly when the value sinks below or raises above the compared value; does the delay_on maybe only work with static states (like “on” or “5” for a time, and if the value changes again, the delay begins again?)

this is the code right now:

    - name: "FEMS Current PV Produktion"
      value_template: '{{value_json | selectattr("address", "equalto", "_sum/ProductionActivePower") | map(attribute="value") | first }}'
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "fems/_sum/ProductionActivePower"

and

templates.yaml

- trigger:
    - platform: state
      entity_id: sensor.fems_produktion
      not_to:
        - unavailable
        - unknown
  binary_sensor:
    - name: TMPTEST
      state: "{{ trigger.to_state.state | float(0) > 1000 }}"
      delay_on:
        minutes: 2

The state of a binary sensor can only be on or off and the output of the template you’re using can only be true or false which will make the sensor on or off respectively. This is documented here.

All that to say having a state template render true every 3 seconds does not have any impact on the delay_on behavior.

i tested it; without the delay on it’s exactly what it’s supposed to do (see image).
after adding delay_on with 20 seconds, it does not trigger anymore
I just added the last line (delay on) at the red arrow… the green line shows 3000 watt production. the blue arrow shows a point where it should have turned to “on” after 20 secs.

- trigger:
    - platform: state
      entity_id: sensor.fems_produktion
      not_to:
        - unavailable
        - unknown
  binary_sensor:
    - name: TESTTMP
      state: "{{ trigger.to_state.state | float(0) > 3000 }}"
      delay_on: "00:00:20"

do you have any more ideas? im clueless :frowning:

i found out, that trigger may not be used together with delay_on for binary_sensor. i deleted the trigger, and only left the binary sensor part. it now works as intended . thanks for all the help!