Solar power, 1 automation for on/off, 2 num. value triggers: the 'right' way?

I have this automation and am aware that the triggers only execute when the value thresholds are crossed.
I know that using 2 separate automations would make it easier but I’m bending my head, searched, on how to achieve this in 1 automation.

This is what I have now, the value changes every 5 minutes and the idea was to switch only if the threshold is above/below during 15minutes but maybe that’s not a good idea.

alias: "Pool: pump"
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.solaredge_i1_ac_power
    for:
      hours: 0
      minutes: 15
      seconds: 0
    above: 1000
    id: solar+1000
  - platform: numeric_state
    entity_id:
      - sensor.solaredge_i1_ac_power
    id: solar-1000
    below: "1000"
    for:
      hours: 0
      minutes: 15
      seconds: 0
condition: []
action:
  - if:
      - condition: trigger
        id:
          - solar-1000
    then:
      - service: switch.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: switch.relay14
  - if:
      - condition: trigger
        id:
          - solar+1000
    then:
      - service: switch.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: switch.relay14
mode: single

How would the pro’s do this?
TIA

Not sure if I would call myself pro, but this is what I would do:

alias: "Pool: pump"
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.solaredge_i1_ac_power
    for:
      minutes: 15
    above: 1000
    id: "on"
  - platform: numeric_state
    entity_id: sensor.solaredge_i1_ac_power
    id: "off"
    below: "1000"
    for:
      minutes: 15
condition: []
action:
  - service: "switch.turn_{{ trigger.id }}"
    metadata: {}
    data: {}
    target:
      entity_id: switch.relay14
mode: single
1 Like

Hi, thanks for jumping in!
The solution with the action is :+1:

I wonder if, in this case with solar power and powering an electrical motor, these triggers and the way implemented - with that delay - is right (the ‘best’ way).

It’s more like a timer than merely a delay. The sensor’s value must remain above the threshold value for a minimum of 15 minutes in order to trigger.

Think of it as a 15 minute timer that is started the moment the sensor’s value rises above 1000. If the value decreases below 1000 during the 15 minute countdown, the timer is canceled. If the value remains above 1000 throughout the 15 minute countdown, the timer finishes and the trigger occurs.


FWIW, given that both triggers use the same values for above/below and for, you can combine them into a single trigger. The service call’s template determines the action (on or off) based on if trigger.to_state.state is above 1000.

1 Like

We can’t possibly answer this.
All we knew was you wanted to run whatever load is on relay 14 with the sun.
Now you say it’s a motor, but that is as much as we know.

Hi, you have a point and I assumed that “Pool: pump” would make it clear that it’s a motor that is switched.
I guess that it’s not a good idea to switch it on & off in a short timeframe so that’s 1 thing I’m not sure of.
Then, I also wonder how others are automating stuff with solar panels.

Thank you for clarifying that Taras!

That is indeed a neater solution
I did this without much thinking but maybe, in this case, it’s not the best option to do it that way.

Guys, I’m struggling to get it to work as desired.
The automation basically does what I requested here, but…

The goal is to make the filter run for 8h per day; so not switch off if this is not reached because solar power drops below 1000 in the meantime.
I have created a timer which starts when the automation triggers to switch on.
How do I make it such that when this goal is not reached, not to switch off yet and do so when the timer has reached that limit?

TIA

This is an more or less impossible task.
If the solar power goes above 1000 at 7 in the morning then the timer starts.
And it keeps the pump running for 8 hours but the clouds might roll in at 7:30.
Then the clouds break up in the afternoon so you have had the pump running while it was cloudy and running from the grid.

You might need to look at solar forecast