Have an electric heater controlled through MQTT in HA.
They are basic switches with reporting of 0 and 1 for on/off.
As i know their energy consumption (700w) i would like to calculate their hourly/daily usage. Seems it cannot be done with HA directly. Installed influxdb with grafana but seems i cannot do that either (if possible maybe a hint?)
So which history component i should use for that?
You should be able to do it with the History Statistics Sensor. https://home-assistant.io/components/sensor.history_stats/
Time on per day * power = energy per day.
Two options:
A)
Start with this to calculate time on
:
Then create a template sensor where you multiply the result(s) of the above mentioned component with your 0.74kW.
e.g. for yesterday
- platform: history_stats
name: Heater ON yesterday
entity_id: sensor.heater
state: '1'
type: time
end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
duration:
hours: 24
and the template sensor:
energy_heater_yesterday:
value_template: '{{ states.sensor.heater_on_yesterday.state | multiply(0.74) | round(2)}} kWh'
friendly_name: 'Heater yesterday kWh'
B)
You mentioned Grafana. I assume you also have InfluxDB.
Do your aggregations using a combination of template sensors (some math inside) and InfluxDB sensors:
However, since you are not reading kWh or kW directly I recommend option A.
For me the sensor returns a wrong value with your solution.
I used:
{{ (states.sensor.motor_on_today.state | float * 0.7 ) | round(2) }}
The value 0.7 means the 700W device.
Feel free to correct me if I’m wrong.
Any way to get this value into Energy Dashboard?