Tesla Powerwall use cases and automation sharing

Hi HA community!

After a recent breaking API change from Tesla, a bunch of developers and users got together to help debug and resolve within a day or two (yay open source!).

Out of that thread, there was also a suggestion to share automations and use cases. This is that spot!

(Note: this thread is mainly for discussion around the HACS Tesla integration, which still includes Cloud API connection as all power management has been removed from the local API, and hence the Tesla Powerwall built-in integration)

1 Like

Iā€™ve got a couple of automations which Iā€™ll give an overview of here, and happy to provide more detail if anyone else finds it useful

For context, Iā€™m in Australia and a customer of Amber Electric, which allows real-time energy pricing, and a lot of opportunity for savings based on battery usage.

When Iā€™m talking about charging, for me this means both setting number.home_energy_gateway_backup_reserve to 100 and select.home_energy_gateway_operation_mode to Backup (as this charges at a faster rate).

Notify when Solar feed in is negative
Exactly what it sounds like. If the following trigger is negative:

platform: numeric_state
entity_id: sensor.feed_in_price
below: 0
for:
  minutes: 5

then send a home assistant notification that weā€™re exporting, and should turn on any power-hungry devices

Charge and discharge based on a configurable schedule
This uses two time of day sensors set up in the UI to charge at certain times of the day (in winter I keep this turned on from 1am-5am and 10am-3pm). I also have an input number setting the ā€œtoo expensiveā€ price, which I stop buying at, even within those timeframes.

Note: I use Time of Day sensors as it allows for significantly better user experience that modifying scheduled in YAML every day, and allows for better in-app control.

Charge and discharge Powerwall based on current energy price
There is quite a bit of fluctuation in the market, so I donā€™t use this one as much as the previous automation.

In simple terms, I have a few input_number variables:

  • minimum_reserve_level: My actual minimum reserve. I pretty much always keep this at 20%
  • cheap_power_threshold: How cheap power has to be before Iā€™ll buy. Iā€™ll usually set these values of a morning after looking at the daily energy forecast in the Amber app
  • expensive_power_threshold: How expensive power has to be before I switch back to discharging the battery
  • max_autocharge_value: the maximum value I want my battery to charge to. Usually leave this around 95% to allow some headroom for incidental solar

And use these values to drive whether the Powerwall is charging quickly, holding charge, or discharging.

Go off-grid if automatically
I use this one sparingly, but if the solar export price is extremely low (I leave it around -10 cents, though we have price guarantees here in Australia so it doesnā€™t really matter) I use Powerwallā€™s in-built switch.home_energy_gateway_off_grid_operation to curtain solar production and avoid exporting.

Note that is you have anything other than a basic single phase, single powerwall installation then curtailments doesnā€™t seem to work

4 Likes

Thanks @daniel-simpson

I have a couple of automations that drive an input selection box which allow me to select ā€œcustomā€ modes, nothing special

  • ā€œcharge nowā€: set reserve to 100%; ensure grid charging is enabled and set operation mode to ā€˜backupā€™;
  • ā€œtime-based solarā€: use time based operation (autonomous iirc) but use excess solar to recharge battery;
  • ā€œtime based exportā€: use time based operation and export solar generation as possible; recharge battery off the grid;

On top of this, thereā€™s schedule driven automations that check battery levels and trigger grid charging at night. In fairness, for my use case, leaving the battery to do its thing in ā€˜autonomousā€™ mode does 90% of what I want it to on its own.

When I get permission to export energy from the battery, I will revisit some of these settings and automations.

Speaking of exporting - has anyone worked out if there is a way to force exporting to the grid a point in time? The only way I know of is to tweak the tariff to nudge the software to trigger exporting.

I too have been very impressed with the community effort to get the Custom Integration working again, so wanted to detail how it helps us.

We are in the UK and our electricity is via ā€˜Intelligent Octopusā€™ Intelligent Octopus Go | Octopus Energy which requires an EV registered to the account. As standard it has 6 hours of off-peak power (2330 - 0530) but if the EV is low on charge and needs more than 6 hours to get full enough for the next day then the system will (where possible) allocate other off-peak slots. These can be a contiguous block or split into half hour chunks. These extra off-peak slots apply to the whole house consumption, not just the EVā€™s consumption.

We also have 2 Powerwalls which are usually set to use 90% as Time of Use (Backup level of 10%). Normally the Powerwalls will charge between 2330 - 0530 and then the house will run from the Powerwalls from 0530 - 2330, so we usually use only a tiny amount of peak rate electricity.

When there is an ā€˜Intelligent Slotā€™ we want the car to charge from the grid, not from the Powerwalls. I used to set this manually in the Powerwall app by setting the Tariff details to match that nightā€™s charging plan. That is dull to do, and on occasion the Intelligent Slots can change during the night which then means the manually set slots are wrong.

