Please suppress Undefined Var errors until completes startup

Regarding HA 2021.4’s new feature: Warnings for undefined variables in Templates

I use a Lovelace decluttering_templates entry to render a high-level summary report to see any issues I should focus on. Variables are set to accumulate entities that have states I need to investigate.

During a HA restart, Lovelace reports not all entities will be available until HA Completes starting, but if any browser window is open, Lovelace starts rendering that decluttering_templates card, causing my log to fill with >15k lines of
Template variable warning: ‘None’ has no attribute ‘state’ when rendering

How do we deal with Lovelace’s insistence to start before things are ready, and template warnings, because things aren’t ready?


{% set unavailable_entities = 
      ( states | selectattr('state','eq','unavailable')
        | rejectattr("entity_id","eq","sensor.shelly_shrgbw2_662674_total_consumption")
        | rejectattr("entity_id","eq","var.upstairs_temperature_today_max")
        | rejectattr("entity_id","eq","var.downstairs_temperature_today_max")
        | list  ) %}

{% set unknowncount = (  (unavailable_entities | count ) + (unknown_entities | count )  ) %}

For any specific variable I define, like above, I added dummy value assignments, but it hasn’t helped at all. The error message doesn’t offer any clue as to which line in that 150-line template is failing.

Can we please have a way to prevent these checks before HA has started?

That’s an issue for the developer of the decluttering card to address.