Best way to automate 3 switches depending on sensor data

Tags: #<Tag:0x00007fc3eded9320>

Hi. I eventually managed to get the data from my inverter and when I am exporting power to the grid switch on/off three heaters to use the solar production. However it’s not the most elegant solution and doesn’t quite work the way I would like it to and I can’t seem to get it to do what I want using the automation GUI. So just asking the brains trust here what you think would be the best way to go about it.

Scenario is:
When exporting to grid >1000 turn on switch1 (1000w) heater
when exporting to grid another 1000 (total available solar production = 2000) turn off switch 1, turn on switch 2 (2000w heater)
when exporting another 1000 turn switch 1 on again (solar production 3000w)
another 1000. switch 1 off, switch 3 on (2000w heater) (solar production 4000w)
finally, another 1000 and switch 1 on (solar production 5000w)

and turn them off in the reverse order.

I’ve got it kinda working except for the bit when export is between 1000 and 2000
automation.yaml below

- id: '1627917436517'
  alias: bedroom heater
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.fronius_grid_export
    id: exporting
    above: '1000'
  action:
  - service: switch.turn_on
    target:
      device_id: 037cf4f9ac9daa817db6d2a7e499b43f
  mode: single
- id: '1627979956806'
  alias: bedroom heater off
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.fronius_grid_export
    below: '1'
    id: not exportin enough
  condition:
  - condition: numeric_state
    entity_id: sensor.fronius_grid_use
    above: '1'
  action:
  - service: switch.turn_off
    target:
      device_id: 037cf4f9ac9daa817db6d2a7e499b43f
  mode: single
- id: '1627982634622'
  alias: living1 heater
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.fronius_grid_export
    above: '2000'
  condition:
  - condition: device
    type: is_on
    device_id: 037cf4f9ac9daa817db6d2a7e499b43f
    entity_id: switch.bedroom
    domain: switch
  action:
  - service: switch.turn_on
    target:
      device_id: bca5e632d266af95a3d53a24d7c7b5a8
  mode: single
- id: '1627985120953'
  alias: living2 heater
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.fronius_grid_export
    above: '2000'
  condition:
  - condition: device
    type: is_on
    device_id: bca5e632d266af95a3d53a24d7c7b5a8
    entity_id: switch.living_1
    domain: switch
  action:
  - service: switch.turn_on
    target:
      device_id: db623dcf0042a1d11ff64baaaf16ae4f
  mode: single
- id: '1627986966020'
  alias: living1 heater off
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.fronius_grid_export
    below: '1'
  condition:
  - condition: numeric_state
    entity_id: sensor.fronius_grid_export
    below: '1'
  action:
  - service: switch.turn_off
    target:
      device_id: bca5e632d266af95a3d53a24d7c7b5a8
  mode: single
- id: '1627987108667'
  alias: living2 off
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.fronius_grid_export
    below: '1'
  condition: []
  action:
  - service: switch.turn_off
    target:
      device_id:
      - db623dcf0042a1d11ff64baaaf16ae4f
  mode: single
'''
As you can see, not the most elegant and i'm sure there is a better way, but I am not sure if it should be by scripts, templates, if else esleif or what. Any advice most welcome.

You already have a topic on this. Why open another one?

Sorry, I solved half of the initial issue, getting the sensors to work and the automation is mostly working, I thought it was enough of a different issue to post.