How to add a guard in this JS template

the new loading of HA 111, causes errors when an not yet initialized entity is used as source for a customization of another entity (6-700 lines of the identical error is a bit much )… I’ve managed to take out most of the culprits by adding a guard in the existence of the entity, but now ask you help in this particular template:

      icon: mdi:weather-windy
        icon_color: >
          var bft = entities['sensor.wind_bft'].state;
          var mapper = {'0':'lightblue',
          return mapper[bft] ? mapper[bft] : 'crimson';

I would have thought the bottom line would guard against any non existing ‘bft’ but apparently that doesnt suffice, since this is what I see in the startup log:

2020-06-11 11:27:01 ERROR (MainThread) [frontend.js.latest.202006032] https://redacted/local/lovelace/resources/custom-ui/custom-ui.js?v=20200528-1:31:37215 TypeError: undefined is not an object (evaluating 'entities['sensor.wind_bft'].state')

would I need to change anything in the first line too?


var bft = entities['sensor.wind_bft'].state if (entities['sensor.wind_bft']) else '0' ;

I’ve tried to use this same issue and solution but no luck just yet.

          var bft = entities['sensor.wind_bft'] ? entities['sensor.wind_bft'].state : '0' ;

gives errors in inspector.

ha, this fixed it after all, had another restart for the customization to be correctly parsed.
answering myself here to toggle the fix button.