dwainscheeren / dwains-dashboard-addons

Dwains Dashboard Community Addons
118 stars 75 forks source link

Error when using templates in more_page addon #124

Closed lukastillmann closed 3 years ago

lukastillmann commented 3 years ago

I recently added the vacuum rooms page and was really happy to see I could use templates like this to loop over some data

https://github.com/dwainscheeren/dwains-dashboard-addons/blob/master/rooms/vacuum/page.yaml

However, I tried to do the same with a more_page for a custom radio player and got this error:

while scanning for the next token found character '%' that cannot start any token in "/config/dwains-dashboard/addons/more_page/radio/page.yaml", line 4, column 4

I basically copy pasted this yaml, so I don't know why this is not working. Is there a difference in the way, the Dashboard handles rooms versus more_page addons?

- type: custom:dwains-flexbox-card
  items_classes: 'col-xs-12 col-sm-6 col-sm-6'
  cards:
  {% if (data | fromjson)['stations'] %}
    - type: custom:dwains-flexbox-card
      padding: true
      cards:
        - type: custom:dwains-heading-card
          item_classes: 'col-xs-12 col-sm-12 col-md-12 col-lg-12'
          title: Radio
        - type: custom:select-list-card
          entity: input_select.radio_player
          title: Player auswählen
      {% for station in (data | fromjson)['stations'] %}          
        - type: custom:button-card
          item_classes: 'col-xs-6'
          template: radio_player
          entity: input_boolean.dummy1
          name: {{ station.name }}
          icon: mdi:radio
          show_state: false
          show_last_changed: false
          tap_action:
            action: call-service
            service: media_player.play_media
            service_data:
              entity_id: >
                {% if is_state("input_select.radio_player", "WOHNUNG") %} media_player.wohnung
                {% elif is_state("input_select.radio_player", "KUECHE") %} media_player.kueche
                {% elif is_state("input_select.radio_player", "WOHNZIMMER") %} media_player.wohnzimmer
                {% else %} media_player.kueche
                {% endif %}
              media_content_type: 'audio/mp4'
              media_content_id: {{ station.url] }}
          styles:
            grid:
              - grid-template-areas: '"i n"'
            icon:
              - width: 25px
              - height: 25px
      {% endfor %}     
    - type: custom:dwains-flexbox-card
      padding: true
      cards:
        - type: custom:dwains-heading-card
          item_classes: 'col-xs-12 col-sm-12 col-md-12 col-lg-12'
          title: Steuerung
        - type: custom:button-card
          item_classes: 'col-xs-6'
          template: room_climate_info
          entity: input_boolean.dummy1
          name: Radio Starten
          icon: mdi:radio
          show_state: false
          show_last_changed: false
          tap_action:
            action: call-service
            service: script.radio_start
          styles:
            grid:
              - grid-template-areas: '"i n"'
            icon:
              - width: 25px
              - height: 25px                 
  {% endif %}
Klumpke commented 3 years ago

You need to have # dwains_dashboard in the first line of your page.yaml file.

lukastillmann commented 3 years ago

Thanks so much! I actually tried adding some comment at the top, but didn't think of copying the whole line ^^

I still have an error, because of using home assistant jinja2 templates. I guess I don't have access to entity states in here?

dwainscheeren commented 3 years ago

You can escape it with

{% raw %}
  - type: markdown
    content: |
      # Coming soon(?)

      A built-inmarkdown card with jinja templating.
      So I can tell that my light is {{ states('light.bed_light') }}!
{% endraw %}
lukastillmann commented 3 years ago

Awesome, thanks!