I´ve got a template sensor telling me when it was last vacuumed. Is there a way to change the language of the day and month to norwegian?
- platform: template
sensors:
siste_stovsuger_start:
friendly_name: 'Sist gang støvsugd'
value_template: '{{ (as_timestamp(states.sensor.roborock_vacuum_a15_last_clean_start.last_changed)) | timestamp_custom("%A, %d. %B %H:%M") }}'
Gives me:
Monday, 05. December 17:22
and I would like
Mandag 05. Desember 17:22
kolia
3
I was under the same impression, apparently it is not. You may adapt this snippet to achieve your goal (same idea for months)
template:
- sensor:
- name: jour_fr
unique_id: 9dd5782d-83c4-401c-afcf-5cd83232bde7
state: >
{% set jour = ["Dimanche", "Lundì", "Mardì", "Mercredì", "Jeudi", "Vendredì", "Samedi"] %}
{% set jour = jour[now().weekday()] %}
{{jour}}
1 Like
So with this one I can use it to give me when an automation was last triggered:
{% set t = state_attr('automation.automatisk_lys_bad_2_etg', 'last_triggered') %}
{{ "%s %d. %s kl %02d:%02d" %
(["Mandag","Trisdag","Onsdag","Torsdag","Fredag","Lørdag","Søndag"][t.weekday()],
t.day,
["Januar","Februar","Mars","April","Mai","Juni","Juli","August","September","Oktober","November","Desember"][t.month-1],
t.hour,
t.minute) }}
But how can I make the same thing work with a sensor or light, which doesn’t have the attribute “last_triggered”?
Entities have a last_changed
property that can be accessed using the state object:
{{ states.light.kitchen_light.last_changed }}
Tried this:
{% set t = states('roborock_vacuum_a15_last_clean_start.last_changed') %}
{{ "%s %d. %s kl %02d:%02d" %
(["Mandag","Trisdag","Onsdag","Torsdag","Fredag","Lørdag","Søndag"][t.weekday()],
t.day,
["Januar","Februar","Mars","April","Mai","Juni","Juli","August","September","Oktober","November","Desember"][t.month-1],
t.hour,
t.minute) }}
Just gives me:
UndefinedError: 'str object' has no attribute 'weekday'
You used the states()
function instead of the state object method I showed in my previous post… and your entity is missing its domain.
{% set t = states.sensor.roborock_vacuum_a15_last_clean_start.last_changed %}
{{ "%s %d. %s kl %02d:%02d" %
(["Mandag","Trisdag","Onsdag","Torsdag","Fredag","Lørdag","Søndag"][t.weekday()],
t.day,
["Januar","Februar","Mars","April","Mai","Juni","Juli","August","September","Oktober","November","Desember"][t.month-1],
t.hour,
t.minute) }}