So to be clear, the correct layout as dated now 11-12-2022 in configyaml should be right?
sensor:
- platform: template
sensors:
dag:
value_template: "{{ now().strftime('%A') }}"
maand:
value_template: "{{ now().strftime('%B') }}"
datum:
value_template: >
{% set suffix = ['st', 'nd', 'rd'] %}
{% set day = now().day %}
{% set index = 3 if day // 10 == 1 or day % 10 == 0 else (day % 10) - 1 %}
{{ day~'th' if index > 2 else day~suffix[index] }}
No wait, we needed entity_id: sensor.date so it updates everyday rigtht? Othewise it would’t update tomorrw. Or does it even when it is deprecated many versions ago?
that’s how it used to work, it’ll now update each minute when you use now(). YOu’re also using the old template format. You can still use it but you can also move to the new layout.
EDIT: This new format allows us to add triggers to it, so it’ll update when the trigger happens. You can also add another trigger to it so that it updates on home assistant restart.
Dear Petro, thanks, that works! > CURRENTLY TESTING OUTSIDE TEMPLATE EDITOR
Could you be so kind to point me how to offset the day? I’d like to make 14 additional sensors showing each displaying one day back. I tried
now().day-1
for example, but that seems not to be supported anymore. I’m confused wher to find this offset information.
Searching the forum for “ordinal” produced many results but (almost) none using the word as a Jinja filter. However, it’s used as a filter in this two year-old post (where it’s author states he got it from discord … so possibly from a developer). What I haven’t done is search Github to determine when, exactly, it was introduced. Anyway, it’s been undocumented for quite awhile.
and my config checker says:
Configuration invalid!
Error loading /config/configuration.yaml: while parsing a block mapping
in “/config/configuration.yaml”, line 671, column 5
expected , but found ‘,’
in “/config/configuration.yaml”, line 672, column 40
Error loading /config/configuration.yaml: while parsing a block mapping
in “/config/configuration.yaml”, line 671, column 5
expected , but found ‘,’
in “/config/configuration.yaml”, line 672, column 40
Geeze I was chasing a browser-error gost. That error keeped popping up nomatther what I did, needed a big browser refresh. Dunno why. So the final code i’m using is below. Works in template editor, only thing in practical the state is “unknown”…wait tell me it will only fill in the states tonight at 00:00 right? In the previous “old” example it worked right away…
Yes, it will only calculate at midnight. Remove the trigger to have it calculate every minute. If you remove the trigger, make sure you put a - in front of the sensor line.
Good afternoon, my apologies I’m new to home assistant and would love to implement your exact code. This is exactly what I’m looking for. Would you mint guiding me through the steps to implement this please?
please always use preformatted text when pasting code, so the quotes don’t get all screwed up (also tabs are preserved).
It’s a PITA to copy the code and replace them all manually