Using Watt value from Powerfox integration to turn on/off Shelly Plug

Goal.

Turn ON Smart Plug Shelly S to allow grid power to battery charger when Powerfox measured wattage is feeding grid (negative wattage).

Turn OFF when grid flow into house. Positive wattage.

Background. I have both a rooftop PV installation feeding an SMA inverter and a carport installation feeding DC to two Bluettí’s. AC300 and AC500. The Bluetti can also take AC but I do not want them to use Grid AC power.

Both Shelly switches and PowerFox successfully added to HA.

Using dedicated Ubuntu based laptop running HAOS standalone.

  • Core 2024.4.4
  • Supervisor 2024.04.0
  • Operating System 12.2
  • Frontend 20240404.2
    image

I wrote two automations to turn outlet on or off. My plan is to combine both with trigger id’s later, but just want to get one automation to work. The nice youtube instructions linked within HA show a completely different GUI -which actually would be nice to have. In the Create Automation I see no drop downs for trigger id’s on my version for example.

If I hit Run the outlet will turn on. Otherwise, it ignores my House Current value and never turns on or off. When it does work, I will fine tune the values for wattage and time.

Grid to Battery
image

I could not figure out how to copy the automation file with line numbers and I was scolded for posting code incorrectly - so here is a screen shot.

Any guidance for my first automation would be appreciated.

Greg

You are triggering currently on automation.add_grid_power_to_charger

That is incorrect. that is the automation (code) itself.

perhaps you want sensor.house_current? Is that what you intend?

Please also take a look at this:

Thanks for the quick feedback. I started over. The Turn on automation worked once. That’s all.

The Run command results in the switch toggling (Action).

I hope this is formatted correctly.

- id: '1714312185837'
  alias: Turn off outlet 5
  description: 'When takings power from grid turn off SW 5 charging battery '
  trigger:
  - platform: numeric_state
    entity_id:
    - sensor.house_current
    for:
      hours: 0
      minutes: 0
      seconds: 10
    attribute: W
    above: 1
  condition: []
  action:
  - type: turn_off
    device_id: 47c3f2d0fb2b78901f8a10c075d864cd
    entity_id: a061c1db9d5ed8804b3f3709bbfda2bb
    domain: switch
  mode: single
- id: '1714312646520'
  alias: Turn on Outlet 5 grid to battery
  description: Switch outlet 5 on when house PV is feeding grid
  trigger:
  - platform: numeric_state
    entity_id:
    - sensor.house_current
    for:
      hours: 0
      minutes: 0
      seconds: 10
    below: 1
  condition: []
  action:
  - type: turn_on
    device_id: 47c3f2d0fb2b78901f8a10c075d864cd
    entity_id: a061c1db9d5ed8804b3f3709bbfda2bb
    domain: switch
  mode: single

these, as written should trigger when the current change from being above 1 to below and vice versa for 10 seconds. it must transition from being above to below (or reverse).

See this

That’s not what’s biting you is it?

Perhaps. What seems simple may not be after all. A switch is turned ON or OFF depending on a certain wattage value.

Let’s back up and ask how one can achieve my goal of turning the outlet switch ON or OFF depending on the Value of the sensor.house_current.

It can be fine-tuned for what watt value to use and the time delay, but for now we want the switch ON when current is negative (feeding excess to grid) and OFF when positive. This is why I chose 1 Watt.

I get a bit confused when asked about a value being above or below a negative number. Is -400 above or below -200???

Ideally turn ON when -200 watts or greater and turn OFF when less then -200 watts.

it shouldn’t be that hard, but you have to wrap your head around a slightly different way of thinking. automations will do it’s work (turn on/off the switch) when something changes… when the trigger requirement goes from false to true.

you’re saying that you want it to turn on/off depending on the sensor.house_current. ok, that’s fine. it can turn on when it BECOMES greater than xxxx watts.

for home assistant (and most automation systems) you don’t turn on the switch when it “is” greater than xxxx watts. because the first instant it “is” greater than xxxx watts, it has become greater than xxxx watts… so if you turn it on when it becomes greater than xxxx watts, you should be all set.

does that make sense? so then if there are some scenarios where it is higher and the switch is off… you have to think about why it is off and what you want to do about it. e.g. if the switch was on (because it became greater than xxxx watts) then you go manually turn it off. what should happen? should it instantly turn it on again? if should it wait a while? should it stay off until it drops below xxxx and then rises again? if it did what you said litterally… that whenever it “is” above xxxx. then it should instantly turn on again the instant you turn it off… probably not what most people want. that’s one of the reasons why things don’t trigger on state, but they trigger on the requirement state changing to become true.

finally. -200 is greater than -400. home assistant uses standard math evaluations.

Many thanks. Something else then is at play here. To date I have had three successful Turn ON 's. Zero Turn Off"s. This is with carefully making sure switch was in opposite condition that I wanted and a solid transition using a heat gun to insure more or less wattage. Will keep working.

the way your code is currently there are a number of ways that could happen. here are a couple examples.

you have “attribute: w” in the turn off. but not turning on. are you supposed to look at the value of attribute “w” for the sensor? or is that a bug? i’m guessing this is prob the issue. but beyond that there are more cases…

i don’t know what your sensor.house_current values are but it’s theoretically possible if the value goes to 1 (exactly) then up. does that sensor round? is that possible? because you are triggering on going above and below 1. but not on 1. so imagine that it goes to 1, then to 0, then 1 then 0, then 1, then 0. it will keep triggering on, but never off.

another case (perhaps more likely?) is, since you have a 10 second requirement… if it goes above 1 for 9 seconds, then to 0 for 10 seconds, it will trigger the 'on". but never trigger the off.

Sorry for the delay. I went down a rabbit hole trying another device - Shelly Pro 3EM and using the native Shelly App. The 3EM provides total house current. Theoretically. Once you add a PV inverter the wattage readings go out the window. There is an apparent power reading that is close, unfortunately it is always positive, so useless. I will recheck wiring, but have little hope. There’s also the Shelly one phase Pro-EM which is advertised to provide solutions to PV excess power switching.

I will rewrite and get back to you one way or the other. I might just purchase a Sunny Home Manager 2.0 which reads total house current and talks to the SMA inverter and with Shelly switches. Unfortunately implementation with HA appears iffy however HA just adds another layer anyway that might not be advantageous for this particular task.