Swith on smart plug when solar excess > smart plug power

I have a smart plug that I can switch off and on.
The smart plug also reports the consumed power.
I also have a home energy meter that will report excess solar power returned to the grid.
I want to make an automation that will switch on the plug when there’s excess solar power and switch it off otherwise.

here’s my trial:

- alias: Solar Excess Smart Plug
  trigger:
      - platform: sun
        event: sunrise
  condition:
      - condition: numeric_state
        entity_id: sensor.grid_return_power
        above: 0
  action:
      action: >
        {% if states('sensor.grid_return_power') | float > 0 %}
          switch.turn_on
        {% else %}
          switch.turn_off
        {% endif %}
      target:
        device_id:
          - 97434adc00b9b29f11bbf385f366bc18

but I get this error:
Automation with alias 'Solar Excess Smart Plug' could not be validated and has been disabled: Unable to determine action @ data['action'][0]. Got None

Can someone help me on the syntax, please ?

Hi carkin,

Device stuff does not work in most cases with templates. Use an entity instead.

Why and how to avoid device_ids in automations and scripts.

thanks Sir_Goodenough,

that helped a bit but looks like I also need to modify the other action properties:

    action:
      - service: >
          {% if states('sensor.grid_return_power') | float > 0 %}
            switch.turn_on
          {% else %}
            switch.turn_off
          {% endif %}
        entity_id:
           - switch.smart_plug_xxx