- sensor:
    - name: "Batteri (%)"
      unique_id: snowywhite_battery_numeric
      unit_of_measurement: "%"
      state: >
        {% set val = states('sensor.snowywhite_battery') %}
        {% if val not in ['unknown','unavailable',''] %}
          {{ val.replace('%','') | float }}
        {% else %}
          0
        {% endif %}

    - name: "Rækkevidde (km)"
      unique_id: snowywhite_range_numeric
      unit_of_measurement: "km"
      state: >
        {% set val = states('sensor.snowywhite_range') %}
        {% if val not in ['unknown','unavailable',''] %}
          {{ val.replace(' km','') | float | round(0) | int }}
        {% else %}
          0
        {% endif %}

    - name: "Charging (numeric)"
      unique_id: snowywhite_charging_numeric
      unit_of_measurement: "1"
      state: >
        {% if is_state('binary_sensor.snowywhite_charging','on') %}
          1
        {% else %}
          0
        {% endif %}

    - name: "Energy Added (kWh)"
      unique_id: snowywhite_energy_added_numeric
      unit_of_measurement: "kWh"
      state: >
        {% set val = states('sensor.snowywhite_energy_added') %}
        {% if val not in ['unknown','unavailable',''] %}
          {{ val | float }}
        {% else %}
          0
        {% endif %}

    - name: "Charging Rate (km/h)"
      unique_id: snowywhite_charging_rate_numeric
      unit_of_measurement: "km/h"
      state: >
        {% set val = states('sensor.snowywhite_charging_rate') %}
        {% if val not in ['unknown','unavailable',''] %}
          {{ val | float }}
        {% else %}
          0
        {% endif %}

    - name: "Dato"
      unique_id: n22_dato
      state: >
        {{ now().strftime('%-d/%-m') }}

    - name: "Solopgang"
      unique_id: n22_solopgang
      state: >
        {% set t = state_attr('sun.sun','next_rising') %}
        {{ as_timestamp(t) | timestamp_custom('%H:%M') if t else '-' }}

    - name: "Solnedgang"
      unique_id: n22_solnedgang
      state: >
        {% set t = state_attr('sun.sun','next_setting') %}
        {{ as_timestamp(t) | timestamp_custom('%H:%M') if t else '-' }}

    - name: "Opvask tid tilbage"
      unique_id: dishwasher_remaining_minutes
      unit_of_measurement: "min"
      state: >
        {% set val = states('sensor.dishwasher_remaining_time_2') %}
        {% if val in ['unknown','unavailable',''] %}
          0
        {% elif ':' in val %}
          {% set parts = val.split(':') %}
          {{ (parts[0] | int * 60) + (parts[1] | int) }}
        {% elif 'min' in val %}
          {{ val.replace('min','') | int }}
        {% else %}
          {{ val | int(0) }}
        {% endif %}

    - name: "Dage til jul"
      unique_id: dage_til_jul
      state: >-
        {{ states('sensor.nedtaelling_juleaften') }}

    - name: "Dage til nytår"
      unique_id: dage_til_nytaar
      state: >-
        {{ states('sensor.nedtaelling_nytaar') }}

    - name: "Dage til ferie"
      unique_id: dage_til_ferie
      state: >-
        {{ states('sensor.nedtaelling_ferie') }}

    - name: "Dagens dato"
      unique_id: dato
      state: >-
        {% set timestamp = strptime(states('sensor.date'), '%Y-%m-%d').timestamp() %}
        {% set weekdays_DK = ['Man', 'Tirs', 'Ons', 'Tors', 'Fre', 'Lør', 'Søn'] %}
        {% set months_DK = ['Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December'] %}
        {{ weekdays_DK[timestamp | timestamp_custom('%w') | int - 1] }}dag den {{ timestamp | timestamp_custom('%-d.') }} {{ months_DK[timestamp | timestamp_custom('%-m') | int - 1] }} {{ timestamp | timestamp_custom('%Y') }}