Template error help

Hello,
Have a sonoff TH16 with temperature, humidity sensor and have problems with sensor updates. Want to make automation to check if update is more then x minutes.

above: '3'
entity_id: sensor.time
platform: numeric_state
value_template: '{{ (now() - states.sensor.10010b92da_h.last_updated).seconds / 60 }}'

this give me error: TemplateSyntaxError: expected token ‘)’, got ‘b92da_h’
tested automation with other entities and working great, but those “10010” from the entity name causing this error, any clues?

Try this in the template editor:

value_template: '{{ (now() - states.sensor.["10010b92da_h"].last_updated).seconds / 60 }}'

Why: https://www.home-assistant.io/docs/configuration/templating/#entity_id-that-begins-with-a-number

I’d suggest you rename that entity id to something a little more descriptive that does not begin with a number, before you start using it all over the place.

worked great, just removed the dot before the bracket like in documentation

value_template: '{{ (now() - states.sensor["10010b92da_h"].last_updated).seconds / 60 }}'

thanks a lot

1 Like

Good catch.