Is there a way to make a platform: integration that uses multiple entities? I want the sum of the energy used by my grouped sengled bulbs which report power. If not, how can I get the total energy used by these bulbs per hour, day, week, month and year?
You should check out the Utility integrations. There is all sorts of useful integrations for calculating values from other sensors. If you want the simple sum of all power sensors then you can use a statistics sensor. If you want the total usage over time then I think that’s the integration sensor although I will admit that one is a little tricky. You might need a SQL sensor for that, especially if you want to get the data over a particular range.
Although I have to say, a year is pretty long. If you have your purge_keep_days set that high I hope you have your recorder mapping to an external DB or a NAS or something. Although even then you might want to look into InfluxDB or something that’s a bit more designed for long-term storage and queriability of time-series data.
The integration sensor is what I was referring to in my initial post when I mentioned platform: integration. So my question was specifically about that.
I already have multiple integration sensors with a single source for each. They are for a fridge, heaters, a dehumidifier, etc. I have a utility meter for each of them that log energy used by these entities per hour, day, week, month and year. They are each in their own package. I use MariaDB and the recorder default of 10 days for purge_keep_days has been keeping the database size to an acceptable size. I use a USB HDD for HA.I also have InfluxDB setup but I use that only for Grafana. I wouldn’t know how to use InfluxDB to combine the total of multiple utility meters and have them report on a card in HA.
What I was trying to avoid was doing the exact same setup for each of my bulbs as I have for the other entities I have integration sensors and utility meters for since it would entail eleven more packages being created then creating a value template that adds them up although it might be what I have to do.
So what I am looking for is the most efficient way to make a integration sensor that uses multiple sources. If that isn’t possible what I was thinking was making a senors folder with multiple yaml files and one of the yaml files with a bunch of the integration sensor for each of my bulbs but HA won’t load with a sensor folder. I also thought of making a utility_meters.yaml and adding utility_meter: !include utility_meters.yaml
but without being able to use a sensors folder I don’t think it helps and I am back to creating eleven more packages for my bulbs.
Could you just use a template sensor that sums up all the bulb sensors and then create an Integration sensor on that? So like something like this for the template sensor:
sensor:
- platform: template
sensors:
total_bulb_power:
unique_id: sensor_sum_bulb_power
device_class: power
unit_of_measurement: W
value_template: >-
{% set bulb_sensors = [
"sensor.bulb_1_power",
"sensor.bulb_2_power",
...
] %}
{{ bulb_sensors | expand | map(attribute='state') | map('float') | sum | round(2) }}
I’m just guessing on the unit_of_measurement
obviously. Could also convert from W to kW or vice versa as part of the sensor, which ever you prefer. Then Integrate over this sensor that sums up the others.
EDIT: Also if you want, can make a group of all your bulbs to manage that separately instead of having that list in this template. Then can simplify this sensor even further:
sensor:
- platform: template
sensors:
total_bulb_power:
unique_id: sensor_sum_bulb_power
device_class: power
unit_of_measurement: W
value_template: >-
{{ 'group.my_bulbs' | expand | map(attribute='state') | map('float') | sum | round(2) }}
Thanks. I used the first example since it prevented me from having to make a group and then a template. I also used the example here to assist me since it was more similar to my situation. I put that template plus an integration sensor and a utility meter and value templates all for those bulbs in a single yaml and placed it in my packages folder. It all looks good now.