I have setup a trasportation sensor that allows me to monitor some attributes. I want to create a template sensors that take an attributes in time format (the time of train arrival, for example 19:00) and make a math operations: reduce the value by 10 minutes, something like this:
I copied and pasted your code but I receive an error:
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected char ‘“’ at 72) for dictionary value @ data[‘sensors’][‘next_train_arrival’][‘value_template’]. Got ‘{% set hour, minute = states.sensor.frecciarossa_delle_1845.attributes [“compOrarioPartenzaZeroEffettivo”].split(“:”) %} {% if now().hour == hour | float and now().minute == minute | float %}\n on\n{% else %}\n off\n{% endif %} \n’. (See ?, line ?). Please check the docs at Template - Home Assistant
I take this opportunity to better explain my goal:
The train sensor has attribute only the arrival time for the final destination (the last station). But I need to visualize the arrival time to another station that is more or less 10 minutes before the last one.
So if the compOrarioArrivoZeroEffettivo is 19:00 my goal is to create a sensor that shows 18:50. Is this possible?
try replacing all double quotes with single. Make sure the character is not copied from microsoft word, because they use the forward/backward quotes. This needs to be the normal quote.
But I can see only the status as on or off…not the time minus 10 minutes…I know I miss something…but I’m a total noob regard templating…What should I do?
It’s simple math man. How many seconds are in a minute? How many minutes are in an hour? My niece just learned this in 7th grade, you can do it if you are working with home assistant.
That’s your first problem. The code placed in yaml files is not yaml, its Jinja. Yaml is the format, like xml. Jinja is the for loops, if statements, and overall object use inside the templates.