Is there any way to create many templates at once automatically, and do so without swamping my history storage?
The context is: I’m setting up energy monitoring and have 80-90 devices reporting wattage in Home Assistant (mixture of circuit monitors, smart plugs, smart outlets/switches, and smart appliances. (Note that some of these devices contribute fairly frequent readings – like every handful of seconds – which is great!) From this, I’m trying to create a dashboard with a table listing each device and the amount it has contributed to this month’s power bill. (Note that I’m able to pull my current monthly average power price ($/kWh) from a power company integration though it fluctuates due to the fun of seasonal power prices, inclining block tariffs, etc.)
The obvious approach would be:
For each wattage entity, create a template that computes a Riemann sum integral of that device’s wattage. (The result will be energy.) Somehow find a way to reset this to zero once a month.
Create a second template that multiplies that energy template by the power price to determine spend.
But this approach has three significant drawbacks:
I will have to manually create like 160-180 templates (and remember to correctly update these if I ever, e.g., move a smart plug from one device to another or a circuit monitor to another circuit and rename it, etc.). This will not be fun to do!!!
I’m concerned about storage usage for my history recorder: I have a fairly long history window (1yr) and some of these devices report wattage quite frequently. I’m willing to spend the storage storing actual usage… but I don’t want to triple that storage volume to stupidly record these easy-to-compute templates as well.
I’m not actually sure how to auto-reset the cumulative consumption templates every month. Is there a straightforward way to do that?
@Holdestmade thanks, but the utility meter integration only provides total consumption for the entire house/meter… but my whole point for any of this is to be able to see which devices are guilty of consuming and outsized share, so that I can potentially do something about it…
Are you sure those devices don’t also provide you with energy consumption besides power? I mean, why did you invest in 80+ devices without checking what they actually provide you with?
Check out powercalc.
It can calculate the meter values on devices and add it as an entity.
It have profiles for many devices, so smart bulbs can be metered too and it can add metering to devices with a fixed usage profile too.
@danieldotnl Some of the devices provide daily energy but I don’t personally find that as useful as monthly.
(And thanks for the helpful admonishment about why I bought the devices. The majority of them are circuit monitors on a multi-circuit breaker monitor, and many of the others are devices bought for other purposes that incidentally can report power too (like smart plugs)… and either way I know it’s always possible to simply export the raw data and analyze it outside of Home Assistant but I asked this question hoping that there might be a more-streamlined alternative. )
Sorry for that. Reading back I can see how you read it as an admonishment though I was rather surprised.
I was asking if they provide energy so you can skip the riemann or powercalc step and just throw it in a utility meter for monthly totals(and have more accurate results).
Personally I prefer weekly or 4-week periods though, as months cannot be compared fairly.
So what I do, is first not worry about having hundreds of templates. HA is very efficient. You can also manage recorder retention on a per entity basis.
For my power sensors and utility meters. I create a “master template” yaml file as a “package”, I store this outside of HA. I then run a shell script that converts the master template into a specific template for a specific power sensor. Then deploy these packages to HA. I can change the master template rerun the script and everything is now consistent. If I need to add a new power meter, gas meter, water meter, etc. it’s a one liner in the build script.
#/bin/bash -xv
TARGET="/mnt/c/github/ha_rage"
source ./module_scripts.sh
build_init
# Furnace has 0.65 GPH nozzle
furnace_template furnace_burner oil binary_sensor.furnace_burner_running 0.65
furnace_template bedroom_heat oil binary_sensor.furnace_burner_running '{{ states("sensor.bedroom_oil_usage_gph") }}'
furnace_template studio_heat oil binary_sensor.furnace_burner_running '{{ states("sensor.studio_oil_usage_gph") }}'
furnace_template living_room_heat oil binary_sensor.furnace_burner_running '{{ states("sensor.living_room_oil_usage_gph") }}'
furnace_template water_heater_heat oil binary_sensor.furnace_burner_running '{{ states("sensor.water_heater_oil_usage_gph") }}'
# Home Power
power_template house_power sensor.total_watts trapezoidal utility
# Wells
power_template newwell_power sensor.newwell_watts left load_minor
power_template oldwell_power sensor.oldwell_watts left load_minor
# Dehumidifier
power_template dehumidifier_power sensor.switch_2_power left load
# Furnace Burner
power_template furnace_burner_power sensor.furnace_burner_watts left load_minor
# Air Conditioner
power_template ac_compressor_power sensor.sagehouse_inverter_energy left load
power_template ac_air_handler_power sensor.air_conditioner_indoor_unit_power left load
# HVAC_UV
power_switch_watts_template hvac_uv switch.hvac_uv 103
power_template hvac_uv_power sensor.hvac_uv_power left load_minor
# WATER_UV
power_switch_watts_template water_uv switch.water_uv 24.7
power_template water_uv_power sensor.water_uv_power left load_minor
# Study IT
power_static_watts_template pw_study_it 73
power_template pw_study_it_power sensor.pw_study_it_power left load
# Basement IT
power_static_watts_template pw_basement_it 27.2
power_template pw_basement_it_power sensor.pw_basement_it_power left load_minor
# TV
power_template pw_tv_power sensor.tv_powerstrip_tv_power left load_minor
# Roku
power_template pw_roku_power sensor.tv_powerstrip_roku_power left load_minor
# Cisco
power_template pw_lr_cisco sensor.tv_powerstrip_hub_power left load_minor
# Receiver
power_template pw_receiver sensor.tv_powerstrip_receiver_power left load_minor
# Sonos
power_template pw_lr_sonos sensor.tv_powerstrip_sonos_power left load_minor
water_template oldwell binary_sensor.oldwell_state input_number.oldwell_gpm supply
water_template newwell binary_sensor.newwell_state input_number.newwell_gpm supply
water_template_totalizer home "states(\"sensor.oldwell_gallons_per_hour\")|float(0) + states(\"sensor.newwell_gallons_per_hour\")|float(0)" total
um_delta_values garden sensor.ltap_last_volume water G
water_filter ap124 sensor.home_water_usage
water_filter ap110 sensor.home_water_usage
water_filter salt sensor.home_water_usage binary_sensor.wl_salt_ran_today
water_filter calcium sensor.home_water_usage binary_sensor.wl_calcium_ran_today
uv_filter water_uv switch.water_uv "iif(is_state(\"switch.water_uv\",\"on\"),1,0)"
uv_filter hvac_uv switch.hvac_uv "iif(is_state(\"switch.hvac_uv\",\"on\"),1,0)"
build_finish