DBuit / Homekit-panel-card

Homekit panel card for home assistant
MIT License
304 stars 54 forks source link

markdown as rules? #26

Closed sauloonze closed 4 years ago

sauloonze commented 4 years ago

Is there a way to add the markdown coding into the rules attribute? Something like:

        rules: >
          <li>{% if now().hour  < 5
          %} Good Night {{'\U0001F634'}}
              {% elif now().hour < 12 %} Good Morning {{'\u2615\uFE0F'}}
              {% elif now().hour < 18 %} Good Afternoon {{'\U0001F44B\U0001F3FB'}}
              {% else %} Good Evening {{'\U0001F44B\U0001F3FB'}}
              {% endif %}</li>
          {% if "not_home" in states('person.saulo') %} <li>Saulo is out.</li>
          {% endif %} {% if "not_home" in states('person.olga') %} <li>Olga is
          out</li> {% endif %}

          {% if states('sensor.current_lights_on') | float > 0 %}
          <li>{{states('sensor.current_lights_on')}} lights on</li> {% endif %}

          {% if states('sensor.current_media_players_on') | float > 0 %}
          <li>{{states('sensor.current_media_players_on')}} speakers on</li> {%
          endif %}
DBuit commented 4 years ago

Hi @sauloonze, the rules uses the templating of home assistant not sure if it is the same as markdown. Here you have the documentation i think what you have as example should be possible.

https://www.home-assistant.io/docs/configuration/templating/

sauloonze commented 4 years ago

I couldn't run it using the custom card but It worked when run as templating. Not sure how to debug it.

DBuit commented 4 years ago

@sauloonze i think i found the problem. So the <li> and </li> and everything in between must be on 1 line. So for the goodmorning part you should add this line under rules

<li>{% if now().hour  < 5 %} Good Night {{'\U0001F634'}}{% elif now().hour < 12 %} Good Morning {{'\u2615\uFE0F'}}{% elif now().hour < 18 %} Good Afternoon {{'\U0001F44B\U0001F3FB'}}{% else %} Good Evening {{'\U0001F44B\U0001F3FB'}}{% endif %}</li>

i will see if i can fix it so it does not need to be on 1 line.

DBuit commented 4 years ago

@sauloonze just released new version of the card with a fix so it should render your configuration that is not on 1 line

sauloonze commented 4 years ago

Thanks!