Help with Solar/Utility/Load Automation

Hello.

I need help with making an automation.

I have an Inverter with Solar Panels connected to my Home Assistant

I also have a Tuya breaker switch on the grid (utility) line into the inverter, also connected to the Home Assistant

I want an automation that turns the grid switch on when the load is greater than the Solar production

and off when the Solar production is greater than the load.

with a delay of 2 Minutes to account for cloud events

This is due to the limitations of my Inverter.

Load entitty = sensor.srne_v2_load_power
Solar entity = sensor.srne_v2_pv_power
Grid Switch = switch.grid_meter_none

You would need to use the automation UI to write this.
This is not an AI or a service that scratch writes automations for you, sorry.

Write something, troubleshoot it, and then if something doesn’t work you can come back with that and you may get some help. I say may because it you plug that into an AI and come back with AI Gibberish, that is usually recognized and often little to no help can be provided.

thank you.

i tried and it wasn’t apparent to me that i could achieve it using the UI, so i thought it could only be done writing a yaml, which i can’t do.

what i tried in the UI was create 2 automations (because i don’t understand how to have multiple WHEN triggers)

these are their yaml.

id: '1719040776965'
alias: PV UP+Grid Off
description: Turns off Grid when PV crosses 300w
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.srne_v2_pv_power
    for:
      hours: 0
      minutes: 2
      seconds: 0
    above: 300
condition: []
action:
  - type: turn_off
    device_id: 0efd556fd883891fa6802c8b4f99697a
    entity_id: 5206cb6aeb522cdc9c093e39fba38061
    domain: switch
mode: restart
id: '1719041685322'
alias: PV DOWN + Grid On
description: Turns on Grid when PV drops below 300w
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.srne_v2_pv_power
    for:
      hours: 0
      minutes: 2
      seconds: 0
    below: 300
condition:
  - condition: numeric_state
    entity_id: sensor.srne_v2_load_power
    above: 300
action:
  - type: turn_on
    device_id: 0efd556fd883891fa6802c8b4f99697a
    entity_id: 5206cb6aeb522cdc9c093e39fba38061
    domain: switch
mode: restart

as far as i can tell they only triggered once all day, and the one to turn on the grid did not work at all in the evening when the sun went down. (also because i have load shedding and its possible that the grid was out when its supposed to trigger)

but it never did even when grid was restored and there was no solar at all

when i trigger them manually they execute the switching.

is it not possible to have both scenarios in one automation that checks the states at intervals and triggers

You use this (choose) when picking multiple branches.
Script Syntax - Home Assistant.
It is available in the UI.

Unfortunately i’m probably the most clueless person that ever posted on this site

i have no idea where this is

start by sketching out on paper in a flow chart the things you want to do.

  • When X happens do that
  • When y happens do this
  • Wnen Z = this and Y is less than that, then do the other

Then look at the UI, there will be places to put these things.
Start simple, with 1 When (trigger) and 1 Then Do (Action)
When you get that going, start to add things to it and test as you go.

The statement above will trigger when the load power is below 300 for 2.00 but then the And If (condition) statement says the load power has to be above 300, This can’t happen so that can never get to Then Do (actions) because logically it cannot.

Do a flowchart, start the simplest building block, test and add building blocks.

A hint, sometimes you cannot fake the trigger point, so you create a helper entity and plug that in to use for testing your logic.

1 Like

Just to check: you don’t have batteries, right?

What happens today if you don’t turn on the grid feed?

Even if you can get an automation to logically be correct, I’m worried that flipping the switch won’t be fast enough. Grid-tied systems typically have an AC clamp and the system is grid synced. It needs to respond in under 20 ms to prevent your power from tripping when switching over.

I do have batteries.

Just trying to not use the grid when there’s sufficient solar.

its a feature with some inverters but not this particular model i have so i figure i could use the switch and Home Assistant automation. kinda crude but fine i guess

Right, that changes my understanding.

Do you have a sensor for your battery’s charge (SOC)?

When you want to perform this switchover, is your battery typically full?

Does your inverter prioritise grid over solar, and its not something you can change?

The reason for all my question is that I may have other suggestions too.

It’s under the action block (then do).

Do you have a sensor for your battery’s charge (SOC)?

Yes

When you want to perform this switchover, is your battery typically full?

When its higher than 60%

Thats the minimum SOC that gets me through the night

i have switched to charging the batteries with solar only

Does your inverter prioritise grid over solar, and its not something you can change?

Yes. This is the problem

it only has output modes that prioritize grid when its on

I cannot give you all the UI steps and I don’t know if you can do this without the use of templates, but here’s one version:

  - alias: "Control Grid Feed"
    trigger:
      - platform: template
        value_template: >-
          {% set load = states('sensor.srne_v2_load_power') | int(0) %}
          {% set solar = states('sensor.srne_v2_pv_power') | int(0) %}
          {{ load > solar }}
        for:
          minutes: 2
        id: "on"
      - platform: template
        value_template: >-
          {% set load = states('sensor.srne_v2_load_power') | int(0) %}
          {% set solar = states('sensor.srne_v2_pv_power') | int(0) %}
          {{ load <= solar }}
        for:
          minutes: 2
        id: "off"
    action:
      - service: "switch.turn_{{ trigger.id }}"
        target:
          entity_id: switch.grid_meter_none

Thank you very much

I think this put me on the path with templates