But how did you update that ?
I had used this yesterday and had a value of 165 days or so and today this should have increased to 166 , but it has not.
I like the clean formula but how can i make sure that it updates at midnight ?
But how did you update that ?
I had used this yesterday and had a value of 165 days or so and today this should have increased to 166 , but it has not.
I like the clean formula but how can i make sure that it updates at midnight ?
I made custom template macros that do this. Just use that
Thanks, I will try this tonight !
might be worth to update the documentation cause the first line seems to be so easy, right
{%- set default_language = 'en' %}
But in case of germany I have seen 2 versions
ge for german
and
de for the german word of german which is deutsch
Most recently I have seen more and more “de” but still not sure cause internationally not many know about de = german.
Therefore I would suggest to start each language line with the key, its meaning and its translator like here where I have moved germany up cause I have no clue about the other languages like dutch which can be “nl” or maybe “du”
The current supported languages are:
Does not belong here but i did not wanna open an issue for such simple question.
I have now started with de cause I followed the german translator on his github side and there I found this project and a “de” quite in the beginning.
But can not say if that is right or not, cause I have not tried out, just installed it via hacs.
UPDATE: OK, got it.
I also suggest to change this line and insert
After installation you can edit the first line
of easy_time.jinja
in config\custom_templates\
to set a default language, this will make the macros easier to use in your native language.
Then I would have instantly know where I have to check the line and see the available languages and acronyms. thx
Hello petro,
I do not really know what the term macro means.
I had thought script but it does not feel right.
so I have tried this in the template engine to get the number of days between now and back then in autumn 2023 when the heating season had started.
But the template did not like it.
{{% from 'easy_time.jinja' import easy_time_between %}}
{{ easy_time_between( (as_timestamp(now()) , as_timestamp('2023-10-12 00:00:00')) }}
I wanted to use the result in a sensor heating_days
Right now I am using this as a sensor but that did not update tonight:
{{ (as_timestamp(now()) - as_timestamp('2023-10-12 00:00:00') ) | timestamp_custom("%j") | int }}
Hope you have a solution to get the days updated at midnight.
thx
I made easy time to be easy
{% from 'easy_time.jinja' import easy_time_between %}
{{ easy_time_between(now(), '2023-10-12 00:00:00') }}
{% from 'easy_time.jinja' import count_the_days %}
{{ count_the_days('2023-10-12 00:00:00') }}
FYI count_the_days starts from midnight to midnight, not including the hours in today. If you want the hours including todays hours, you’ll have to add one to the result. Anything in relation to midnight of today is considered 0 days.
EDIT: The result will be negative BTW because it’s in the past.
Yes, that has worked out when I pasted your code into the template engine and then used it in the sensor configuration.yaml
this way even though I had been unsure in the beginning and read a lot about the 2023.4 HA release and reuseable macros till I understood that your solution was not about reuseable macros. So I put it in the configuration.yaml sensor
template:
- sensor:
- name: "HEIZPERIODE DAUER"
unique_id: "heizperiode_dauer"
unit_of_measurement: "days"
icon: "mdi:counter"
state_class: "measurement"
state: >-
{% from 'easy_time.jinja' import count_the_days %}
{{ ( count_the_days('2023-10-12 00:00:00') | float ) * -1 }}
and that is how I got the right amount of days.
Even though your solution had caused a far better result cause we had -900 Liter and -310€ instead of 900 Liter oil consumption and 310€ total cost for heating the house this heating period so far.
And yes, we got the oil cheap , bought at the lowest prices point in the past 10 years at end of Sept. 2020 for 36 cents / liter - therefore heating is still cheap till the 6600 liters will be gone.
Thanks a lot , has worked out great and in case of any time operations I will check your documentation first. And yes, a time from 01 am to 23 pm means 0 days cause midnight will be the counter for day 1 . In our case not so important, but good to keep in mind how it counts.
I would also suggest to add at least 1 of such template sensor examples to the documentation cause it would have helped me a lot when I was looking through the whole document unsure how to use it . I had used the second line before for sensors but never seen or used the first, the import line.