Home Assistant - Energy Dashboard - Part 2

In this part we'll look how to add standing charges to the total cost and how to correct readings from device that only outputs wH.


Meross Plug Energy Correction

So as I said in Part 1, the Meross plugs I have don't output a kWh reading, only in wH. All we have to do is create a bank of template sensors for each one and divide the reading 1000 which will result in the kWh reading. These plugs don't have a ENERGY Yesterday sensor built in either, it's possible to get HA to calculate it if you wish. I haven't bothered as they'll all be replaced for Tasomata plugs in the coming weeks.

The wh reading is named sensor.attic_auxiliary_energy,  we then use the template sensor named attic_auxiliary_energy_kwh to perform the division sum, do this for each device.

## Meross Plug Kilowatt Correction from wH

      - platform: template
        sensors:
          attic_auxiliary_energy_kwh:
                friendly_name: "Attic Auxiliary Energy"
                unit_of_measurement: 'kWh'
                value_template: "{{ (states('sensor.attic_auxiliary_energy') | float / 1000) }}"

      - platform: template
        sensors:
          port_lamp_energy_kwh:
                friendly_name: "Port Lamp Energy"
                unit_of_measurement: 'kWh'
                value_template: "{{ (states('sensor.port_lamp_energy') | float / 1000) }}"

Total Cost Card

First of all we want to create a template sensor for the standing charge which in my case is £0.25 (due to double in the coming months!).

      - platform: template
        sensors:
          price_standing_charge_daily:
                friendly_name: "Price Standing Charge Daily"
                icon_template: mdi:currency-gbp
                unit_of_measurement: '£'
                value_template: "0.2500"

Now we want to sum together the total costs for previous day, daily, weekly and monthly. In my case I already know what the totals are for my equipment which is divided up between the Server Gear & Battle-Station as we set these up in Part 1.

Time to create another bank of four template sensors!

For the previous day and today figure we just add the standing charge sensor to the already totalled sensors for both sets of equipment. Weekly and Monthly are slightly different as we need to multiply the daily charge by 7 & 28 respectively, then add the totalled sensors for both sets of equipment.

## Cost Senors
## Totals for energy card

      - platform: template
        sensors:
          total_cost_yesterday:
                friendly_name: "Total Cost Yesterday"
                icon_template: mdi:currency-gbp
                value_template: "{{ (states('sensor.cost_server_devices_yesterday_power') | float +
                                                        states('sensor.cost_monitored_devices_yesterday_power') | float +
                                                        states('sensor.price_standing_charge_daily') | float) | round(2)  }}"


      - platform: template
        sensors:
          total_cost_daily:
                friendly_name: "Total Cost Daily"
                icon_template: mdi:currency-gbp
                value_template: "{{ (states('sensor.cost_server_devices_daily_power') | float +
                                                        states('sensor.cost_monitored_devices_daily_power') | float +
                                                        states('sensor.price_standing_charge_daily') | float) | round(2)  }}"


      - platform: template
        sensors:
          total_cost_weekly:
                friendly_name: "Total Cost Weekly"
                icon_template: mdi:currency-gbp
                value_template: "{{ (states('sensor.price_standing_charge_daily') | float * 7 +
                                                        states('sensor.cost_monitored_devices_weekly_power') | float +
                                                        states('sensor.cost_server_devices_weekly_power') | float) | round(2)  }}"



      - platform: template
        sensors:
          total_cost_monthly:
                friendly_name: "Total Cost Monthly"
                icon_template: mdi:currency-gbp
                value_template: "{{ (states('sensor.price_standing_charge_daily') | float * 28 +
                                                        states('sensor.cost_monitored_devices_monthly_power') | float +
                                                        states('sensor.cost_server_devices_monthly_power') | float) | round(2)  }}"

Remember to check the .yaml as we did before in the Developer tools before rebooting HA!

The next part is easy, create a new entity card on the dashboard and add the new totalled template sensors to it. This can be done in the GUI as it's a simple table card and you can use the sensors "friendly name".

Not Included Card

This card exists purely for keeping an eye on some low powered devices. It is not included in the total cost card mainly because there's hardly any usage . Like the total cost card above it's a simple entity card with the plugs kHw usage, which we made at the start of this tutorial, and the current wattage. As you can see it's barley measurable, note this is for a 24hr period.


After publishing I've been made aware this is the legacy method of making templates, they still work and will continue to work for sometime yet I would imagine. Post 3 will probably detail how to convert the current templates to the new method.