Templates UndefinedError: 'None' has no attribute 'state' error at boot

On HA boot, i get a few template error:

16-12-24 02:36:54 homeassistant.components.sensor.template: UndefinedError: 'None' has no attribute 'state'
16-12-24 02:36:54 homeassistant.components.sensor.template: UndefinedError: 'None' has no attribute 'attributes'
16-12-24 02:36:54 homeassistant.components.sensor.template: UndefinedError: 'None' has no attribute 'attributes'
16-12-24 02:36:54 homeassistant.components.sensor.template: UndefinedError: 'None' has no attribute 'state'

Any way to properly debug the problem?

Edit: Original problem was most likely not linked to this errors.

You’re testing an attribute of a sensor before it exists. This won’t break anything, but it will generate errors. Wrap it in an “if” that checks for the existence of the entity first. Like

value_template: '{% if states.remote.livingroom.state %}{{ states.remote.livingroom.attributes.current_activity }}{% endif %}'

1 Like

Thank you for answering!

How should i add the IF to this template:

"{% if is_state('device_tracker.tplink_router', 'home') %}Online{% else %}=OFFLINE={% endif %}"

If I’m not mistaken, is_state shouldn’t error like this. Are you sure that’s where you’re getting the errors from? That log mentions attributes of “attributes” and “state”. Rather than failing (before the tracker exists) the value for that template would be “=OFFLINE=”