Hi!
I’m trying to setup a sensor that shows % energy used compare to yesterday, last week, last month and last year. The math i can solve but i can’t get it to work in a template.
To get the right value I need to divided the energy value from yesterday with the hour, number of days, days in the month and days in the year to get a value that is reliable.
This is my template for the day but i don’t get the right value. Can I get som help to set up a template that givs my a valut if i use more och less % energy compare to last day.
Thanks, but when i calculate the % in a calculator I get different value. In my calculator it says 34 % but with the template I get 39%. Is the math right in the template?
The calculation is going to have some error because you’re 3/4th of the way through the hour. You could just forgo using the current hour and just get the percentage.
I did that before. My aim is to get a value that is reliable for the current hour. Therefore I divided with 24 and multiple with current hour. When I do that I get a better value for the current hour.
I can live with som error in the value. Thanks for the template code.
Hi! I can’t get next mission right. My aim is to calculate how many hour that has past this week. Can you help me?
{% set week = states('sensor.energy_in_week') | float %}
{% set last_week = states('sensor.energi_senaste_vecka') | float %}
{{ ((week / (last_week / **HOUR THAT HAS PAST THIS WEEK** | round }}