caspix
(Kjetil)
1
I have a sensor that outputs when the postman delivers mail. The sensor outputs ex: “Tomorrow, Friday 28. April”
Is there a way with template to shorten this to just take the weekday?
This is what I have so far (the else part is what I need help with):
{% set today = 'i dag' in states('sensor.posten_sensor_next') %}
{% set tomorrow = 'morgen' in states('sensor.posten_sensor_next') %}
{% if today == true %}
Post today
{% elif tomorrow == true %}
Post tomorrow
{% else %}
{{states('sensor.posten_sensor_next') }}
{% endif %}
Hi @caspix
I think we may need to see more examples of what sensor.posten_sensor_next
can return.
There are many ways to split the output up. You could try:
states('sensor.posten_sensor_next').split(',')[1]
to get the text after the comma. Then
states('sensor.posten_sensor_next').split(',')[1].split(' ')[0]
to get the first word after the comma.
I haven’t tried my code for real so it may not work.
caspix
(Kjetil)
3
This looks good, but maybe I have been thinking wrong. The sensor can output the following;
“I dag torsdag 27. april”
“I morgen fredag 28 april”
“Mandag 1 mai”
“Tirsdag 2 mai” .etc (The names are the Norwegian names for the weekdays)
So maybe what’s needed here is to look for “Mandag or Tirsdag or Onsdag” etc and post which day it finds since the weekday name is always included…