I have a sensor that send the kWh i have left on my prepay meter as well as the 1min. average usage.
The data is send to HA once every minute where the sensor count the “red” led flashing, 1000 counts /kWh, and subtract it from the value i load into the sensor.
I update the sensor kWh value from the prepay meter reading every time i buy electricity.
How do i implement a “sensor” that will estimate when my kWh value will reach either zero or close to zero based on by 1min. average usage for me to buy electricity before i run out?
That part i understand, should have indicated so, i am not sure how to create a "template sensor that does that.
I have not done a “template” sensor, so i must be missing something…
template:
- sensor:
- name: "Time to ZERO kWh"
unit_of_measurement: "h"
state: {{ (Remaining kwh / 1min Avarage) }}
It seems that i am still doing something wrong.
As i mentioned above, i do not see the sensor in the entries, so i presume my formatting is wrong.
Here is my config file:
Yes, sorry i just did a copy / paste and changed the values without looking at it.
But i think that is not my issue.
If the state calculation is wrong, i should at least see the “sensor” but with a error value or zero value.
I am not able to see the sensor at all, so i need to resolve that issue 1st and then look at the sensor value.
With that backtick there, the template is invalid syntax preventing the sensor from being created, and there will be an error in the logs. Fix that, reload template entities and your sensor should appear.
Hi Troon
I did update the syntax
I do not have any errors in the log file?
I only see errors from yesterday when i had indent issues.
In the file editor, the tick is green - when i reload the config file i do not get any notification and the log file do not show any error.
I thougt i would at least see a sensor.time_to_zero_kwh with some error.
But i do not, even when i remove the “state:” line from the config.
So, somewhere in the config file i am doing something stupid
I can’t see anything wrong with that — my next step would be to align the template section indenting to the documentation (just move the - sensor: two spaces left):
template:
- sensor:
- name: "Time to ZERO kWh"
unit_of_measurement: "h"
state: "{{ states('sensor.remaining_kwh')|float / (states('sensor.1min_avarage'))|float }}"
…although this shouldn’t make a difference. I assume you have restarted HA / reloaded template entities?
For anyone else that is interested in doing something similar, here is the script.
From this i get hours remaining and days remaining before i get to zero based on the current rate.
Next is to use consumption per day or week to get a more realistic value.
template:
- sensor:
- name: "Time to ZERO kWh"
state: "{{ (states('sensor.remaining_kwh')|float / (states('sensor.1min_avarage')|float) *1000) | round(2) }}"
unit_of_measurement: "hrs"
- name: "Days to Zero kWh"
state: "{{ ((states('sensor.remaining_kwh')|float / (states('sensor.1min_avarage')|float) *1000) / 24) | round(0) }}"
unit_of_measurement: "Days"
I would love to know how you setup the KWH remaining. I already have a pulse counter implemented and can read my current consumption. I also have the “Energy” dash board setup using this. I would love to be able to enter my current units and have home assistant work out what is left. Could you please share? Thanks
At the time i was using an ESP8266 that was, counting the pulses and sending the 1min_average as well as the remaining kWh.
The kWh reading was derived from the value i manually entered into the ESP8266 via a web interface.
The ESP8266 subtracted the “Pulses” from the kWh i manually entered and then fed “Remaining kWh” via mqtt to HA.
I have stopper using the “Remaining kWh” until i can resolve some power issues as we have frequent power outages in South Africa due to a lack of capacity from our State owned Electricity supplier.