Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[Home Assistant] Person card

I recently saw this cool dashboard and the person cards caught my eye. As the dashboard creator also provided all the yaml code and a really helpful guide, I tried to rebuild it. I was already using the mushroom-person-card, so I “just” had to add the little icons (mushroom-chips-card) below it (using the vertical-stack-in-card). To display the network type and the charging status, you first have to enable these sensors in the Home Assistant Companion App on your mobile phone. This is my result:

type: horizontal-stack
cards:
  - type: custom:vertical-stack-in-card
    cards:
      - type: custom:mushroom-person-card
        entity: person.nico
        icon_type: entity-picture
        secondary_info: last-changed
        card_mod:
          style: |
            ha-card {
              background: transparent;
            }
      - type: horizontal-stack
        cards:
          - type: custom:mushroom-chips-card
            alignment: center
            card_mod: 
              style: |
                ha-card {
                    --chip-font-size: 0.3em;
                    --chip-icon-size: 0.5em;
                    --chip-border-width: 0;
                    --chip-box-shadow: none;
                    --chip-background: none;
                    --chip-border: none;
                    --chip-spacing: none;
                    --chip-font-weight: bold;
                }
            chips:
              - type: template
                entity: sensor.mi_8_network_type
                content: '{{ states(''sensor.mi_8_network_type'')}}'                
                icon: |-
                  {% if is_state('sensor.mi_8_network_type','wifi')%}
                    mdi:wifi 
                  {% elif is_state('sensor.mi_8_network_type','vpn')%}
                    mdi:network
                  {% elif is_state('sensor.mi_8_network_type','cellular')%}
                    mdi:signal-4g
                  {% else %} 
                    mdi:network-strength-off
                  {% endif %}  
                icon_color: >-
                  {% if is_state('sensor.mi_8_network_type','wifi') or
                  is_state('sensor.mi_8_network_type','vpn')%}
                    green
                  {% elif is_state('sensor.mi_8_network_type','cellular')%}
                    red
                  {% else %} 
                    grey
                  {% endif %}   
                tap_action:
                  action: more-info
              - type: template
                entity: sensor.mi_8_battery_level
                content: '{{ states(''sensor.mi_8_battery_level'')}}%'
                icon: |-
                  {% set state = states('sensor.mi_8_battery_level')|float %}
                  {% if state >= 0 and state < 10 %} mdi:battery-10
                  {% elif state >= 10 and state < 20 %} mdi:battery-20
                  {% elif state >= 20 and state < 30 %} mdi:battery-30
                  {% elif state >= 30 and state < 40 %} mdi:battery-40
                  {% elif state >= 40 and state < 50 %} mdi:battery-50
                  {% elif state >= 50 and state < 60 %} mdi:battery-60
                  {% elif state >= 60 and state < 70 %} mdi:battery-70
                  {% elif state >= 70 and state < 80 %} mdi:battery-80
                  {% elif state >= 80 and state < 95 %} mdi:battery-90
                  {% else %} mdi:battery
                  {% endif %}   
                icon_color: |-
                  {% set state = states('sensor.mi_8_battery_level')|float %}
                  {% if state >= 0 and state < 20 %} red
                  {% elif state >= 20 and state < 50 %} orange
                  {% elif state >= 50 and state < 80 %} yellow
                  {% else %} green
                  {% endif %}         
                tap_action:
                  action: more-info
              - type: template
                entity: sensor.mi_8_battery_power
                content: '{{ states(''sensor.mi_8_battery_power'')}} W'
                icon: |-
                  {% if is_state('binary_sensor.mi_8_is_charging','on')%} 
                    mdi:power-plug  
                  {% else %} 
                    mdi:power-plug-off 
                  {% endif %}                  
                icon_color: |-
                  {% if is_state('binary_sensor.mi_8_is_charging','on')%} 
                    blue
                  {% else %} 
                    grey
                  {% endif %}
                tap_action:
                  action: more-info
  - type: custom:vertical-stack-in-card
    cards:
      - type: custom:mushroom-person-card
        entity: person.user2
        icon_type: entity-picture
        secondary_info: last-changed
        card_mod:
          style: |
            ha-card {
              background: transparent;
            }
      - type: horizontal-stack
        cards:
          - type: custom:mushroom-chips-card
            alignment: center
            card_mod: 
              style: |
                ha-card {
                    --chip-font-size: 0.3em;
                    --chip-icon-size: 0.5em;
                    --chip-border-width: 0;
                    --chip-box-shadow: none;
                    --chip-background: none;
                    --chip-border: none;
                    --chip-spacing: none;
                    --chip-font-weight: bold;
                }
            chips:
              - type: template
                entity: sensor.redmi_note_8_pro_network_type
                content: '{{ states(''sensor.redmi_note_8_pro_network_type'')}}'                
                icon: >-
                  {% if
                  is_state('sensor.redmi_note_8_pro_network_type','wifi')%}
                    mdi:wifi 
                  {% elif
                  is_state('sensor.redmi_note_8_pro_network_type','vpn')%}
                    mdi:network
                  {% elif
                  is_state('sensor.redmi_note_8_pro_network_type','cellular')%}
                    mdi:signal-4g
                  {% else %} 
                    mdi:network-strength-off
                  {% endif %}  
                icon_color: >-
                  {% if is_state('sensor.redmi_note_8_pro_network_type','wifi')
                  or is_state('sensor.redmi_note_8_pro_network_type','vpn')%}
                    green
                  {% elif
                  is_state('sensor.redmi_note_8_pro_network_type','cellular')%}
                    red
                  {% else %} 
                    grey
                  {% endif %}   
                tap_action:
                  action: more-info
              - type: template
                entity: sensor.mi_8_battery_level
                content: '{{ states(''sensor.redmi_note_8_pro_battery_level'')}}%'
                icon: >-
                  {% set state = states('sensor.redmi_note_8_pro_battery_level')|float %}
                  {% if state >= 0 and state < 10 %} mdi:battery-10
                  {% elif state >= 10 and state < 20 %} mdi:battery-20
                  {% elif state >= 20 and state < 30 %} mdi:battery-30
                  {% elif state >= 30 and state < 40 %} mdi:battery-40
                  {% elif state >= 40 and state < 50 %} mdi:battery-50
                  {% elif state >= 50 and state < 60 %} mdi:battery-60
                  {% elif state >= 60 and state < 70 %} mdi:battery-70
                  {% elif state >= 70 and state < 80 %} mdi:battery-80
                  {% elif state >= 80 and state < 95 %} mdi:battery-90
                  {% else %} mdi:battery
                  {% endif %}   
                icon_color: >-
                  {% set state = states('sensor.redmi_note_8_pro_battery_level')|float %}
                  {% if state >= 0 and state < 20 %} red
                  {% elif state >= 20 and state < 50 %} orange
                  {% elif state >= 50 and state < 80 %} yellow
                  {% else %} green
                  {% endif %}            
                tap_action:
                  action: more-info
              - type: template
                entity: sensor.redmi_note_8_pro_battery_power
                content: '{{ states(''sensor.redmi_note_8_pro_battery_power'')}} W'
                icon: >-
                  {% if is_state('binary_sensor.redmi_note_8_pro_is_charging','on')%} 
                    mdi:power-plug  
                  {% else %} 
                    mdi:power-plug-off 
                  {% endif %}                  
                icon_color: >-
                  {% if is_state('binary_sensor.redmi_note_8_pro_is_charging','on')%} 
                    blue
                  {% else %} 
                    grey
                  {% endif %}
                tap_action:
                  action: more-info

