I’m not much of a programmer and require some help. I thought, this would be the best place to ask.
How would I go about formatting this array value so that it only displays the day of the week.
Here’s what I’m currently getting from the entity:
I would like to convert and format this value so that it only gives me the day of the week (Mon, Tue, Wed…).
Here’s the code:
- sensor:
- unique_id: weather
state: template
attributes:
weather: >
{% set d1_datetime = state_attr('weather.forecast_home', 'forecast')[-5]['datetime'] %}
{% set d1_condition = state_attr('weather.forecast_home', 'forecast')[-5]['condition'] %}
{% set d1_temperature = state_attr('weather.forecast_home', 'forecast')[-5]['temperature'] %}
{% set d1_templow = state_attr('weather.forecast_home', 'forecast')[-5]['templow'] %}
{{ d1_datetime }}
<font color='#6a7377'>
{{ d1_condition | title }},
</font>
{{ d1_temperature | title }}°C
<font color='#6a7377' size="2">
{{ d1_templow | title }}°C
</font><br>
I’ve used the following code to display the current weekday:
{% set weekday = now().strftime('%a') %}
{{ weekday }}
This gives me:
Sat
And the following code to display the current weekday as an integer:
{% set weekday_num = now().strftime('%w') %}
{{ weekday_num }}
This gives me:
6
But I’m having trouble, and wouldn’t know the syntax for creating a for loop that would add +1 to that integer while it is less than 7. If I’m able to do that I can then convert that integer to string format.
I pretty much want to display the days of the week and their forecast without having to use a weather card for a more uniform look and for custom flexibility. I’ve tried utilizing other weather cards to retrieve their attributes as some will contain the weekday as a string value but to no outcome.