Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 103465

Sensor-template for caldav-addon: sometimes working, mostly not

$
0
0

I use the Caldav addon from Github, which works very well so far. Now I want to output the upcoming 10 appointments from two calendars as a list for a display. These are to be published later via MQTT.
The template works in the developer mostly, but after restart I always get errors like TypeError: object of type 'NoneType' has no len().
My suspicion is that the error occurs because the data in the two calendars are not yet available after restart. But so far I haven’t managed to eliminate this error by a condition either.
Is my approach maybe just wrong to do the work via a sensor-template?

- platform: template
  sensors:
    events:
      friendly_name: "Termine"
      value_template: >-
        {% set ns = namespace() %}
        {% if state_attr("sensor.cal_gemeinsam", "data")|count > 0 %}
          {% set ns.nr_a = 0 %}
          {% set ns.nr_b = 0 %}
          {% set anzahl_a = state_attr("sensor.cal_gemeinsam", "data")|count %}
          {% set anzahl_b = state_attr("sensor.cal_familie", "data")|count %}
          {% set ns.anzahl = anzahl_a + anzahl_b %}

          {% if ns.anzahl > 10 %}
            {% set ns.anzahl = 10 %}
          {% endif %}

          {% for i in range(0, ns.anzahl) %}

            {% if ns.nr_a > anzahl_a - 1 %}
              {% set ns.datum_a = 'fertig' %}
            {% else %}
              {% set ns.datum_a = state_attr("sensor.cal_gemeinsam", "data")[ns.nr_a].startDate %}
            {% endif %}

            {% if ns.nr_b > anzahl_b - 1 %}
              {% set ns.datum_b = 'fertig' %}
            {% else %}
              {% set ns.datum_b = state_attr("sensor.cal_familie", "data")[ns.nr_b].startDate %}
            {% endif %}

            {% if ns.datum_a < ns.datum_b %}

              {% if state_attr("sensor.cal_gemeinsam", "data")[ns.nr_a].start_time == '00:00' %}
                {{ state_attr("sensor.cal_gemeinsam", "data")[ns.nr_a].start_day }}. {{ state_attr("sensor.cal_gemeinsam", "data")[ns.nr_a].start_month }}: {{ state_attr("sensor.cal_gemeinsam", "data")[ns.nr_a].summary }}
              {% else %}
                {{ state_attr("sensor.cal_gemeinsam", "data")[ns.nr_a].start_day }}. {{ state_attr("sensor.cal_gemeinsam", "data")[ns.nr_a].start_month }}, {{ state_attr("sensor.cal_gemeinsam", "data")[ns.nr_a].start_time }} Uhr: {{ state_attr("sensor.cal_gemeinsam", "data")[ns.nr_a].summary }}
              {% endif %}
              {% set ns.nr_a = ns.nr_a + 1 %}

            {% else %}

              {% if state_attr("sensor.cal_familie", "data")[ns.nr_b].start_time == '00:00' %}
                {{ state_attr("sensor.cal_familie", "data")[ns.nr_b].start_day }}. {{ state_attr("sensor.cal_familie", "data")[ns.nr_b].start_month }}: {{ state_attr("sensor.cal_familie", "data")[ns.nr_b].summary }}
              {% else %}
                {{ state_attr("sensor.cal_familie", "data")[ns.nr_b].start_day }}. {{ state_attr("sensor.cal_familie", "data")[ns.nr_b].start_month }}, {{ state_attr("sensor.cal_familie", "data")[ns.nr_b].start_time }} Uhr: {{ state_attr("sensor.cal_familie", "data")[ns.nr_b].summary }}
              {% endif %}
              {% set ns.nr_b = ns.nr_b + 1 %}

            {% endif %}

          {% endfor %}

        {% endif %}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 103465

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>