The Power Max Tracker integration for Home Assistant tracks the maximum hourly average power values from a specified power sensor, with optional gating by a binary sensor. It creates sensors to display the top power values in kilowatts (kW), their average, a source sensor that mirrors the input sensor in watts (W), and an hourly average power sensor, all ignoring negative values and setting to 0 when the binary sensor is off.
- Max Power Sensors: Creates
num_max_valuessensors (e.g.,sensor.max_hourly_average_power_1_<entry_id>,sensor.max_hourly_average_power_2_<entry_id>) showing the top hourly average power values in kW, rounded to 2 decimal places, with alast_updateattribute for the timestamp of the last value change. - Average Max Power Sensor: Creates a sensor (e.g.,
sensor.average_max_hourly_average_power_<entry_id>) showing the average of all max hourly average power values in kW, with an attributeprevious_month_averagefor the previous month's average. - Average Max Cost Sensor: Creates a sensor (e.g.,
sensor.average_max_hourly_average_power_cost_<entry_id>) showing the monetary cost of the average max hourly average power in the configured currency, with attributes for previous month cost and price per kW. Only created when price per kW is greater than 0. - Source Power Sensor: Creates a sensor (e.g.,
sensor.power_max_source_<entry_id>) that tracks the source sensor's state in watts, setting to0for negative values or when the binary sensor is off/unavailable. - Hourly Average Power Sensor: Creates a sensor (e.g.,
sensor.hourly_average_power_<entry_id>) that calculates the average power in kW so far in the current hour based on the source sensor's power, gated by the binary sensor, with periodic updates to account for 0W periods. - Hourly Updates: Updates
max_valuesat 1 minute past each hour using hourly average statistics from the source sensor. - Negative Value Filtering: Ignores negative power values in all sensors.
- Binary Sensor Gating: Only updates when the binary sensor (if configured) is
"on". - Monthly Reset: Optionally resets
max_valuesto0on the 1st of each month. - Multiple Config Entries: Supports multiple source sensors with separate max value tracking.
- Power Scaling Factor: Automatically detected based on the source sensor's unit_of_measurement (W/kW). No manual configuration required.
- Electricity Price Configuration: Configure electricity price per kW to calculate power costs.
- Services: Provides
power_max_tracker.update_max_valuesto recalculate max values from midnight, andpower_max_tracker.reset_max_valuesto update max values to the current month's maximum so far.
-
Via HACS:
- Add
https://github.com/perosb/power_max_trackeras a custom repository in HACS. - Install the
Power Max Trackerintegration. - Restart Home Assistant.
- Add
-
Manual Installation:
- Download the latest release from
https://github.com/perosb/power_max_tracker. - Extract the
power_max_trackerfolder to/config/custom_components/. - Restart Home Assistant.
- Download the latest release from
Add the integration via the Home Assistant UI or configuration.yaml.
- Go to Settings > Devices & Services > Add Integration.
- Search for "Power Max Tracker" and select it.
- Configure the options:
- Source Sensor: The power sensor to track (must provide watts).
- Number of Max Values: Number of max power sensors (1-10, default 2).
- Monthly Reset: Reset max values on the 1st of each month.
- Binary Sensor: Optional binary sensor to gate updates.
- Price per kW: Electricity price per kilowatt (0.01-100.0, default 0.0). When set to 0, no cost sensor is created.
- Power Scaling Factor: Automatically detected based on source sensor's unit_of_measurement. No manual configuration needed.
Add to your configuration.yaml under the sensor section:
sensor:
- platform: power_max_tracker
source_sensor: sensor.power_sensor
num_max_values: 2
monthly_reset: false
binary_sensor: binary_sensor.power_enabled
price_per_kw: 0.25
power_scaling_factor: 1000 # If source sensor is in kW, convert to WNote: YAML configurations create config entries automatically. To modify, edit configuration.yaml and restart Home Assistant.
source_sensor(required): The power sensor to track (e.g.,sensor.power_sensor), must provide watts (W).num_max_values(optional, default: 2): Number of max power sensors (1–10).monthly_reset(optional, default:false): Reset max values to0on the 1st of each month.binary_sensor(optional): A binary sensor (e.g.,binary_sensor.power_enabled) to gate updates; only updates when"on".price_per_kw(optional, default: 0.0): Electricity price per kilowatt for cost calculations (0.01-100.0). When set to 0, no cost sensor is created.power_scaling_factor(optional, default: 1.0): Deprecated. Scaling factor is now automatically detected based on source sensor's unit_of_measurement.
If you want to gate the power tracking based on time (e.g., only during high peak hours in certain months), create a template binary sensor in your configuration.yaml and reference it in the binary_sensor option. Here's an example that activates during weekdays (Mon-Fri) from 7 AM to 8 PM in the months of November through March:
template:
- binary_sensor:
- name: "Power Tracking Gate"
state: >
{% set current_month = now().month %}
{% set current_day = now().weekday() %}
{% set current_hour = now().hour %}
{% if current_month in [11, 12, 1, 2, 3] and current_day in [0, 1, 2, 3, 4] and current_hour >= 7 and current_hour < 20 %}
True
{% else %}
False
{% endif %}Then, configure the integration to use this sensor:
sensor:
- platform: power_max_tracker
source_sensor: sensor.power_sensor
binary_sensor: binary_sensor.power_tracking_gate- Entities Created:
sensor.max_hourly_average_power_<index>_<unique_id>: Topnum_max_valueshourly average power values in kW (e.g.,sensor.max_hourly_average_power_1_yaml_sensor_tibber_power).sensor.average_max_hourly_average_power_<unique_id>: Average of all max hourly average power values in kW (includesprevious_month_averageattribute).sensor.average_max_hourly_average_power_cost_<unique_id>: Cost of the average max hourly average power in the configured currency (includesprevious_month_costandprice_per_kwattributes). Only created when price per kW > 0.sensor.power_max_source_<unique_id>: Tracks the source sensor in watts,0if negative or binary sensor is off/unavailable.sensor.hourly_average_power_<unique_id>: Average power in kW so far in the current hour, with periodic updates for 0W periods.
- Services:
power_max_tracker.update_max_values: Recalculates max values from midnight to the current hour.power_max_tracker.reset_max_values: Updates max values to the current month's maximum so far (resets to 0 and recalculates from month start).
- Updates: Max sensors update at 1 minute past each hour or after calling services. The source and hourly average sensors update in real-time when the binary sensor is
"on", with additional periodic updates for the hourly average sensor.
- Source Sensor Units: The integration automatically detects whether the source sensor provides power in watts (W) or kilowatts (kW) based on the sensor's unit_of_measurement attribute. No manual configuration is required.
- Renaming Source Sensor: If the
source_sensoris renamed (e.g., fromsensor.power_sensortosensor.new_power_sensor), the integration will stop tracking it. Update the configuration with the new entity ID and restart Home Assistant to restore functionality.
MIT License. See LICENSE file for details.