Power flow as a trigger for an automation

I would like to use my Solar inverter power flow as a trigger to turn on (and off) my EV charger.

For example:-
Something like this? (to turn on when power to grid reaches above 2000W)

- id: '1638656798449'
  alias: EV Charger on Solar
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.power_grid_fronius_power_flow_system_http_10_1_1_3
    attribute: unit_of_measurement
    to: '>-2000'
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  condition:
  - condition: time
    before: '18:00:00'
    after: 08:00:00
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.ev_charger
  mode: single

Use a Numeric State trigger instead of State trigger, that will give you the above/below options.

- id: '1638656798449'
  alias: EV Charger on Solar
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.power_grid_fronius_power_flow_system_http_10_1_1_3
    below: -2000
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  condition:
  - condition: time
    before: '18:00:00'
    after: '08:00:00'
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.ev_charger
  mode: single

EDIT: Removed attribute from trigger and corrected for negative value

Thanks, that makes sense to me but considering that power flow to the grid shows as
a negative numeric value, should I have
above: 2000
or
above: -2000
or
below: 2000
or
below: -2000

I have tried all 4 options and following a restart the switch does not turn on.
I have also tried without the time condition.

I have just read more about automation triggers…
“Fires when the numeric value of an entity’s state crosses (and only when crossing) a given threshold.”

So more playing required

In your case - is “to grid”. The value would have to have been above -2000 before and then cross the limit for a below: -2000 to trigger. I think a HA restart wouldn’t trigger this.

I would add some hysteresis instead of a timer in the ON condition.
So when the charger uses 2kW start it eg. at -2200 immediatly and stop it on above: 0. To avoid too short on-off cycles add some minimum ON time.

Sorry, I just noticed that I hadn’t erased the “unit of measurement” attribute line from your original post, and that’s not what we need to use… its value will always be “W”.

Assuming the state of the sensor is current value, and you are looking to trigger on when that value is more negative than -2000, then the following should be your trigger:

- platform: numeric_state
  entity_id: sensor.power_grid_fronius_power_flow_system_http_10_1_1_3
  below: -2000
  for: "00:05:00"

Yes I have on at below: -2000
and off at above: -100

Ah, this explains why my test automations sending an email worked (without that line)
I did not notice the difference.

I have to go to work now so I will see what happens today.

Thanks for the help guys. I now have my EV charger switched on (and off) for “night rate power” and during the day switched on (and off) by the level of solar “power flow”.
I will document below my automations.yaml section to hopefully help others.

- id: '1638656798449'
  alias: EV Charger on Solar
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.power_grid_fronius_power_flow_system_http_10_1_1_3
    for:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
    below: '-2000'
  condition:
  - condition: time
    after: 07:15:00
    before: '21:15:00'
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.ev_charger
  mode: single
- id: '1638848258276'
  alias: EV Charger off Solar
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.power_grid_fronius_power_flow_system_http_10_1_1_3
    for: 
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
    above: '-100'
  condition:
  - condition: time
    before: '21:15:00'
    after: 07:15:00
  action:
  - service: switch.turn_off
    target:
      entity_id: switch.ev_charger
  mode: single

Hello!
i want to use the same setup but the automation trigger does not work.
I also tried ist with „above: 2000“ and also with Numbers under 1.000 (in case the dot in 2.000 Watt causes the problem).

Does anyone has an idea what the problem is?
I‘m running the latest homeassistant OS on Raspi 4.


alias: Auto laden ab 2100 W
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.sb5_0_1av_41_783_grid_power
    for:
      hours: 0
      minutes: 0
      seconds: 10
    attribute: ""
    below: -2000
condition: []
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.wallboxpulsar_charge_control
    enabled: true
mode: single

Remove that line.

Hello @mobile.andrew.jones, thanks for your reply! Unfortunatelly, nothing has changed.

Here is a screenshot of my setup. My PV Power was 30 minutes above 2.100 but the automation was never activated. I don’t know what I’m missing :neutral_face:

Some more Information:
Home Assistant 2022.9.2
Supervisor 2022.08.6
Operating System 8.5
Frontend 20220907.0 - latest

Integrations:

  • SMA Solar (to see PV Power)
  • Open Charge Point Protocol /OCPP (to turn on my wallbox)

