I’m trying to simplify an automation I’m using to create a weather display using the open epaper service. I’ve already got an automation going that updates the weather forecast every 20 minutes and it has been working fine. In that automation I hard coded all of the calls for the weekday, temps hi/low, icon and precipitation for all 6 days on the screen. I just change the day number for the forecast array and move the “x” position 50 px for each day. I am now trying to refactor it to be scalable using a for loop to loop through each day rather than copy/paste the same values for each day.
Below is just a sample of how I’m iterating through the weekday value and placing it on the screen by modifying the “x” position based on the iteration. This runs just fine in the developer tools → template. I can even copy the template output directly into Services and run it with no errors. However, If I try to run it in the services with the for loop in the services panel I get a very nondescript, “Service YAML contains syntax errors, please fix the syntax”.
If I comment out the for and endfor lines and replace the day variable with 0 and the x at 12 it works fine, so I think it can’t handle the loop. However I’ve see other people use loops successfully so before I just give up I wanted to check to see if anyone sees an obvious mistake.
service: open_epaper_link.drawcustom
data:
background: white
rotate: 0
payload:
{% for day in range(0,6) %}
- type: text
value: >-
{{ as_timestamp((state_attr('weather.home', 'forecast')[day].datetime)) |
timestamp_custom('%a') }}
font: ppb.ttf
x: {{12 + (50*day)}}
y: 30
size: 10
color: red
{% endfor %}
target:
entity_id: >-
open_epaper_link.0000027fff8b3b10