Last active
January 23, 2022 18:37
-
-
Save Cougar/2f7f87ac2dbbe84d892d6928cda898bd to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Automate switch based on energy price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Price Switch | |
description: Switch appliance on and off based on electricity price | |
domain: automation | |
source_url: https://gist.github.com/Cougar/2f7f87ac2dbbe84d892d6928cda898bd | |
input: | |
electricity_price_sensor: | |
name: Electricity price sensor | |
description: Electricity price tracking sensor (¢/kWh) | |
selector: | |
entity: | |
domain: sensor | |
default: 'sensor.enduser_energy_price' | |
target_switch: | |
name: Switch | |
description: The switch that needs to be automated | |
selector: | |
entity: | |
domain: switch | |
switch_on_price: | |
name: Switch on price | |
description: Switch on when price is below this treshold | |
selector: | |
number: | |
mode: box | |
min: 0 | |
max: 50 | |
step: 1 | |
unit_of_measurement: '¢' | |
default: 5 | |
switch_off_price: | |
name: Switch off price | |
description: Switch off when price is above this treshold | |
selector: | |
number: | |
mode: box | |
min: 0 | |
max: 50 | |
step: 1 | |
unit_of_measurement: '¢' | |
default: 10 | |
notify_device: | |
name: Devices to notify | |
description: Send change notification to this device | |
selector: | |
target: | |
device: | |
integration: mobile_app | |
notification_message: | |
name: Notification message | |
description: You can use "{{ target_switch }}", "{{ old_price }}", "{{ new_price }}", "{{ switch_state }}" and "{{ new_state }}" variables | |
default: Switch {{ target_switch }} {{ new_state }} after price change ({{ old_price }} → {{ new_price }}) | |
variables: | |
old_price: '{{ trigger.from_state.state }}' | |
new_price: '{{ trigger.to_state.state }}' | |
electricity_price_sensor: !input electricity_price_sensor | |
price: '{{ states(electricity_price_sensor)|float(0.0) }}' | |
switch_on_price: !input switch_on_price | |
switch_off_price: !input switch_off_price | |
target_switch: !input target_switch | |
switch_state: '{{ states(target_switch) }}' | |
new_state: '{% if (price|float) < (switch_on_price|float) %}on{% elif (price|float) > (switch_off_price|float) %}off{% else %}{{ switch_state }}{% endif %}' | |
notify_device: !input notify_device | |
notification_message: !input notification_message | |
trigger: | |
- platform: state | |
entity_id: !input electricity_price_sensor | |
condition: | |
- condition: template | |
value_template: '{{ switch_state != new_state }}' | |
action: | |
- service: switch.turn_{{ new_state }} | |
data: {} | |
entity_id: !input target_switch | |
- domain: mobile_app | |
type: notify | |
device_id: '{{ notify_device.device_id }}' | |
message: '{{ notification_message }}' | |
mode: single |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment