|
|
######################################################################
|
|
|
# @CCOSTAN - Follow Me on X
|
|
|
# For more info visit https://www.vcloudinfo.com/click-here
|
|
|
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
|
|
|
# -------------------------------------------------------------------
|
|
|
# Tesla Powerwall - Monitoring and outage automations
|
|
|
# Related Issue: 1550
|
|
|
# Related Issue: 1571
|
|
|
# Powerwall status sensors, outage alerting, and load-shedding helpers.
|
|
|
# -------------------------------------------------------------------
|
|
|
# Notes: Read more https://www.vcloudinfo.com/2018/01/going-green-to-save-some-green-in-2018.html | Existing Issue #272
|
|
|
# Tesla Powerwall added via UI Integration
|
|
|
######################################################################
|
|
|
# Binary Sensors:
|
|
|
# - binary_sensor.powerwall_charging ............. battery_charging (on=charging)
|
|
|
# - binary_sensor.powerwall_connected_to_tesla ... connectivity (on=connected)
|
|
|
# - binary_sensor.powerwall_grid_services_active .. power (on=active)
|
|
|
# - binary_sensor.powerwall_grid_status .......... power (on=grid up)
|
|
|
# - binary_sensor.powerwall_status ............... power (on=system ok)
|
|
|
#
|
|
|
# Power & Energy Sensors:
|
|
|
# - sensor.powerwall_charge ...................... battery %, 0–100
|
|
|
# - sensor.powerwall_backup_reserve .............. reserve %, 0–100
|
|
|
# - sensor.powerwall_battery_power ............... kW (+discharge / -charge)
|
|
|
# - sensor.powerwall_load_power .................. kW house load
|
|
|
# - sensor.powerwall_site_power .................. kW (+export / -import)
|
|
|
# - sensor.powerwall_solar_power ................. kW solar production
|
|
|
#
|
|
|
# Lifetime kWh Meters:
|
|
|
# - sensor.powerwall_battery_export .............. kWh -> grid/load
|
|
|
# - sensor.powerwall_battery_import .............. kWh <- battery charged
|
|
|
# - sensor.powerwall_load_export ................. kWh exported from loads
|
|
|
# - sensor.powerwall_load_import ................. kWh imported to loads
|
|
|
# - sensor.powerwall_site_export ................. kWh site -> grid
|
|
|
# - sensor.powerwall_site_import ................. kWh site <- grid
|
|
|
# - sensor.powerwall_solar_export ................ kWh solar -> site/battery/grid
|
|
|
# - sensor.powerwall_solar_import ................ kWh solar <- grid (rare)
|
|
|
#
|
|
|
# Switches:
|
|
|
# - switch.powerwall_off_grid_operation .......... island mode toggle
|
|
|
######################################################################
|
|
|
|
|
|
#-------------------------------------------
|
|
|
script:
|
|
|
powerwall_turn_off_nonessential_lights:
|
|
|
alias: "Powerwall - Turn Off Non-Essential Lights"
|
|
|
sequence:
|
|
|
- service: homeassistant.turn_off
|
|
|
target:
|
|
|
entity_id:
|
|
|
- group.interior_lights
|
|
|
- group.exterior_lights
|
|
|
- switch.kitchen_accent_2
|
|
|
- switch.master_bathroom_accent_2
|
|
|
|
|
|
automation:
|
|
|
- alias: Notify if Grid is down
|
|
|
id: 56a32121-5725-4510-a1fa-10f69a5c82ef
|
|
|
trigger:
|
|
|
- platform: state
|
|
|
entity_id: binary_sensor.powerwall_grid_status
|
|
|
|
|
|
condition:
|
|
|
- condition: template
|
|
|
# Check that both current and previous states are not 'unavailable', 'unknown', or 'null'.
|
|
|
value_template: >-
|
|
|
{{ states('binary_sensor.powerwall_grid_status') not in ['unavailable', 'unknown', 'null'] and
|
|
|
trigger.from_state.state not in ['unavailable', 'unknown', 'null'] }}
|
|
|
|
|
|
action:
|
|
|
- service: script.send_to_logbook
|
|
|
data:
|
|
|
topic: "POWER"
|
|
|
message: >-
|
|
|
Grid status is {{ (trigger.to_state.state)|replace('on', 'up')|replace('off', 'down') }}.
|
|
|
- service: script.notify_engine
|
|
|
data:
|
|
|
title: "Electrical Grid Status {{ (trigger.to_state.state)|replace('on', 'up')|replace('off', 'down') }}."
|
|
|
value1: "Please verify with the Tesla App."
|
|
|
who: 'parents'
|
|
|
group: 'information'
|
|
|
|
|
|
# https://github.com/CCOSTAN/Home-AssistantConfig/issues/779
|
|
|
- alias: Shut Things down if running on PowerWall
|
|
|
mode: restart
|
|
|
id: 37288a96-5f49-46c2-85c8-7e8794d23612
|
|
|
trigger:
|
|
|
- platform: state
|
|
|
entity_id: binary_sensor.powerwall_grid_status
|
|
|
to: 'off'
|
|
|
|
|
|
action:
|
|
|
- repeat:
|
|
|
count: 3
|
|
|
sequence:
|
|
|
- choose:
|
|
|
- conditions:
|
|
|
- condition: template
|
|
|
value_template: "{{ repeat.index == 2 }}"
|
|
|
sequence:
|
|
|
- delay:
|
|
|
minutes: 1
|
|
|
- conditions:
|
|
|
- condition: template
|
|
|
value_template: "{{ repeat.index == 3 }}"
|
|
|
sequence:
|
|
|
- delay:
|
|
|
minutes: 3
|
|
|
- service: script.powerwall_turn_off_nonessential_lights
|
|
|
- choose:
|
|
|
- conditions:
|
|
|
- condition: template
|
|
|
value_template: "{{ repeat.index == 1 }}"
|
|
|
sequence:
|
|
|
- service: script.notify_engine
|
|
|
data:
|
|
|
title: "Electrical Grid Status {{ (trigger.to_state.state)|replace('True', 'up')|replace('False', 'down') }}."
|
|
|
value1: "Taking actions to turning off the House Lights to preserve Battery Power."
|
|
|
who: 'family'
|
|
|
group: 'information'
|
|
|
- conditions:
|
|
|
- condition: template
|
|
|
value_template: "{{ repeat.index == 2 }}"
|
|
|
sequence:
|
|
|
- service: script.speech_engine
|
|
|
data:
|
|
|
value1: "Because of the Power Outage, the Lights will be recycled for 3 minutes. Lights may turn on and off during this time."
|
|
|
- conditions:
|
|
|
- condition: template
|
|
|
value_template: "{{ repeat.index == 3 }}"
|
|
|
sequence:
|
|
|
- service: script.speech_engine
|
|
|
data:
|
|
|
value1: "Automatic light recycling has been completed. Any abnormalities will have to be addressed in the Hue App most likely. "
|
|
|
|
|
|
- alias: "Powerwall Low Charge Monitoring and Recovery"
|
|
|
id: fda6116b-b2a5-4198-a1ce-4cf4bb3254b2
|
|
|
mode: single
|
|
|
trigger:
|
|
|
- id: low_24h
|
|
|
platform: numeric_state
|
|
|
entity_id: sensor.powerwall_charge
|
|
|
below: 60
|
|
|
for:
|
|
|
hours: 24
|
|
|
- id: recovered
|
|
|
platform: numeric_state
|
|
|
entity_id: sensor.powerwall_charge
|
|
|
above: 60
|
|
|
for:
|
|
|
minutes: 10
|
|
|
condition:
|
|
|
- condition: state
|
|
|
entity_id: binary_sensor.powerwall_grid_status
|
|
|
state: 'on'
|
|
|
action:
|
|
|
- choose:
|
|
|
- conditions:
|
|
|
- condition: trigger
|
|
|
id: low_24h
|
|
|
sequence:
|
|
|
- service: script.send_to_logbook
|
|
|
data:
|
|
|
topic: "POWER"
|
|
|
message: "Powerwall charge below 60% for 24h (current: {{ states('sensor.powerwall_charge') }}%)."
|
|
|
- service: repairs.create
|
|
|
data:
|
|
|
issue_id: "powerwall_low_charge_60_24h"
|
|
|
title: "Powerwall charge low for 24h"
|
|
|
severity: "warning"
|
|
|
persistent: true
|
|
|
description: >-
|
|
|
Powerwall has been below 60% for 24 hours while the grid is online.
|
|
|
|
|
|
Current charge: {{ states('sensor.powerwall_charge') }}%.
|
|
|
- service: script.notify_engine
|
|
|
data:
|
|
|
title: "Powerwall Low Charge Alert - Current Charge: {{ states('sensor.powerwall_charge') }}"
|
|
|
value1: "The Powerwall has been below 50% charge for more than 24 hours while the grid is online. This may indicate an issue."
|
|
|
who: 'parents'
|
|
|
group: 'information'
|
|
|
- conditions:
|
|
|
- condition: trigger
|
|
|
id: recovered
|
|
|
sequence:
|
|
|
- service: repairs.remove
|
|
|
continue_on_error: true
|
|
|
data:
|
|
|
issue_id: "powerwall_low_charge_60_24h"
|
|
|
- service: script.send_to_logbook
|
|
|
data:
|
|
|
topic: "POWER"
|
|
|
message: "Powerwall charge recovered above 60%. Cleared repair issue."
|
|
|
|
|
|
- alias: "Shut down Docker hosts and camera PoE at 75% Powerwall"
|
|
|
id: 25b3d3d8-92fa-454a-9f1c-6d3fd0f3af58
|
|
|
description: "Protect battery by shutting down non-essentials when Powerwall drops below 75%"
|
|
|
mode: single
|
|
|
trigger:
|
|
|
- platform: numeric_state
|
|
|
entity_id: sensor.powerwall_charge
|
|
|
below: 75
|
|
|
for:
|
|
|
minutes: 3
|
|
|
action:
|
|
|
- service: button.press
|
|
|
target:
|
|
|
entity_id:
|
|
|
- button.qemu_docker2_101_shutdown
|
|
|
- button.qemu_docker69_169_shutdown
|
|
|
- service: switch.turn_off
|
|
|
target:
|
|
|
entity_id:
|
|
|
- switch.poe_garage_port_3_poe
|
|
|
- switch.poe_garage_port_4_poe
|
|
|
- switch.poe_garage_port_5_poe
|
|
|
- switch.poe_garage_port_6_poe
|
|
|
|
|
|
- alias: "Powerwall outage - Rheem WH mode control"
|
|
|
id: d686f650-65ad-4cc6-8e27-8b5ee76b5338
|
|
|
description: "During outages, switch Rheem mode by time-of-day and battery reserve"
|
|
|
mode: single
|
|
|
trigger:
|
|
|
- id: sunrise
|
|
|
platform: sun
|
|
|
event: sunrise
|
|
|
- id: charge_above_50
|
|
|
platform: numeric_state
|
|
|
entity_id: sensor.powerwall_charge
|
|
|
above: 50
|
|
|
for:
|
|
|
minutes: 5
|
|
|
- id: sunset
|
|
|
platform: sun
|
|
|
event: sunset
|
|
|
- id: grid_off_1m
|
|
|
platform: state
|
|
|
entity_id: binary_sensor.powerwall_grid_status
|
|
|
to: 'off'
|
|
|
for:
|
|
|
minutes: 1
|
|
|
condition:
|
|
|
- condition: state
|
|
|
entity_id: binary_sensor.powerwall_grid_status
|
|
|
state: 'off'
|
|
|
action:
|
|
|
- choose:
|
|
|
- conditions:
|
|
|
- condition: template
|
|
|
value_template: "{{ trigger.id in ['sunset', 'grid_off_1m'] }}"
|
|
|
- condition: or
|
|
|
conditions:
|
|
|
- condition: sun
|
|
|
after: sunset
|
|
|
- condition: sun
|
|
|
before: sunrise
|
|
|
sequence:
|
|
|
- service: water_heater.set_operation_mode
|
|
|
target:
|
|
|
entity_id: water_heater.rheem_wh
|
|
|
data:
|
|
|
state: off
|
|
|
- conditions:
|
|
|
- condition: template
|
|
|
value_template: "{{ trigger.id in ['sunrise', 'charge_above_50', 'grid_off_1m'] }}"
|
|
|
- condition: numeric_state
|
|
|
entity_id: sensor.powerwall_charge
|
|
|
above: 50
|
|
|
- condition: sun
|
|
|
after: sunrise
|
|
|
before: sunset
|
|
|
sequence:
|
|
|
- service: water_heater.set_operation_mode
|
|
|
target:
|
|
|
entity_id: water_heater.rheem_wh
|
|
|
data:
|
|
|
state: heat_pump
|
|
|
|
|
|
- alias: "Restore PoE ports when grid returns"
|
|
|
id: 1ae8b5c5-8627-4a44-8c8a-5bf8ca5e1bf5
|
|
|
description: "Turn camera PoE ports back on after grid has been stable"
|
|
|
mode: single
|
|
|
trigger:
|
|
|
- platform: state
|
|
|
entity_id: binary_sensor.powerwall_grid_status
|
|
|
from: 'off'
|
|
|
to: 'on'
|
|
|
for:
|
|
|
minutes: 60
|
|
|
- platform: numeric_state
|
|
|
entity_id: sensor.powerwall_charge
|
|
|
above: 90
|
|
|
|
|
|
condition:
|
|
|
- condition: or
|
|
|
conditions:
|
|
|
- condition: state
|
|
|
entity_id: switch.poe_garage_port_3_poe
|
|
|
state: 'off'
|
|
|
- condition: state
|
|
|
entity_id: switch.poe_garage_port_4_poe
|
|
|
state: 'off'
|
|
|
- condition: state
|
|
|
entity_id: switch.poe_garage_port_5_poe
|
|
|
state: 'off'
|
|
|
- condition: state
|
|
|
entity_id: switch.poe_garage_port_6_poe
|
|
|
state: 'off'
|
|
|
- condition: numeric_state
|
|
|
entity_id: sensor.powerwall_charge
|
|
|
above: 90
|
|
|
action:
|
|
|
- service: switch.turn_on
|
|
|
target:
|
|
|
entity_id:
|
|
|
- switch.poe_garage_port_3_poe
|
|
|
- switch.poe_garage_port_4_poe
|
|
|
- switch.poe_garage_port_5_poe
|
|
|
- switch.poe_garage_port_6_poe
|
|
|
- service: script.notify_engine
|
|
|
data:
|
|
|
title: "Grid restored - PoE ports re-enabled"
|
|
|
value1: "Power is stable. Camera PoE ports 3-6 were turned back on automatically."
|
|
|
who: 'family'
|
|
|
group: 'information'
|
|
|
|
|
|
# https://github.com/CCOSTAN/Home-AssistantConfig/issues/547
|
|
|
- alias: Turn off the Nest Thermostats during a Power Outage
|
|
|
id: 022bd9da-ab7c-4c1b-9e95-2ff4ffe5f9cc
|
|
|
|
|
|
trigger:
|
|
|
- platform: state
|
|
|
entity_id: binary_sensor.powerwall_grid_status
|
|
|
to: 'off'
|
|
|
for:
|
|
|
minutes: 6
|
|
|
|
|
|
condition:
|
|
|
- condition: template
|
|
|
value_template: "{{ states('binary_sensor.powerwall_grid_status') == 'off' }}"
|
|
|
|
|
|
action:
|
|
|
- service: climate.turn_off
|
|
|
data:
|
|
|
entity_id:
|
|
|
- climate.downstairs
|
|
|
- climate.upstairs
|
|
|
|
|
|
- service: script.notify_engine
|
|
|
data:
|
|
|
title: "Electrical Grid Status {{ (trigger.to_state.state)|replace('True', 'up')|replace('False', 'down') }}."
|
|
|
value1: "Taking actions to turning off the AC units to preserve Battery Power."
|
|
|
who: 'family'
|
|
|
group: 'information'
|
|
|
|
|
|
- alias: Turn back on the Nest Thermostats after a Power Outage
|
|
|
id: 14faf84b-cb24-4391-a97f-b83479a67fc7
|
|
|
|
|
|
trigger:
|
|
|
- platform: state
|
|
|
entity_id: binary_sensor.powerwall_grid_status
|
|
|
from: 'off'
|
|
|
to: 'on'
|
|
|
for:
|
|
|
minutes: 10
|
|
|
|
|
|
condition:
|
|
|
- condition: template
|
|
|
value_template: "{{ states('binary_sensor.powerwall_grid_status') == 'on' }}"
|
|
|
- condition: or
|
|
|
conditions:
|
|
|
- condition: state
|
|
|
entity_id: climate.downstairs
|
|
|
state: 'off'
|
|
|
- condition: state
|
|
|
entity_id: climate.upstairs
|
|
|
state: 'off'
|
|
|
|
|
|
action:
|
|
|
- choose:
|
|
|
- conditions:
|
|
|
- condition: numeric_state
|
|
|
entity_id: sensor.pirateweather_temperature
|
|
|
below: 75
|
|
|
sequence:
|
|
|
- service: script.send_to_logbook
|
|
|
data:
|
|
|
topic: "CLIMATE"
|
|
|
message: "Skipping downstairs cool mode (outside temp <75F)."
|
|
|
default:
|
|
|
- service: climate.set_hvac_mode
|
|
|
data:
|
|
|
entity_id: climate.downstairs
|
|
|
hvac_mode: cool
|
|
|
- service: climate.set_hvac_mode
|
|
|
data:
|
|
|
entity_id: climate.upstairs
|
|
|
hvac_mode: cool
|
|
|
- service: climate.set_temperature
|
|
|
data:
|
|
|
entity_id: climate.upstairs
|
|
|
temperature: 80
|
|
|
|
|
|
- service: script.notify_engine
|
|
|
data:
|
|
|
title: "Electrical Grid Status {{ (trigger.to_state.state)|replace('True', 'up')|replace('False', 'down') }}."
|
|
|
value1: "All AC systems are set back to normal operations (downstairs cool may be skipped if outside <75F)."
|
|
|
who: 'family'
|
|
|
group: 'information'
|