[Home Assistant] Display Battery devices, sorted by battery status

Simple and handy card, to display devices/entities of a specific type. Thanks to this card, it is no longer necessary to add new battery devices manually.

https://github.com/thomasloven/lovelace-auto-entities

    type: custom:auto-entities
    card:
      show_header_toggle: false
      title: Battery status
      type: entities
      state_color: true
    filter:
      include:
        - attributes:
            device_class: battery
          state: <= 100
      exclude:
        - name: /MI/
        - name: /Redmi/
        - name: /T550/
    sort:
      method: state
      numeric: true

[Home Assistent] AWSH Müllabfuhrtermine einbinden

HACS Integration: https://github.com/mampfes/hacs_waste_collection_schedule

Die Integration bietet eine custom component für die AWSH. Nach Angabe von Ort und Straße bekommt man hier für alle Abfallbehälterarten die entsprechenden Termine zurück. Man muss daher noch die relevanten für sich heraussuchen. Diese kann man unter customize dann angeben und zusätzlich mit einem alias und einem icon versehen.

# Waste Collection Schedule
waste_collection_schedule:
  sources:
    # Integrated Service Provider for AWSH
    - name: awsh_de
      args:
        city: Ammersbek
        street: Frahmredder
      customize:
        # my waste types I ordered
        - type: Restabfall 40L-240L(2-wöchentlich)
          alias: restabfall
          icon: mdi:trash-can          
        - type: Bioabfall(2-wöchentlich)
          alias: bioabfall
          icon: mdi:leaf-circle
        - type: Wertstoff/LVP(2-wöchentlich)
          alias: wertstoff
          icon: mdi:recycle
        - type: Papiertonne(monatlich)
          alias: papier
          icon: mdi:trash-can

Alternativ bekommt man hier den Link zu einer .ics Kalenderdatei. Man kann vorher die für sich relevanten Abfallbehälter auswählen. Die .ics kann ebenfalls direkt eingebunden werden (siehe hier)

