Last state sensor ,but without correct time-zone

  • Hello I create this sensor , it’s working ,but time is showed without correct time-zone , in my case is’t +2 hrs
  • how can I change name of days genatate by strftime(‘%A’) ?
    Thank you.
sensors:
  ## One For Each Device
  okno_emma_on2:
    friendly_name: novy format 
    value_template: >
      {%- set last_changed = states.binary_sensor.dvere_vchod_zamek_contact.last_changed %}
      {% if last_changed < today_at() - timedelta(days=6) %}
       týden +
      {% elif last_changed < today_at() - timedelta(days=1) %}
      {{ last_changed.strftime('%A v %H:%M')}}
      {% elif last_changed < today_at() %}
      {{ last_changed.strftime( 'Včera v %H:%M')}}
      {% else %}
      {{ last_changed.strftime('Dnes v %H:%M') }}
      {% endif %}

Copy-paste the following template into the Template Editor and confirm it reports the correct date, time, and timezone offset.

{{ now() }}

If it’s not correct, go to Settings → System → General and ensure Time Zone is set correctly.

You can’t. It is exclusively in English.

You will need to use a template to report the day name in your preferred language (which I believe is Czech).

Here’s an example:

{{ ['Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota', 'Neděle'][now().weekday()] }}
{{ now() }} result 2024-04-23 05:33:10.915962+02:00

So I found the way.

{%- set last_changed = states.binary_sensor.okno_kuchyn_contact.last_changed %}
{% if last_changed < today_at() - timedelta(days=6) %}
{{ as_timestamp(states.binary_sensor.okno_kuchyn_contact.last_changed, default=0)| timestamp_custom("%d.%m v %H:%M") }}
{% elif last_changed < today_at() - timedelta(days=1) %}
{{ ['Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota', 'Neděle'][now().weekday()] }} {{ last_changed | timestamp_custom('%H:%M', true)}}
{% elif last_changed < today_at() %}
{{ as_timestamp(states.binary_sensor.okno_kuchyn_contact.last_changed, default=0)|timestamp_custom('včera v %H:%M', default=0) }}
{% else %}
{{ as_timestamp(states.binary_sensor.okno_kuchyn_contact.last_changed, default=0)|timestamp_custom(' %H:%M', default=0) }}
{% endif %}

I know, this isn’t clear code but working.

It’s the custom of this community forum to assign the Solution tag to the post that offers the Solution. That would be this post, because it explained strftime only reports in English and provided you a template to convert to Czech.

Guideline 21 in the FAQ

1 Like