Creating an alert template to concatenate individual templates in a marquee

HI,

for a marquee in the Custom Header, I’d like to have a couple of signaling sensors to be displayed on a single line. I have all the ingredients and conditions, but am a bit confused how to group this in 1 single larger set of templates.

Have an example how to do this, but it is built on a single integration, which I don’t have, mine should be built on individual sensors.

the example is made by @ludeeus here in the Custom Header showcase thread :

        {% set alerts = namespace(active=[], color='var(--google-red-500)') %}
        {% if states('sensor.weatheralerts') | float != 0 %}
          {% for alert in state_attr('sensor.weatheralerts', 'alerts') %}
          {% set alerts.active = alerts.active + [alert['title']] %}
          {% endfor %}
        {% else %} {% set alerts.active = alerts.active + ['No active alerts'] %}
        {% endif %}

and the marquee then uses:

        <span style='color: {{ alerts.color }};'>
        Alerts: {{ alerts.active | join(' - ')}},
        </span>

so far so good. My sensors would be based on:

binary_sensor.alert:
  value_template: >
    {{ is_state('binary_sensor.schimmel_alert','on') or 
       is_state('binary_sensor.meteoalarm_brabant','on') or
       is_state('persistent_notification.updater_notification','notifying') or
       is_state('persistent_notification.trash_notification','notifying')}}

being on, and then I’d need to display these values for each contributing sensor above:

Schimmel alert: {{ states('sensor.schimmel_sensor')|float}}
MeteoAlarm: {{state_attr('binary_sensor.meteoalarm_brabant','awareness_level')} - {{state_attr('binary_sensor.meteoalarm_brabant','awareness_type')}}
Update {{ states('sensor.ha_available_version') }} available

Trash-alert:  {% if states('sensor.trash_firstdate') == 'vandaag'  %}   {{states('sensor.trash_today')|title}} wordt vandaag opgehaald!
       {% else %} {{states('sensor.trash_tomorrow')|title}} wordt morgen opgehaald!
       {% endif %}

Please have a look if yo can help me build this, thanks!

for the time being I now have this, but it obviously stops right after the first met condition and wouldn’t use the consecutive conditions if they where met…

{% if is_state('binary_sensor.alerts','on') %}
  {% if is_state('binary_sensor.schimmel_alert','on') %} Schimmel alert: {{ states('sensor.schimmel_sensor')|float}} - Ventilate! %
  {% elif is_state('binary_sensor.meteoalarm_brabant','on') %} MeteoAlarm: {{state_attr('binary_sensor.meteoalarm_brabant','awareness_level')}}{{state_attr('binary_sensor.meteoalarm_brabant','awareness_type')}}
  {% elif is_state('persistent_notification.updater_notification','notifying')%} Update: {{ states('sensor.ha_available_version') }} available
  {% elif is_state('persistent_notification.trash_notification','notifying')%} 
    {% if states('sensor.trash_firstdate') == 'vandaag' %} Afval:  {{states('sensor.trash_today')|title}} wordt vandaag opgehaald!
    {% else %} {{states('sensor.trash_tomorrow')|title}} wordt morgen opgehaald!
    {% endif %}
  {% endif%}
{% else %} No Alerts
{% endif %}

@petro and @123 might I ask you to have a quick glance here? Hope you can help me out.

not sure what you want, do you have examples of what you’re trying to do? Maybe an image?

No image yet, other than in the current situation in the footer:

let me try to explain:

I have a horizontal marquee that shows a few sensor values. I’d like to add these alerts if and when they arise. But, and that’s where it gets tricky, if more than 1 of these exist, the template should concatenate them so all existing values are displayed ( right now only the first one to exist should be output. Or none.

Does this clarify a bit?

this would be it in a horribly verbose way I think (don’t even want to think about the empty else clauses…):

  - platform: template
    sensors:
      marquee_alerts:
        value_template: >
          {%- if is_state('binary_sensor.alerts','on') -%}
            {%- if is_state('binary_sensor.schimmel_alert','on') %} Schimmel alert: {{states('sensor.schimmel_sensor')|float}}% / CO2: {{states('sensor.co2_living')}} ppm - Ventilate!
            {%-else-%}
            {%-endif-%}
            {%-if is_state('binary_sensor.meteoalarm_brabant','on') %} MeteoAlarm: {{state_attr('binary_sensor.meteoalarm_brabant','awareness_level')}}{{state_attr('binary_sensor.meteoalarm_brabant','awareness_type')}}
            {%-else-%}
            {%-endif-%}
            {%- if is_state('persistent_notification.updater_notification','notifying')%} Update: {{states('sensor.ha_available_version')}} available
            {%-else-%}
            {%-endif-%}
            {%- if is_state('persistent_notification.trash_notification','notifying')%} 
            {%-else-%}
            {%-endif-%}
            {%- if states('sensor.trash_firstdate') == 'vandaag' %} Afval: {{states('sensor.trash_today')|title}} wordt vandaag opgehaald!
            {%-elif states('sensor.trash_tomorrow') != 'Geen'%} Afval: {{states('sensor.trash_tomorrow')|title}} wordt morgen opgehaald!
            {%-else-%}
            {%-endif-%}
          {%-else-%} No Alerts
          {%-endif-%}

used in the CH like this now:

      header_text: >-
        {% set alerts = namespace(active=[], color='var(--google-red-500)') %}
        {% if states('sensor.weatheralerts') | float != 0 %}
          {% for alert in state_attr('sensor.weatheralerts', 'alerts') %}
          {% set alerts.active = alerts.active + [alert['title']] %}
          {% endfor %}
        {% else %} {% set alerts.active = alerts.active + ['No active alerts'] %}
        {% endif %}
        {% set inside=states('sensor.temperatuur_living')%}
        {% set outside=states('sensor.temp_current')%} 
        {% set temp_color='var(--primary-text-color)'%} 
        {% set symbol='°C' %}
        <div style='display: flex;display: -webkit-flex;'>
        <div>Ha&nbspRpi4:&nbsp;</div>
        <marquee>
        <span style='color: {{ temp_color }}'>
        Inside temperature: {{ inside }}{{ symbol }},
        Outside temperature: {{ outside }}{{ symbol }},
        </span>
        <span style='color: {{ alerts.color }};'>
        Alerts: {{ alerts.active | join(' - ')}},
        </span>
        <span style='color: orange;'> 
        System alerts: {{states('sensor.marquee_alerts')}},
        </span>
        <span style='color: {{ temp_color }}'>
        Summary - {{states('sensor.dark_sky_summary')}},
        Daily -  {{states('sensor.dark_sky_daily_summary').split('.')[0]}},
        Hourly - {{states('sensor.dark_sky_hourly_summary').split('.')[0]}}.
        </span>
        </marquee>