
- id: 'solar_pool_pump_early_start'
  alias: Solar Pool Pump - Early Start
  description: >
    Turns pool pump on before 10am when solar is exporting enough to cover it (3.5kW buffer).
    Respects battery SOC minimum. Existing schedule handles the 10am guaranteed start.
  triggers:
    - trigger: numeric_state
      entity_id: sensor.grid_boss_4434850618_grid_power
      below: -3500
      for:
        minutes: 3
  conditions:
    - condition: state
      entity_id: switch.pool_pump_socket_1
      state: 'off'
    - condition: time
      after: '06:00:00'
      before: '10:00:00'
    - condition: sun
      after: sunrise
    - condition: numeric_state
      entity_id: sensor.eg4_battery_soc_voltage
      above: 20
  actions:
    - action: switch.turn_on
      target:
        entity_id: switch.pool_pump_socket_1
    - action: notify.mobile_app_chad
      continue_on_error: true
      data:
        title: "☀️ Pool Pump - Solar Start"
        message: >
          Solar exporting {{ states('sensor.grid_boss_4434850618_grid_power') | float | abs | round(0) }}W.
          Pool pump started early on solar power.
  mode: single

- id: 'solar_pool_pump_early_stop'
  alias: Solar Pool Pump - Solar Dropout Stop
  description: >
    Turns pump off when solar drops and grid starts importing (pump running on grid/battery).
    20-minute minimum runtime guard to protect pump motor from short-cycling.
  triggers:
    - trigger: numeric_state
      entity_id: sensor.grid_boss_4434850618_grid_power
      above: 300
      for:
        minutes: 4
  conditions:
    - condition: state
      entity_id: switch.pool_pump_socket_1
      state: 'on'
    - condition: template
      value_template: >
        {{ (now() - states.switch.pool_pump_socket_1.last_changed).total_seconds() > 1200 }}
    - condition: time
      before: '20:00:00'
  actions:
    - action: switch.turn_off
      target:
        entity_id: switch.pool_pump_socket_1
    - action: notify.mobile_app_chad
      continue_on_error: true
      data:
        title: "🌥️ Pool Pump - Solar Dropout"
        message: >
          Grid now importing {{ states('sensor.grid_boss_4434850618_grid_power') | float | round(0) }}W.
          Pool pump stopped to avoid running on grid/battery.
  mode: single