# Waste Collection Schedule
waste_collection_schedule:
  sources:
    # ICS
    - name: ics
      args:
        url: https://www.awsh.de/api_v2/collection_dates/1/ort/XXX/strasse/XXX/hausnummern/0/abfallarten/R02-B02-D02-P04/kalender.ics

Nach einem Reboot kann man nun im Home Assistant Kalender seine Abholtermine einsehen.

Im nächsten Schritt definiert man sich noch seine Sensoren je Abfallart.

sensor:
  - platform: waste_collection_schedule
    name: Restabfall
    value_template: 'in {{value.daysTo}} Tag(en)'
    types:
      - restabfall
  - platform: waste_collection_schedule
    name: Bio
    value_template: 'in {{value.daysTo}} Tag(en)'
    types:
      - bioabfall
  - platform: waste_collection_schedule
    name: Wertstoff
    value_template: 'in {{value.daysTo}} Tag(en)'
    types:
      - wertstoff
  - platform: waste_collection_schedule
    name: Papier
    value_template: 'in {{value.daysTo}} Tag(en)'
    types:
      - papier  

Die Sensoren kann man dann zu seinem Dashboard hinzufügen und bei Bedarf auch noch umbenennen. So sieht es bei mir dann aus:

Button-card

Für eine Button-card habe ich mir noch einen weiteren Sensor angelegt. Diesem Sensor einfach alle Abfallarten zuordnen.

  # Used with custom:button-card
  - platform: waste_collection_schedule
    name: wasteButton
    count: 4
    value_template: '{{value.types|join(", ")}}|{{value.daysTo}}|{{value.date.strftime("%d.%m.%Y")}}|{{value.date.strftime("%a")}}'
    types:
      - Restabfall
      - Bioabfall
      - Wertstoff
      - Papier

Die Button-card dann noch befüllen mit:

type: custom:button-card
entity: sensor.wastebutton
layout: icon_name_state2nd
show_label: true
label: |
  [[[
    var days_to = entity.state.split("|")[1]
    if (days_to == 0)
    { return "War heute" }
    else if (days_to == 1)
    { return "Heute Abend raus" }
    else
    { return "in " + days_to + " Tagen" }
  ]]]
show_name: true
name: |
  [[[
    return entity.state.split("|")[0]
  ]]]
state:
  - color: red
    operator: template
    value: '[[[ return entity.state.split("|")[1] == 0 ]]]'
  - color: orange
    operator: template
    value: '[[[ return entity.state.split("|")[1] == 1 ]]]'
  - value: default

Benachrichtigung

Um immer die Anzahl der Tage bis zum nächsten Abholtermin zu kennen, am besten noch einen weiteren Sensor anlegen und diesem wieder alle Abfallarten zuordnen.

  # Sensor for upcoming waste. Used in my reminder automation
  - platform: waste_collection_schedule
    name: upcomingWaste
    value_template: "{{value.daysTo}}"
    types:
      - Restabfall
      - Bioabfall
      - Wertstoff
      - Papier

Dieser kann dann in einer Erinnerungsautomatisierung verwendet werden, welche z.b. eine Notification am Vortag um 19Uhr verschickt.

alias: Abfall Erinnerung
description: ""
trigger:
  - platform: time
    at: "19:00:00"
condition:
  - condition: state
    state: "1"
    entity_id: sensor.upcomingwaste
action:
  - service: notify.family
    data:
      message: >-
        Müll rausbringen: {{ states.sensor.upcomingwaste.attributes.values() |
        first | 
        replace("restabfall","Restmüll") |
        replace("wertstoff","Wertstoff") |  
        replace("bio","Bio") |
        replace("papier","Papier") }}
      data:
        actions:
          - action: YES_TRASHCAN_IS_OUTSIDE
            title: Ja, ist rausgestellt!
        tag: trashcan_done
mode: single

Die Notification beinhaltet eine Bestätigungsmöglichkeit. Hat jemand die Tonne herausgestellt, kann dieser darüber dies einfach kurz bestätigen und mit einer zweiten Automatisierung kann man die Benachrichtigung dann bei anderen verschwinden lassen. Mehr dazu hier.

alias: Abfall Erinnerung - cleared
description: ""
trigger:
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: YES_TRASHCAN_IS_OUTSIDE
condition: []
action:
  - service: notify.family
    data:
      message: clear_notification
      data:
        tag: trashcan_done
mode: single

Karte für das Dashboard

Ein tolles Beispiel für eine schöne Dashboard-Karte findet man hier.

Dafür müssen jedoch noch ein paar weitere Sensoren hinzugefügt werden, wie es hier ebenfalls beschrieben ist.