Sensor name with zeroes is causing issues in template

Hello,

I have a sensor that has some hex address in its name and I’m trying to get this to work to create a binary sensor:

{{ (now() - states.sensor.000d5dxxxxxxxx_current_illumination.last_changed).seconds < 600 }}

This results in:

TemplateSyntaxError: expected token ')', got 'd5dxxxxxxxx_current_illumination'

I have determined part of the problem to be the zeroes (0) in the name of the sensor (If I remove them, the syntax error goes away), but I cannot for the life of me figure out how to prevent them from causing this issue. Is there a way to escape them?

Use bracket notation:

{{ (now() - states.sensor['000d5dxxxxxxxx_current_illumination'].last_changed).seconds < 600 }}
1 Like

Thanks! That works. (Guess I should trawl the docs manually rather than rely on Google to point me to the correct section.)