Below is from my automations.yaml for an automation created from the GUI.
(Also above I sent another working section on Dec 21 which has the same syntax as my new one)
It looks to me like your formatting or syntax or whatever it is called is different. (Note the spaces at the beginning of each line. E.G. 2 spaces before alias, 4 spaces before entity )
You could try editing yours manually but why not try creating it in the settings > automations GUI?

- id: '1662686217958'
  alias: Towels on Solar
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.power_grid_fronius_power_flow_0_http_10_1_1_3
    below: -2700
  condition: []
  action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
      - switch.towel_high
      - switch.towel_low
      - switch.towel_north
      - switch.towel_west
  mode: single
1 Like

Also your screen shot is, I believe, showing 2429W of PV power which is not the same sensor you are using for the automation.
The automation using Grid Power will be a negative number if exporting to the grid. I do not know German but if you add the Grid Power sensor ( sensor.sb5_0_1av_41_783_grid_power) to your Home page you might see another reason why it may not be triggered yet.

Hello @robfish,

thanks for the answer. I created this automation via gui. Above is only the yaml view, to have a better overview. Also the sensor “sensor.sb5_0_1av_41_783_grid_power” ist correct. Its the same as PV-Leistung (PV-Power) in the Gui. I checked the spaces and everthing is correct and removed the time condition (to have exactly your setup). But it doesn’t work.

Could you tell me, what a value your PV Sensor shows? Is it possible that the Problem is the Value (the dot above 1.000 W oder have i add the W)?

I have a few sensors on my home page.
My PV Power one (at 7am today) shows 300W
My Grid Power shows 1,800W which means I am drawing power from the grid.
When I am exporting to the grid my Grid Power shows up to -4,500W
Unless your Grid Power gets below your threshold your automation will not trigger.

Your screen shot showed PV Power which, when your load is subtracted, would not leave enough exported to trigger your automation.
Try adding , Grid Power to your home page. (I really don’t believe, as you stated, that your Grid Power is the same as your PV Power)

Ok, thank you! I think this was a misunderstanding. I only get one Value from my PV Converter and this is the grid Power Sensor. I think i misunderstood your setup, sorry!
However, i change the value from below -2100 to above 2100. This was not working before the last update (in my memory) but now it works as expected.

I also added a condition, that the wallbox switch have to be off. At the moment i try to test a second condition (that the wallbox status have to be “Preparing”). If the wallbox is not in Preparing mode, no Car is connected. In the setup below this condition is deactivated.

alias: Wallbox aktivieren ab 2100 W
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.sb5_0_1av_41_783_grid_power
    for:
      hours: 0
      minutes: 0
      seconds: 10
    above: 2100
condition:
  - condition: device
    type: is_off
    device_id: 9de57aa73ccc29a1ebd77c4c5a666eec
    entity_id: switch.wallboxpulsar_charge_control
    domain: switch
  - condition: state
    entity_id: sensor.wallboxpulsar_status_connector
    state: Preparing
    enabled: false
action:
  - device_id: 9de57aa73ccc29a1ebd77c4c5a666eec
    domain: number
    entity_id: number.wallboxpulsar_maximum_current
    type: set_value
    value: 6
  - type: turn_on
    device_id: 9de57aa73ccc29a1ebd77c4c5a666eec
    entity_id: switch.wallboxpulsar_charge_control
    domain: switch
mode: single

Here is also my second automation to turn off the Wallbox, if the PV Power is under 1500W.

alias: Wallbox deaktivieren unter 1500W
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.sb5_0_1av_41_783_grid_power
    for:
      hours: 0
      minutes: 0
      seconds: 30
    below: 1500
condition:
  - condition: device
    type: is_on
    device_id: 9de57aa73ccc29a1ebd77c4c5a666eec
    entity_id: switch.wallboxpulsar_charge_control
    domain: switch
action:
  - type: turn_off
    device_id: 9de57aa73ccc29a1ebd77c4c5a666eec
    entity_id: switch.wallboxpulsar_charge_control
    domain: switch
mode: single

I also have some more scenes and automations to load the car, if the sun doesn’t shine. If anyone is interested, please feel free to write me. :slight_smile: