Switching on battery if solar output is less than 100 w for at least 15 mins

I have this automation. It’s pretty stupid actually. Starting from 4pm, it checks every 15 mins if the solar output is less than 100 W. If so it enables the discharge of my solar battery to take over for the night. However I’m now searching for a smart way to check if the value is less than 100W at least for 15 mins. Even ChatGpt cannot help here as it suggesting using a for which doesn’t seem to be available.

Can anybody help?
Thanks

alias: "Anker: Discharge am Abend"
description: ""
triggers:
  - minutes: /15
    trigger: time_pattern
conditions:
  - condition: time
    after: "18:00:00"
    before: "21:00:00"
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.solarbank_e1600_mode
        state: discharge
  - condition: numeric_state
    entity_id: sensor.solarbank_e1600_solar_power
    below: 100
  - condition: numeric_state
    entity_id: sensor.solarbank_e1600_state_of_charge
    above: 30
actions:
  - action: script.battery_priority
    data: {}
  - data:
      title: Solarstrom zu niedrig
      message: Schalte Batterie auf discharge um.
    action: notify.all_phones
mode: single


What do you mean when you say for is not available?

triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.solarbank_e1600_solar_power
    for:
      hours: 0
      minutes: 15
      seconds: 0
    below: 100

No need to check every 15 minutes.

An alternative approach might be to define a threshold helper based on sensor.solarbank_e1600_solar_power, then your trigger entity would just be on or off.

1 Like

This is a trigger (numeric state)which accepts for:

This is a condition (time)

Basically, your current automation is triggering 96 times a day unnecessarily. Replace your trigger with @jackjourneyman’s suggestion and all should be fine

ok…

So I changed it to this, now my question is (and yes this is a n00b question): Let’s say it triggers at 4pm, it will not run the action, as condition is not met, where i check time must be after 6pm. Will it trigger again at 6pm?

alias: "Anker: Discharge am Abend"
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.solarbank_e1600_solar_power
    for:
      hours: 0
      minutes: 15
      seconds: 0
    below: 100
conditions:
  - condition: time
    after: "18:00:00"
    before: "21:00:00"
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.solarbank_e1600_mode
        state: discharge
  - condition: numeric_state
    entity_id: sensor.solarbank_e1600_state_of_charge
    above: 30
actions:
  - action: script.battery_priority
    data: {}
  - data:
      title: Solarstrom zu niedrig
      message: Schalte Batterie auf discharge um.
    action: notify.all_phones
mode: single

but if the value is going < 100 at 5 and not going > 100 again, it will not trigger again at 6pm and therefor it will never actually trigger the action correct?

Good question - no, it won’t.

To deal with that you could have a second automation triggered by the time (6pm), with battery level as a condition.

If that achieves what you want, you could combine the two into a single automation with two triggers, 6pm and battery state, and a choose action depending on which has fired.

Edit: For example:

triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.solarbank_e1600_solar_power
    for:
      hours: 0
      minutes: 15
      seconds: 0
    below: 100
    id: Battery low
  - trigger: time
    at: "18:00:00"
    id: 6pm
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Battery low
          - condition: time
            after: "18:00:00"
        sequence: 
# Add actions here...
      - conditions:
          - condition: trigger
            id:
              - 6pm
          - condition: numeric_state
            entity_id: sensor.solarbank_e1600_solar_power
            below: 100
        sequence: 
# Add actions here...
1 Like

I think I solved it in a pretty stupid way, but I think it should work like that.

Sensor:

binary_sensor:
  - platform: template
    sensors:
      solar_power_low:
        friendly_name: "Solar Power Low"
        value_template: "{{ states('sensor.solarbank_e1600_solar_power') | float < 100 }}"

And automation:

alias: "Anker: Discharge am Abend"
description: ""
trigger:
  - platform: time_pattern
    minutes: "/15"
condition:
  - condition: time
    after: "18:00:00"
    before: "21:00:00"
  - condition: state
    entity_id: binary_sensor.solar_power_low
    state: "on"
  - condition: template
    value_template: "{{ (now() - states.binary_sensor.solar_power_low.last_changed).total_seconds() >= 900 }}"
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.solarbank_e1600_mode
        state: "discharge"
  - condition: numeric_state
    entity_id: sensor.solarbank_e1600_state_of_charge
    above: 30
action:
  - action: script.battery_priority
    data: {}
  - data:
      title: "Solarstrom zu niedrig"
      message: "Schalte Batterie auf discharge um."
    action: notify.all_phones
mode: single

WDTY?