andrey-git/home-assistant-custom-ui

how to format the customize for sensor.moon _stateDisplay

Mariusthvdb opened this issue · 1 comments

Checklist

  • I'm running the latest version of CustomUI (Update guide) or using a specific release that is not marked as "Broken".
  • I tried to force-refresh (Ctrl+Shift+R / Ctrl+F5) the browser
  • (Optional, but recommended) I'm using Chrome or tried to reproduce the feature on Chrome.

Browser + Version:
Safari on Mac

CustomUI version:
20180831
Home Assistant release (hass --version):
0.81.6
Problem-relevant configuration.yaml entries:

    sensor.moon:
     templates:
       _stateDisplay: >
         return state|title|replace('_',' ');

please see https://community.home-assistant.io/t/strange-different-template-behavior-between-hassio-instances/77444

I am trying to change the regular display of these 2 sensors in a capitalized way (only cap the first character of the state, and remove the _ and replace that with a space.

Somehow my 2 systems with the exact same sensor, show differently. I know now that my above customization isn't correct, as explained i the community thread by @petro and shown in the inspector, but I can't get the correct format for it.

regular template would be:

{{states('sensor.moon').capitalize().replace('_',' ')}}
and
{{ states('sensor.season').capitalize() }}

please let me know how to adapt that for custom-ui.

Problem-relevant Home Assistant log entries:


adc112eeec674a9607b11fbf4b5b80cc0b35ac89

Any errors from browser Javascript console:


answering myself and for reference:

    sensor.moon:
      templates:
        _stateDisplay: >
          function capitalizeFirstLetter(string) {return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();}
          string = state.replace('_',' ');
          return capitalizeFirstLetter(string);