Automating going off-grid

I’m trying to create an automation that will monitor for solar production between 1755 and 2101. If/when production drops below 3kW then go off grid.

I have an automation that goes off grid at 1758 if production is below 3kW, but it doesn’t roll. I’d like the new automation to allow for the grid connection to stay active while production is above 3kW.

This is my current attempt, but it doesn’t work and I’m not sure why. any pointers would be greatly appreciated.

alias: Rolling Off Grid below 3000W production Weekdays
description: Go off grid after between 1755 and 2101 if solar production is under 3000W.
triggers:
  - trigger: numeric_state
    entity_id: sensor.home_gateway_solar_power
    below: 3000
    for:
      hours: 0
      minutes: 5
      seconds: 0
conditions:
  - condition: time
    after: "17:55:00"
    before: "21:01:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  - condition: device
    type: is_off
    device_id: 1a9ca0580383ea6516516b29b6d3c72a
    entity_id: 0084bdf48e3ec9322cbd9525ff53b291
    domain: switch
actions:
  - type: turn_on
    device_id: 1a9ca0580383ea6516516b29b6d3c72a
    entity_id: 0084bdf48e3ec9322cbd9525ff53b291
    domain: switch
  - action: notify.mobile_app_turtle_s_max
    metadata: {}
    data:
      message: Solar production below 3kW, going off grid!
mode: single

For reference, this is my automation that checks at 1758 and goes off is below 3kW.

alias: Off grid below 3000kW weekdays
description: Go off grid after 1758 if solar production is under 3000kW.
triggers:
  - at: "17:58:00"
    trigger: time
conditions:
  - type: is_power
    condition: device
    device_id: 1a9ca0580383ea6516516b29b6d3c72a
    entity_id: 454f0f232d8916201880c7fd107ed9b9
    domain: sensor
    below: 3000
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  - condition: device
    type: is_off
    device_id: 1a9ca0580383ea6516516b29b6d3c72a
    entity_id: 0084bdf48e3ec9322cbd9525ff53b291
    domain: switch
actions:
  - type: turn_on
    device_id: 1a9ca0580383ea6516516b29b6d3c72a
    entity_id: 0084bdf48e3ec9322cbd9525ff53b291
    domain: switch
  - metadata: {}
    data:
      message: Solar production below 3kW, going off grid!
    action: notify.mobile_app_turtle_s_max
mode: single

Ultimately the reason for the switch is summer is coming and I would like to be able to send surplus solar to the grid in the early evening while I still have solid production. No need to go off grid and “lose” the generation for a few hours just because I don’t want to consume anything during peak energy cost.

I just had a revelation, I wonder if it is because the entity is set for kW as its unit of measure. Maybe I need to set my value to “3” instead of “3000”.

Edit: Scratch that thought. It works as expected with the time based automation.

Looks like I was on the right track with setting the value to “3” instead of 3000. I created a whole new test automation and was able to have it trigger when total solar production hit 3kW with this:

alias: Test Gateway Power below 3
description: ""
triggers:
  - type: power
    device_id: 1a9ca0580383ea6516516b29b6d3c72a
    entity_id: 454f0f232d8916201880c7fd107ed9b9
    domain: sensor
    trigger: device
    below: 3
    for:
      hours: 0
      minutes: 5
      seconds: 0
conditions:
  - condition: time
    after: "16:00:00"
    before: "21:01:00"
actions:
  - action: notify.mobile_app_turtle_s_max
    metadata: {}
    data:
      message: Test Gateway Power below 3 after 1600.
mode: single

Here is the resulting trace from this test, specifically the “Changed Variables” section:

this:
  entity_id: automation.test_gateway_power_below_3
  state: 'on'
  attributes:
    id: '1738978499596'
    last_triggered: '2025-02-08T21:25:37.639462+00:00'
    mode: single
    current: 0
    friendly_name: Test Gateway Power below 3
  last_changed: '2025-02-09T01:47:31.359996+00:00'
  last_reported: '2025-02-09T01:47:31.359996+00:00'
  last_updated: '2025-02-09T01:47:31.359996+00:00'
  context:
    id: 01JKM67W4ZNVPNXJMAQHT8KGJF
    parent_id: null
    user_id: null
trigger:
  id: '0'
  idx: '0'
  alias: null
  platform: device
  entity_id: sensor.home_gateway_solar_power
  below: 3
  above: null
  from_state:
    entity_id: sensor.home_gateway_solar_power
    state: '3.004'
    attributes:
      state_class: measurement
      unit_of_measurement: kW
      device_class: power
      friendly_name: Solar Production (Power)
    last_changed: '2025-02-09T21:19:15.659338+00:00'
    last_reported: '2025-02-09T21:19:15.659338+00:00'
    last_updated: '2025-02-09T21:19:15.659338+00:00'
    context:
      id: 01JKP99CPBBD069F9R7SNRGPCY
      parent_id: null
      user_id: null
  to_state:
    entity_id: sensor.home_gateway_solar_power
    state: '2.948'
    attributes:
      state_class: measurement
      unit_of_measurement: kW
      device_class: power
      friendly_name: Solar Production (Power)
    last_changed: '2025-02-09T21:19:45.627507+00:00'
    last_reported: '2025-02-09T21:19:45.627507+00:00'
    last_updated: '2025-02-09T21:19:45.627507+00:00'
    context:
      id: 01JKP9A9YV52HHVHG0X98KKM55
      parent_id: null
      user_id: null
  for:
    __type: <class 'datetime.timedelta'>
    total_seconds: 300
  description: numeric state of sensor.home_gateway_solar_power

I’ll build from here and accomplish my goal. I’ve been adding the conditions I want now that I’m getting the notifications. Once I have the conditions set, I’ll add the finally action of switching the status to off-grid.