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

Help with month counting larger than 12 months

$
0
0

Hello community,

my counting sensor for a contract duration is not working since the new year.

- sensor:
    - name: "Stromverbrauch - Monate"
      unique_id: stromverbrauch_monate
      state: >
        {% if (now().timestamp() | timestamp_custom('%Y') | float(default=0)) < (as_timestamp(states('input_datetime.stromvertrag_vertragsbeginn_aktuell')) | timestamp_custom('%Y') | float(default=0)) %}
        {{ (min(12,(now().timestamp() | timestamp_custom('%m') | float(default=0)) - (as_timestamp(states('input_datetime.stromvertrag_vertragsbeginn_aktuell')) | timestamp_custom('%m') | float(default=0)) + 13)) | int(default=0)}}
        {% else %}
        {{ ((now().timestamp() | timestamp_custom('%m') | float(default=0)) - (as_timestamp(states('input_datetime.stromvertrag_vertragsbeginn_aktuell')) | timestamp_custom('%m') | float(default=0)) + 1) | int(default=0)}}
        {% endif %}
      unit_of_measurement: Monate

It worked well until switching to 2025. Now I only get 1 as result.

The input.datetime is 01.12.2024. So the result should be 13.

Any ideas?

Thanks.

3 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 105921

Trending Articles