I set up the Energy Dashboard with a Shelly EM3 and it is correctly showing the energy taken from and returned to the grid. I’m using a static tariff, but my electric company actually charges a daily fee plus a per kWh tariff. I’ve been trying to set up the utility meter helper to calculate these. This is the configuration.yaml and the sensor it and the energy dashboard use:
- name: "Grid Energy Total"
unique_id: grid_energy_total
state: >-
{{ [ states('sensor.shellyem3_channel_a_energy'),
states('sensor.shellyem3_channel_b_energy'),
] | map('float') | sum }}
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
attributes:
last_reset: "1970-01-01T00:00:00+00:00"
availability: >-
{{ [ states('sensor.shellyem3_channel_a_energy'),
states('sensor.shellyem3_channel_b_energy'),
] | map('is_number') | min }}
but there I’m stuck. I know how I would do it in python or C#: pass the kWh used since midnight to a function that would divide that into the daily fee, add the per kWh tariff and return that as the total tariff. I think I need a sensor template to calculate these charges. I could use some help…thanks for any.
I would have 2 separate utilities meter for channel A and B (i dont think we can have multiple source into one utility meter) and use template sensor to add the two to get total energy. Not very elegant but work fine and seem to quite accurately predict the bill, I am interested to see what others have.
utility_meter:
energy_daily_1:
source: sensor.shellyem_channel_1_energy
name: Energy Daily 1
cycle: daily
energy_daily_2:
source: sensor.shellyem_c45bbe6b70c8_channel_1_energy
name: Energy Daily 1
cycle: daily
That’s what the template sensor does, adds the 2 phases of electricity to get total energy, and it works fine. It’s the utility meter that I need help on.
you can use that sensor for 3rd utility meter… continuing from where i left off
utility_meter:
energy_daily_total:
source: sensor.energy_total
name: Energy Daily Total
cycle: daily
energy_monthly_total:
source: sensor.energy_total
name: Energy Monthly Total
cycle: monthly
energy_quarterly_total:
source: sensor.energy_total
name: Energy Quarterly Total
cron: "0 0 27 3/3 *"
is that what you mean? Since utilities meter is cumulative it doesnt matter, as long as sensor move it will accumulate. And use the two service to adjust you current value.
SERVICE UTILITY_METER.CALIBRATE
SERVICE UTILITY_METER.RESET
I’ve made some progress, though it’s difficult to be certain of the final results since they are accumulative. I’d like to know where the database is for the energy dashboard so I could clean it out and start again. These are the energy meters I use:
`utility_meter:
grid_energy_daily_total:
source: sensor.grid_energy_total
name: Grid Energy Daily Total
cycle: daily
grid_energy_monthly_total:
source: sensor.grid_energy_total
name: Grid Energy Monthly Total
cycle: monthly
grid_energy_returned_daily_total:
source: sensor.grid_energy_returned_total
name: Grid Energy Returned Daily Total
cycle: daily
not using the monthly meter, there just for observing. I found out that, even though you might put the energy meter in config.yaml manually, you should not write the corresponding template. Energy meter writes its own and, if you already have a sensor template, will write another template_2. Even if the first template is deleted from the yaml, the sensor remains. I haven’t found a way to delete it or rename the template_2. I’d like to know where the energy meter keeps its files.
The electric fee and tariff are in units of $, but the energy dashboard says the daily tariff and credit have to be in {currency}/kWh, so I used $/kWh. Not sure that’s correct due to earlier bad database entries, but it parses, at least. Because the energy dashboard polls once per hour (I think!), the daily fee is divided by 24 for each hour it’s polled. then the accumulated value for grid energy is multiplied by the tariff and added to the fee. Energy returned to the grid is handled in like fashion.
I will leave all this way and check the energy dashboard tomorrow. Comments and help welcomed.
Yes $/kWh is right. I missed that mine are actually like that when typing up sorry.
You need to remove the /24 from the supply as it will only ever add one 24th of the supply fee to the total.
Whether you use power all day or not you pay the full supply amount as soon as the day starts.
Also your Total daily credit should not include the supply fee.
You will note i have used total instead of total increasing. You need to do this for both sensors. This is because total increasing does not allow it to decrease which it will do at the start of each day.
You can purge you entire db by deleting it from the config folder. It will remove all history for all entities.
Regarding the old meter entities, it reside in config/.storage/core.restore_state
Edit this while the HA is stop (as it will write the entity back again if it still running), and make back if you are going edit it.
Thanks; the superfluous entity went away after I deleted the database. One more question about using the costs template in the energy dashboard. Should it be entered as “tracking the total costs” or “with current price”?
Following your existing settings above. If you choose…
Use a static price: 0.1342
(This is where you enter the known price)
Use an entity with current price: sensor.electricity_tariff
(This is where you have an entity with the tariff, in this case the one that you created, in some cases it taken straight from the provider if the provider supported in HA)
Use an entity tracking the total costs: sensor.total_daily_tariff
(This is where you have an entity with the total cost)
(Out of town for a few days) I have total daily tariff set as tracking the total costs, and total daily credit as showing current price. Both are wildly off the mark; at 1800 the grid energy total is 1.1 kWh and costs $0.15 while the energy returned is -6.41 kWh with a credit of $2.33! What can be going on? I’d sure like to know where utility meter keeps its files.
The utilities meter integration and the energy dash board are different, are you talking about the dashboard? The energy dashboard have the Day, week and month button top right. The utility_meter: cycle set as “daily” will reset daily.
To calculate those I have a 3 separate Daily, Monthly and Quarterly Utility Meter. The daily one will reset every day, it will not keep data beyond that.
You need to give more information. Nothing you have said indicates and error. Until you provide the sensor data and the prices/tariffs that are used plus your method for calculation and energy dashboard setup we are just guessing.
utility_meter:
grid_energy_daily_total:
source: sensor.grid_energy_total
name: Grid Energy Daily Total
cycle: daily
grid_energy_returned_daily_total:
source: sensor.grid_energy_returned_total
name: Grid Energy Returned Daily Total
cycle: daily
The amount of kWh being consumed and that being returned are calculated correctly, but the costs and credits shown in energy dashboard do not correspond with the tariffs and credits in the sensors. For example, here are the amounts for a recent hour period:
The template output of 1.14 is correct for the 4.65 kWh consumed so far today, but the energy dashboard is showing -0.85. Is the configuration of the energy dashboard grid consumption incorrect? It points to grid_energy_total and total_daily_tariff as an entity tracking total costs (screenshot above).
I’ll run and post again later to show the grid return and credit output.