Numeric state automation help

Hi,
Looking for some help with getting an automation working. Fairly new to HA and very new to automation - this is my first.

I am trying to get a plug to switch on when the grid power in the house goes below a certain value and turn off agin when it goes above a different higher value. The ultimate goal is to make certain sockets turn on when the solar array is generating a lot of energy and off when it isn’t. However it’s dark while I try to do this so simulating with much higher values and turning electrical devices on or off to get the grid power to pass above and below a fixed value. I can get the automation to work using a time trigger but not a numeric state trigger so any help would be greatly appreciated.

I used the automations UI to do add the two automations for on and off and below is what it put in my automations.yaml

- id: '1669239228833'
  alias: Excess Solar On
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.grid_power
    attribute: ''
    below: '600'
  condition:
  - condition: device
    type: is_off
    device_id: 015443524065e6186d76671b7f51bd08
    entity_id: switch.tapo_1
    domain: switch
  action:
  - type: turn_on
    device_id: 015443524065e6186d76671b7f51bd08
    entity_id: switch.tapo_1
    domain: switch
  mode: single
- id: '1669239668783'
  alias: Excess Solar Off
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.grid_power
    above: '600'
  condition:
  - condition: device
    type: is_on
    device_id: 015443524065e6186d76671b7f51bd08
    entity_id: switch.tapo_1
    domain: switch
  action:
  - type: turn_off
    device_id: 015443524065e6186d76671b7f51bd08
    entity_id: switch.tapo_1
    domain: switch
  mode: single

Thanks for any help you can provide with this. Hopefully I have just misunderstood how this works and it’s easy to fix.

Remove this line:

    attribute: ''
1 Like

Thank you so much. Can’t believe it was that simple.

Working perfectly now.

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title signaling to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.


NOTE

If you are interested in learning how to consolidate the two automations, here’s an example of one way to do it:

- id: 'excess_solar'
  alias: Excess Solar
  description: ''
  trigger:
  - id: 'on'
    platform: numeric_state
    entity_id: sensor.grid_power
    below: 600
    variables:
      switch_state: "{{ is_state('switch.tapo_1', 'off') }}"
  - id: 'off'
    platform: numeric_state
    entity_id: sensor.grid_power
    above: 600
    variables:
      switch_state: "{{ is_state('switch.tapo_1', 'on') }}"
  condition:
  - condition: template
    value_template: "{{ switch_state }}"
  action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.tapo_1
  mode: single