A different take on designing a Lovelace UI

Hi Ben,

could you provide some details on the media card? Code?

is the popup printer animation empty too?

Can someone please help me understand how I set up the different screen resolution, our iPhones always choose the default layout instead I want our iPhone to use the phone layout, Hope you understand what I mean and can help me​:blush::blush:

Hi
I would like to use sensor.template_update to log new OS and new supervisor versions
I removed everything about esphome, kemperprofiler, …
This is my new code

      - unique_id: updates
        state: >
          {% set ns = namespace() %}
          {% for k, v in this.attributes | dictsort(by='value') %}
            {% set ns.list = ns.list + [v] if v != '' else [] %}
          {% endfor %}
          {{ ns.list | count }}
        attributes:
          supervisor_update: >
            {% set installed = state_attr('update.home_assistant_supervisor_update', 'installed_version') %}
            {% set latest = state_attr('update.home_assistant_supervisor_update', 'latest_version') %}
            {% set url = 'https://github.com/home-assistant/supervisor/releases/tag/' %}
            {% if installed != latest %}
              <b><a href="#" onclick="window.open('{{ url }}');">Supervisor</a></b> {{ installed + ' <b>&rarr;</b> ' + latest }}
            {% endif %}
          operating_system_update: >
            {% set installed = state_attr('update.home_assistant_operating_system_update', 'installed_version') %}
            {% set latest = state_attr('update.home_assistant_operating_system_update', 'latest_version') %}
            {% set url = 'https://github.com/home-assistant/operating-system/releases/tag/' %}
            {% if installed != latest %}
              <b><a href="#" onclick="window.open('{{ url }}');">Operating system</a></b> {{ installed + ' <b>&rarr;</b> ' + latest }}
            {% endif %}

But I have an error in logs

TemplateError('UndefinedError: 'jinja2.utils.Namespace object' has no attribute 'list'') while processing template 'Template("{% set ns = namespace() %} {% for k, v in this.attributes | dictsort(by='value') %} {% set ns.list = ns.list + [v] if v != '' else [] %} {% endfor %} {{ ns.list | count }}")' for attribute '_attr_native_value' in entity 'sensor.template_updates'

and a warning

Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.template_updates, old_state=<state sensor.template_updates=0; supervisor_update=<b><a href="#" onclick="window.open('https://github.com/home-assistant/supervisor/releases/tag/2022.09.1');">Supervisor</a></b> 2022.08.6 <b>&rarr;</b> 2022.09.1, operating_system_update=<b><a href="#" onclick="window.open('https://github.com/home-assistant/operating-system/releases/tag/9.0');">Operating system</a></b> 8.5 <b>&rarr;</b> 9.0 @ 2022-09-19T21:36:10.838358+02:00>, new_state=<state sensor.template_updates=unavailable @ 2022-09-19T21:36:10.842350+02:00>>, skipping template render for Template[{% set ns = namespace() %} {% for k, v in this.attributes | dictsort(by='value') %} {% set ns.list = ns.list + [v] if v != '' else [] %} {% endfor %} {{ ns.list | count }}]

Does anyone see what is wrong ?
Thanks

works here… try replacing namespace() with namespace(list=[])

1 Like

Thanks Mattias, it works !

yes, i reverted back to the ‘default’ template now but at that time, i modified the grid config in the base template.

       - grid-template-areas:                 |
            "icon      icon"
            "circle    circle"
            "n         n"

Can someone help me with this?

Great theme! I cannot get the background image to show though? where do you put the code, I have added the background tag into “theme.yaml” and added the link in “ui_lovelace.yaml” but still no background?

I get an error in your code - why? @ Mattias_Persson

Error while processing template: Template("{% set entity = 'weather.smhi_home' %} {% if not is_state(entity, 'unknown') %} {% set temp = state_attr(entity, 'temperature') | round %} {% set precip = state_attr(entity, 'forecast')[0]['precipitation'] | round %} Känns som {{ temp }}° med {{ 'ingen risk för regn' if precip == 0 else precip | string + 'mm regn \u2614\uFE0F' }} {% else %} Kan inte läsa in väder... {% endif %}")

Mine moves I think… im not running browsermod 2 yet though

because you haven’t set up smhi (swedish weather)

what link? you only need to copy this into www/background.png

1 Like

Yes

That’s jinja2 templating, you need to use javascript

// you added this
${data[variables.i].airdate} // 2022-09-26T01:30:00Z

// do something like
let airdate = new Date(Date.parse(data[variables.i].airdate)),
    datestring = airdate.getDate() + "-" + (airdate.getMonth()+1) + "-" + airdate.getFullYear();

${datestring} // 26-09-2022

but airdate is in the future? if you use ${data[variables.i].aired} you’ll get the date it was originally aired

2 Likes

Have you tried to remove the template?

I do = I gave you an example from your code. I changed it to my code accordingly. And that’s how it looks: and there’s still an error.
@Mattias_Persson

        weather: >
          {% set entity = 'weather.beer_sheva' %}
          {% if not is_state(entity, 'לא ידוע') %}
            {% set temp = state_attr(entity, 'temperature') | round %}
            {% set precip = state_attr(entity, 'תחזית')[0]['precipitation'] | round %}
              מרגיש כמו {{ temp }}° med {{ 'אין סיכון לגשם' if precip == 0
              Else Precip | string + 'מ"מ גשם \u2614\uFE0F' }}
          {% else %}
            לא ניתן לטעון מידע על מזג האוויר
          {% endif %}
Invalid config for [template]: invalid template (TemplateSyntaxError: expected token 'end of print statement', got 'Else') for dictionary value @ data['sensor'][0]['attributes']['weather']. Got '{% set entity = \'weather.beer_sheva\' %} {% if not is_state(entity, \'לא ידוע\') %}\n {% set temp = state_attr(entity, \'temperature\') | round %}\n {% set precip = state_attr(entity, \'תחזית\')[0][\'precipitation\'] | round %}\n מרגיש כמו {{ temp }}° med {{ \'אין סיכון לגשם\' if precip == 0\n Else Precip | string + \'מ"מ גשם \\u2614\\uFE0F\' }}\n{% else %}\n לא ניתן לטעון מידע על מזג האוויר\n{% endif %}\n'. (See /config/sidebar.yaml, line 0).

No, that’s an entirely different error, Else should be lowercase
https://www.home-assistant.io/docs/configuration/templating/

thank you for the answer. I found the problem with your **Else Precip** | String + MK Rain \ U2614 \ UFE0F}}

sss

        battery: >
          {% set entities = states.sensor 
            | selectattr('entity_id', 'search', 'battery')
            | rejectattr('entity_id', 'search', 'iphone')
            | map(attribute = 'entity_id') | list %}
          {% for sensor in entities if states(sensor) != 'unknown' and states(sensor) !=
          'unavailable' and states(sensor) != 'None' and states(sensor) | int(default=0) <= 5 %}
            {% if loop.first %} {{'\u26A0\uFE0F'}} Batteri {% else %}, {% endif %}
            {{ state_attr(sensor, 'friendly_name') }} {{ states(sensor) }}%
          {% endfor %}

Another question in your possession. I can’t implement the display batteries (iPhone and Samsung devices), depending on your code. what am I missing?
@Mattias_Persson

why this state_display, in the storage dashboard I see the change in changing the entity status and instead in the tablet dashboard, no? can anyone help me?

below the template

                state_display: >
                  [[[ return entity.state === 'on' ? 'Connesso' : entity.state
                  === 'off' ? 'Disconnesso' : 'Sconosciuto'; ]]]