Converting weekday to relative time (today, tomorrow)

My electric car estimates the end of charging and the integration presents these as a string of the time (03:36), and the weekday as a number (6 - Sunday in the example):

How can I jumble the current date, the endofchargetime and endofChargeTimeWeekday together to get me something like:

03:36 tomorrow

Thanks,

Thomas

thereā€™s not enough info here for me to get it so you can just pop it in, however this should get you 95% of the way thereā€¦ there may be a more efficient way, but i donā€™t know what that is so someone else may school meā€¦ but even if not most efficient, this should work

value: >- 
  {% set eoc_dow = state_attr( 'sensor.your_electric_car', 'endofChargeTimeWeekday')  %}
  {% set days_from_now = (eoc_dow - now().weekday() + 7) % 7 %}
  {{ state_attr('sensor.your_electric_car', 'endofchargetime') }}
  {% if days_from_now == 0 %}
    today 
  {% elif days_from_now == 1 %}
    tomorrow
  {% else %}
    {{ (now() + timedelta(days=days_from_now)).strftime('%A') }}
  {% endif %}

Thanks, that worked.

I tinkered around some on my own, came close to your solution, but missed the Jinja2 way of doing ā€œmoduloā€.

1 Like