Very recent to Home Assistant (1 week). I have some automations setup & I would be grateful for feedback from some savvy programmers to simplify my code and remove any obvious bloat or mistakes that may be present.
Car Charging (BMW i3)
Charge my car to max 85% only in my off peak electricity times. It’s a BMW i3 and I’m unable to set a max charge limit within the vehicle, so I poll BMW API to return the charge level. My cheap electricity is between 23.30pm and 05.30am. When the car is plugged in (usually after 5pm) I want the car to wait until my cheap electricity times start and only charge to 85%
I have an API setup for the car (BMW Connected drive) in HA, which polls BMW for various statuses of the car, one of these returned is battery level (SOC).
Note: BMW connected drive rejects API calls if too many requests (100?) in a 24hr period (gets reset around 00.00 UMT). I have disabled HA Cloud auto update from Integrations (default was 5 mins) and THINK I have manually set updates to every 30 mins between 5.30am-23.30pm (36 requests) and every 6 mins during cheap charging window (23.30pm to 5.30am - 60 requests).
The EV charger is programmed (outside of HA) to only deliver power between 23.30-5.30am when in Eco+ mode. When it is outside of the cheap charging times but in Eco+ mode, the charging is paused. I can control the charger in HA to change the mode e.g. Eco+ & Stop.
Here is what I have setup already.
Automation 1 - Poll the BMW server to get car statuses (e.g. charge level, door lock status, etc) every 30 mins between 5.30am and 23.30pm (36 requests in period)
alias: i3S Poll BMW Server Every 30 mins [6am-11.30pm]
description: Poll BMW Servers every 30 mins (not charging)
trigger:
- platform: time_pattern
minutes: /30
condition:
- condition: time
after: "06:00:00"
before: "23:30:00"
action:
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.i3s_120_remaining_battery_percent
mode: single
Automation 2 - Poll the BMW server to get the car status every 6 mins between 23.30pm and 05.30am (60 requests in period) - this will make sure the sampling rate from BMW is higher, to help reach the 85% charge level more accurately in Automation 3 and not overshoot it by much.
alias: i3S Poll BMW Server Every 6 mins [11.30pm-5.30am]
description: Poll BMW Servers every 6 mins (when charging)
trigger:
- platform: time_pattern
minutes: /6
condition:
- condition: time
after: "23:30:00"
before: "05:54:00"
action:
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.i3s_120_remaining_battery_percent
mode: single
Automation 3
Charge the car if its under 85% SOC & only charge in the cheap electricty window 23.30pm and 05.30am
alias: i3S If SOC > 85% > Stop Charger [/5m Between 23.30-05.30]
description: ""
trigger:
- platform: time_pattern
minutes: /5
hours: "*"
seconds: "0"
enabled: true
condition:
- type: is_battery_level
condition: device
device_id: (removed)
entity_id: sensor.i3s_120_remaining_battery_percent
domain: sensor
above: 85
- condition: time
after: "23:30:00"
before: "05:30:00"
weekday:
- sun
- sat
- fri
- thu
- wed
- tue
- mon
- condition: not
conditions:
- condition: device
device_id: (removed)
domain: select
entity_id: select.myenergi_zappi_charge_mode
type: selected_option
option: Stopped
for:
hours: 0
minutes: 0
seconds: 10
action:
- device_id: (removed)
domain: select
entity_id: select.myenergi_zappi_charge_mode
type: select_option
option: Stopped
enabled: true
- service: notify.mobile_app_iphone
data:
message: Car 85% stop charge
title: SOC > 85% > Zappi Mode Stop
mode: single
Automation 4
Reset the charger back to Eco+ mode (paused).
alias: i3S Set Zappi Mode Eco+ [09/12/15/18/21 Daily]
description: Set Zappi mode to Eco+ @ 9am/12pm/3pm/6pm/9pm/11pm Daily
trigger:
- platform: time
at: "09:00:00"
enabled: true
- platform: time
at: "12:00:00"
enabled: true
- platform: time
at: "15:00:00"
enabled: true
- platform: time
at: "18:00:00"
enabled: true
- platform: time
at: "21:00:00"
enabled: true
- platform: time
at: "23:00:00"
enabled: true
condition:
- condition: not
conditions:
- condition: device
device_id: (removed)
domain: select
entity_id: select.myenergi_zappi_charge_mode
type: selected_option
option: Eco+
action:
- device_id: (removed)
domain: select
entity_id: select.myenergi_zappi_charge_mode
type: select_option
option: Eco+
enabled: true
- service: notify.mobile_app_iphone
data:
message: Zappi mode changed
title: i3S Set Zappi Mode Eco+ [09/12/15/18/21 Daily]
mode: single