# Possibilites to identify individual power consumers from total power consumption

Hi,

I have some big power consumers that don’t have individual plugs to measure power consumption and was thinking about if it was possible to identify the consumers based on the change in power consumption. Basically, if the total power consumption goes up by 820 - 860 watts I know this is the dehumidifer in the basement. I made a statistical helper to show the change on power which sort of works but I can’t tell if the consumer is turning on or off since it’s just measuring change.

I realize it could get a bit complex if many consumers turn on at the same time but it’s something I would like to work on.

Any ideas from you guys on how to do this (i.e. fingerprinting consumers and having Home Asisstant identify which it is)?

Thanks!

I did shamelessly try to get ChatGPT to write the script to get a rough idea but I wasn’t able to modify it to work for me, maybe some of you guys can help get it working? Thanks!

Code:

``````alias: Power consumption unit identification

# Define the power threshold for a significant change
power_threshold: 50  # adjust this value as needed

# Define the list of consumers and their power consumption levels
consumers:
- name: "Refrigerator"
power: 100
- name: "Air Conditioner"
power: 500
- name: "TV"
power: 50
# add more consumers as needed

# Define the automation trigger for the power sensor
automation:
trigger:
platform: state
entity_id: sensor.p1_meter_effekt
action:
# Get the current power consumption value from the sensor
- service: mqtt.publish
data:
topic: "home/p1_meter_effekt"
# Check if the power consumption has increased or decreased significantly
- condition: template
value_template: >-
{% set current_power = states('sensor.p1_meter_effekt') | float %}
{% set previous_power = states('sensor.p1_meter_effekt') | float - trigger.from_state.state | float %}
{% set delta_power = current_power - previous_power %}
{% set is_increase = delta_power > power_threshold %}
{% set is_decrease = delta_power < -power_threshold %}
{{ is_increase or is_decrease }}
# Determine which consumer corresponds to the power change
- choose:
- conditions: "{{ delta_power > 0 }}"
sequence:
- variables:
consumer = None
- repeat:
for:
item in consumers
sequence:
- condition: template
value_template: >-
{% set consumer_power = item.power | float %}
{% set total_power = states('sensor.p1_meter_effekt') | float %}
{% set consumer_ratio = consumer_power / total_power %}
{% set delta_ratio = delta_power / total_power %}
{{ consumer_ratio >= delta_ratio }}
- variables:
consumer: "{{ item.name }}"
until:
- "{{ consumer is not none }}"
- service: notify.notify
data:
message: "Power increased by {{ delta_power }} watts. The consumer is {{ consumer }}."
- conditions: "{{ delta_power < 0 }}"
sequence:
- variables:
consumer = None
- repeat:
for:
item in consumers
sequence:
- condition: template
value_template: >-
{% set consumer_power = item.power | float %}
{% set total_power = states('sensor.p1_meter_effekt') | float %}
{% set consumer_ratio = consumer_power / total_power %}
{% set delta_ratio = delta_power / total_power %}
{{ consumer_ratio <= delta_ratio }}
- variables:
consumer: "{{ item.name }}"
until:
- "{{ consumer is not none }}"
- service: notify.notify
data:
message: Power decreased by {{ -delta_power }} watts. The consumer is {{ consumer }}.
``````

It’s a good idea but sometimes the reading of a sensor can have multiple points before reaching the stable value.
Example.
1000
1200
1400
1800
and all these values are within a few seconds. That should mean it’s dehumidifier but could be wrongly assumed to be several other devices.

You probably need a reading from a few seconds ago to compare against.

Hi! Yes, you are right and I did look into it and noticed it takes 5-10 seconds before the power consumption value stabilizes. So it would make sense the the script to react when the value has been consistent for 10 seconds I think. For my P1 Meter power sensor, it seems to stabilize after 5 seconds depending on the appliance so 10 seconds would make sense I think.

The only problem I see with this is it is just a breakdown from your entire power usage.

I have put in a lot of Kasa/TP-Link EP25s and HS300s throughout my home as well as a Sense power monitor to figure out as many of the things it can find. One thing I have noticed is that those smart plugs and power strips get very chatty with Sense.

That’s true, but I was thinking it would be useful to track the bigger consumers like dehumidifer, water heater, air condition, stove, coffe maker etc. The smaller ones like lights and TV would just fall into an “unknown” category.

Just thought of something…

if you create a sensor that triggers on the state change of the power sensor then it could hold the previous values.
Something like:

``````{1000,1200,1400,1800,2000}
``````

And this can then be used (I guess) with

``````{% set v = states('sensor.name') | to_json %}

{{ v[0] }} // 1000
``````

This can then be used to see what the value was some time ago. The time won’t be seconds or anything, it’s just what the previous, and the one before that and so on was.

And you can fairly easily just remove the oldest value in the sensor when a new value comes in.

That sounds possible!

I have some progress but making an automation that triggers on state change of the power meter and stores the value, then waits 5 seconds and stores that value and that works pretty good. Now for the hard part to make the code that compares the difference with pre-defind consumers. Never coded in Home Asisstant before so takes some time learn the syntax and functionalities, but learning about templates now so think that is a way to go.

I don’t think you should wait five seconds.
It’s better to capture every state change (unless the power meeter is super sensitive).
So just a state trigger and empty in to and from.

The comparison could be a state trigger on the power meeter and condition:

``````{{ (trigger.to_state.state | float - (states('sensor.old_values') | to_json)[0] | float) >= 800 }}
``````

I think.

Make sure the state trigger does not trigger on unknown or unavailable

Looking at the data I discovered it takes about 5 seconds for the consumer to stabilize, like starting the humidifier will casue a peak for 2-3 seconds and then stabilize so the logic was to capture the steady state. My meter is quite sensitive so that’s why I thought that would be better.

But that can be changed later, the challenge now is getting the rest to work