We are also a long way from our substation, so the voltage during the day (no load) is up to about 242V, but with maximum load overnight (pegged to a max of 16kW for our 80A supply fuse) it gets down to about 223V. If the car starts charging at 240V and then the voltage drops to 223V then the car thinks there is a problem with the supply and limits itself to about 5kW, so the Powerwalls need to start charging before the car to avoid that big voltage drop.
That means I donā€™t want to rely on Octopus control of the charging times (the system controls the car to charge only during the off-peak slots). We want to allow the Powerwalls to charge for a minute or so before turning on the charger (a MyEnergi Zappi).

So, via HACS we use the

Octopus Intelligent Home Assistant integration

myenergi for Home Assistant

and (of course) the

Tesla Custom Integration

I am new to HA (a few weeks into the journey) so have put these together in the visual editor:

Trigger:
When Octopus Intelligent Slot (binary_sensor.octopus_intelligent_slot) changes to On

Condition:
Confirm Octopus Smart Charging (switch.octopus_smart_charging) is On

Actions:
Set Powerwall Reserve (number.triscombe_backup_reserve) to 100

Delay for 00:02:00

Select ā€˜Fastā€™ mode for Zappi charger (select.myenergi_charger_charge_mode)

and the outcome copied from the YAML editor:

alias: When IO slot, Powerwall Reserve 100, Charger Fast
description: >-
  Powerwall Reserve set to 100 when Intelligent Slot on, wait 2 mins, change
  charger to fast mode
trigger:
  - platform: state
    entity_id:
      - binary_sensor.octopus_intelligent_slot
    to: "on"
condition:
  - condition: state
    entity_id: switch.octopus_smart_charging
    state: "on"
action:
  - device_id: 91f9969405d6e6060c8ad47c8bf2f9ef
    domain: number
    entity_id: fee7c88090e153b895a7b0cebec13dc4
    type: set_value
    value: 100
    alias: Set Powerwall Reserve to 100%
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - service: select.select_option
    data:
      option: Fast
    target:
      entity_id: select.myenergi_charger_charge_mode
    alias: Set charger to Fast mode
mode: single

Then there is an opposite automation to revert back to normal when the Intelligent Slot is over. There may well be ā€˜betterā€™ ways to achieve this which I will discover as I find out more about HA!

1 Like

Firstly fantastic effort to fix this so quickly, a few years ago I hand crafted some stuff in Node Red which have worked really well, but given these recent 410 issues Iā€™d like to use this HA integration fora more stable base. My working Node Red use case is:

1 I call Solcast to get an accurate solar production forecast for the day at the start of an overnight cheap rate electricity period

2 I subtract that production value from the power wall 100% capacity to give me a required amount - the PW now rarely reaches 100% so I donā€™t feed back into the grid often

3 I set the PW reserve to this required amount and set the PW into backup mode (means if I charge car during this period the PW will remain at the required level)

4 At the end of cheap rate period I set the PW backup reserve to 5% and the operation mode to self consumption.

I have a question, how do I set the PW backup value to a template value (my calculated required level), all the examples I have found for this Tesla custom integration use static values? I have an existing sensor value with the required value

Thanks

Welcome @LampyDave

I am on exactly the same situation as you (albeit only 1 powerwall). I rarely plug in the car during the day, so these IO slots are kind of irrelevant, but itā€™s nice to have an elegant solution like yours. Makes perfect sense.

Question - why do you check switch.octopus_smart_charging as a condition? Wouldnā€™t the IO slot be sufficient for what you need?

Iā€™ve just had my PW set to export power, and Iā€™m looking for ways to control exporting. I intend to export during the day when energy is most useful to the grid, but I donā€™t want to export more than what I will need. I think I have a plan:

  • set the tesla tariff plan with a high export value to nudge it into exporting;
  • control the ā€˜energy exportsā€™ setting on HA to decide when to export;
  • calculate how much is reasonable to export, turn that into time and open the floodgates;

Points 1. and 2. are straight forward. Point 3 is more a 2-part process and I havenā€™t spent any time working it out.

Thanks for your reply and apologies for not seeing it for ages.

I check the smart_charging setting because normally the tariff settings on the Powerwall controls the overnight charging very adequately, and Iā€™d rather leave that in control unless I need the car to do an Intelligent charge. I tend to turn Smart Charging off in my Octopus app unless I am going to use it that day so that acts as a useful switch.
If (for example) my HA instance crashes at 0520 then this automation would leave the house running from the grid until I notice instead of running from battery from 0530 - and that would be a shock to the electricity billā€¦ When Iā€™m doing an Intelligent charge I tend to check that everything is running correctly, but thatā€™s not the case every other day.

Weā€™re not allowed to export power from the Powerwalls (by the DNO) so donā€™t have the option of tweaking how and when we export. Ah wellā€¦ :slight_smile:

1 Like

Iā€™m using the Tesla Custom Integration and can change the Battery reserve using the slider found in the integration.

But if I go into the Developer tools and try to set the state to say ā€˜30ā€™ it briefly changes and then goes back to what it was previously set to. Iā€™m looking for a way to set the battery reserve using an automation but have failed. Any one know how to accomplish this?

I have literally no idea why, but mine does the same in Developer Tools (changes but then changes back straight away). But when set from the automation (my automation in the Visual Editor looks like the below) it seems to work fine.

Have you tried yours via that route as yet?

I donā€™t have a service to set the Powerwall Battery Reserve. Iā€™m wondering if your Octopus integration is allowing you to do that. I found that sensors donā€™t typically allow you to set a value:

ā€œThere are no services in Home Assistant to set a sensorā€™s value because a sensor normally represents data received from a monitoring device.ā€

So that explains to me why once I set a value the sensor receives an update and changes it back. Yet, somehow the Tesla Custom Integration can do it. Iā€™d like to do it as well but so far lā€™ve failed ;(

I have managed to do mine as a ā€˜Deviceā€™ Action instead of a Service call. If I add an Action, then choose Device, choose the Powerwall device and then it gives a variety of options, one of which is ā€œSet value for backup reserveā€

Thanks so much. Just what I was looking for.

1 Like

Good afternoon. 1st time poster so be kind.

I have this intergration working. What iā€™d like to do is force the PW to export at maximum rate during the octopus saving sessions.

Is there an entity I can control via HA to enable this?

Iā€™ve just been put onto an Octopus Export Tarrif so iā€™d like to empty my battery tonight during the 1 hour saving session.

Thank you.

Firstly a disclaimer - I am not allowed to export from the Powerwalls, so this is not based on experience:
Even using the Tesla app the only way I can think of to achieve this would be to adjust the Time of Use tariff information so that the ā€˜Sell priceā€™ is really high for that period, but that side of things is not exposed to HA so Iā€™m not aware of a way to do this through HA.

1 Like

Welcome @liveleeiow hope you enjoy the forum;

You cannot directly control the powerwall, but you can ā€¦ nudge it in the direction you want.

Considering the switches and knobs you have available on HA:

  • Export mode: ā€˜solarā€™ or ā€˜everythingā€™
  • Reserve percentage
  • Control mode: ā€˜defaultā€™, ā€˜time based controlsā€™ (names might not be exact)
  • Grid charging: ā€˜Yesā€™ or ā€˜Noā€™

Your tariff rate matters towards how you can control the PW, but this isnā€™t accessible directly (or easily that I know of) from the custom integration but you can set it on the tesla app. Effectively you want to set a high export rate value around the times when you might want to export but keep export mode set to ā€˜solarā€™.

You can then configure some behaviours or ā€˜customā€™ modes of operation:

  • Force charge: set reserve to 100%, enable grid charging.
  • Hold charge: set reserve to current charge percentage.
  • Force export: set reserve to 0%, ensure that youā€™re on ā€˜time based controlā€™, set export mode to ā€˜everythingā€™.
2 Likes

Thank you @pjvenda and @LampyDave I appreciate your replies.

My plan for today has been to manually set an export value between 17:00 and 18:00 at Ā£4/kwh. Does it matter if I set the expensive export rate on the super off peak, mid peak or peak values?

Force charging I have sorted using the methods youā€™ve described.

Thank you.

1 Like

I donā€™t think it matters. I presume that the PW exports when it works out itā€™s beneficial to export, therefore if export rate > import rate, it exports.

But I donā€™t know the details well enough to say whether thereā€™s other factors at play, e.g. ā€œnot charging when at peak or super-peakā€ which would make sense conceptually. So if this were true and you would set your tariff as a flat off-peak with high export rate, it would (maybe) never decide to charge off the grid.

I started by creating the correct tariff plan. Then I added a super-peak between say 4pm and 8pm with an export rate set at Ā£.45 IIRC. So in practice my own PW wonā€™t export except in the hours of 4-8pm.

(curious that octopus are paying me Ā£2.25/kWh for todayā€™s session)

1 Like

Looks like iā€™ll be finding out in 70 mins :slight_smile:

Id like a HACS app that would do the following

1/ Adjusts the the time that the Powerwall2 charges from backup% to full 100% ie 2hrs (whatā€™s happening at my place) to say 6 to 8 hrs and/or
2/ Limits the rate of charge to say 2 kWHrsā€¦
3/ Provides override manual charge control (so it charges or discharges when I wantā€¦ not when Tesla thinks itā€™s bestā€¦

Cheers

SJ

Hi All,

First time postingā€¦

I am trying to get the above working to take advantage of the 15p export tariff. The issue I am having is when I go to select the actions I can only select grid related operations toggle, on, off. Are you able to advise how I have messed this up?

alias: "Powerwall charge to full off peak "
description: ā€œā€
trigger:

  • platform: state
    entity_id:
    • binary_sensor.octopus_intelligent_slot
      to: ā€œonā€
      condition:
  • condition: state
    entity_id: switch.octopus_smart_charging
    state: ā€œonā€
    action:
  • device_id: 3f0c1978fd0bb893029a46154b606890
    domain: number
    entity_id: fa148ccafa901f24d52457596562ccc3
    type: set_value
    value: 100
    alias: Set Powerwall Reserve to 100%
  • delay:
    hours: 0
    minutes: 2
    seconds: 0
    milliseconds: 0
  • service: select.select_option
    data:
    option: Fast
    target:
    entity_id: select.myenergi_charger_charge_mode
    alias: Set charger to Fast mode
    mode: single

then in the other view

the action only allows turning on or off from grid.

Thanks
PR