As the cost of energy continues to rise, many of us are looking for ways to reduce our consumption during peak hours. I’ve been experimenting with automating my home devices based on real-time energy prices, and I’d like to share my findings and a solution that might work for others.
The challenge I faced was similar to what many others have mentioned: creating a script that automatically turns off devices when energy prices exceed a certain threshold relative to the daily average. After some research and trial and error, I found that integrating Home Assistant (HA) with external APIs like Tibber or Nordpool could provide the necessary data to make this work.
Here’s a simplified version of the script I developed. It calculates the daily average price and triggers devices to turn off when the price exceeds this average by a specified percentage:
Example script for HA
sensor.daily_average_price:
friendly_name: “Daily Average Price”
value_template: ‘{{ states.sensor.daily_price.attributes.AVERAGE }}’
automation.turn_off_devices:
alias: “Turn Off Devices During High Prices”
trigger:
platform: numeric_state
entity_id: sensor.current_price
above: ‘{{ states.sensor.daily_average_price.state | float * 1.05 }}’
action:
service: switch.turn_off
entity_id:
- switch.water_heater
- switch.floor_heating
This script calculates the daily average price and triggers the automation when the current price exceeds 105% of this average. The devices are turned off until the price drops back below the threshold.
For those who prefer a failsafe, I added a mechanism to ensure devices don’t stay off for more than 6 hours. This prevents any unintended consequences, like cold showers! The script can be adjusted to meet individual needs, such as changing the percentage threshold or the list of devices.
I’ve tested this setup for several months, and it has significantly reduced my energy costs without causing any inconvenience. It’s a simple yet effective way to make the most of off-peak hours.
If anyone has questions or needs help setting this up, feel free to reach out. Let’s work together to make our homes smarter and more energy-efficient!
Happy automating! ![]()