Skip to content
jwmaas edited this page Oct 29, 2023 · 2 revisions

With the new API, Bosch component can inject values into the HA DB to be used in the Energy Dashboard, however, you cannot view them from the UI and manipulate those values. To create a utility sensor, HA needs a cumulative spending sensor.

This approach lets you create a cumulative total spending sensor to be used on the frontend by getting values directly from the DB with SQL sensors.

Requirements:

  • MariaDB needs to be set up and working.
  • You need to enable the New API of the Bosch component.

You need to create two sql sensors each corresponding to the energy:echenergy_central_heatingexternal and energy:ehwenergy_hot_waterexternal.

Sensor 1:

Database URL: your database URL starting with mysql://

SELECT Query: SELECT sum FROM statistics WHERE metadata_id = ( SELECT id FROM statistics_meta WHERE statistic_id = "energy:ehwenergy_hot_waterexternal" ) ORDER BY id DESC LIMIT 0, 1

Column: sum

Unit of Measure: kWh

Value Template: {{ value | float("unavailable") | round(2) }}

Sensor 2:

Database URL: your database URL starting with mysql://

SELECT Query: SELECT sum FROM statistics WHERE metadata_id = ( SELECT id FROM statistics_meta WHERE statistic_id = "energy:echenergy_central_heatingexternal" ) ORDER BY id DESC LIMIT 0, 1

Column: sum

Unit of Measure: kWh

Value Template: {{ value | float("unavailable") | round(2) }}

Now that the sensors are created, they need to be assigned proper classes. This can be done by using the customize.yaml https://www.home-assistant.io/docs/configuration/customizing-devices/

just add below attributes:

device_class: energy
state_class: total_increasing

Then, you can create monthly utility sensors, billing and so on.