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

[Home Assistant] Display Reolink Recordings from a NAS using the Gallery Card

A few months ago, I installed a Reolink Doorbell at our front door. Since then, I’ve used it for simple automations like sending a photo when someone is at the door. To capture a photo, I was using the camera.snapshot service. I never used the photos and videos that the doorbell itself recorded and that were stored on my TrueNAS system via FTP. Mainly because I haven’t found a good way to display the captured photos and videos on my Dashboard. But finally I was able to fill the gap with the Gallery Card, which turned out to be exactly what I needed the whole time. By using it, you can simply display the latest images and videos, even when they are stored in some kind of nested folder structure, and it also helps to parse filenames to display them in a more convenient way.

Following a brief overview of what I had to do:

  • TrueNAS
    • Create dataset, in my case it’s: data/camera
    • Share the dataset via NFS
      • Sharing → Unix Shares (NFS) → Add → Choose your new dataset
    • Create some folder(s) on your new dataset, for example: /Reolink/Wifi-Doorbell/Recordings (to do that, simply mount the NFS share to your local machine or use the terminal)
    • Activate the FTP Service
      • Services → FTP
  • Reolink
    • Go to Settings → Surveillance → FTP
      • Insert your TrueNAS FTP credentials
      • Remote Directory: /Reolink/Wifi-Doorbell/Recordings
      • Generate subfolder by: YYYY-MM-DD
      • Select what and when you want to record something
  • Home Assistant
    • Add your Doorbell via Reolink Integration
    • Mount NFS Share
      • Settings → System → Storage → Add Network Storage
      • Name: Reolink (whatever you like)
      • Usage: Media
      • Path: /mnt/data/camera
    • Check if you can access your recordings
      • Media → My media → media → Reolink (NFS name)→ Reolink (my folder name)→ Wifi-Doorbell → Recordings
    • If you cannot open your files, you probably have to adjust your permission on the TrueNAS Dataset. Provide at least read permissions (e.g. 655)
      • Storage → Pools → camera → Edit Permissions
    • Install Gallery Card
      • HACS → Frontend → Explore & Download Repositories → Search for Gallery Card
      • Go to your Dashboard and add the card
type: custom:gallery-card
entities:
  - media-source://media_source/media/Reolink/Reolink/Wifi-Doorbell/Recordings/
maximum_files: 25
menu_alignment: top
folder_format: YYYY/MM/DD
video_loop: true
video_autoplay: true
video_muted: true
file_name_date_begins: 12
file_name_format: YYYYMMDDHHmmss
caption_format: HH:mm:ss DD/MM

Most variables are self-explanatory and also well explained by the galery-card docs, but below a few words about the settings I used, beginning with the path to the media which is provided on the entities attribute.

entities:
  - media-source://media_source/media/Reolink/Reolink/Wifi-Doorbell/Recordings/

The first part is a default value: media-source://media_source/
Followed by the usage type and name we have chosen when mounting the NSF share: media/Reolink/
Then we need the directory path: Reolink/Wifi-Doorbell/Recordings

Because we chose in the Reolink settings “Generate subfolder by: YYYY-MM-DD“, the files are stored in a hierarchy like this:

  • 2023
    • 10
    • 11
    • 12
      • 01
      • 02
      • 03
      • 04
      • 05

The gallery-card can automatically parse this, if you provide the following setting: folder_format: YYYY/MM/DD.
And because the filenames look like this: Haustuer_00_20231230143626.jpg, you have to add file_name_date_begins: 12 to skip the firs letters, and file_name_format: YYYYMMDDHHmmss to parse the date. With caption_format: HH:mm:ss DD/MM you can define the output, how you want to display the parsed timestamp.

[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] Template sensor which combines door lock and contact sensor

Cool template sensor idea I found here, which combines the states of two sensors and display the different combined states. Useful if, for example, you want to combine a door lock and a contact sensor on the same door.

Settings -> Devices & services -> Helpers -> Create Helper -> Template

{% if is_state('lock.kellertur', 'locked') and is_state('binary_sensor.kellertur_contact', 'off') %}
  Locked
{% elif is_state('lock.kellertur', 'unlocked') and is_state('binary_sensor.kellertur_contact', 'on') %}
  Open
{% elif is_state('lock.kellertur', 'unlocked') and is_state('binary_sensor.kellertur_contact', 'off') %}
  Closed, Unlocked
{% elif is_state('lock.kellertur', 'locked') and is_state('binary_sensor.kellertur_contact', 'on') %}
  Open, Locked 
{% else %}
  Unknown
{% endif %}

Helpful to check whether a door is really closed when locking it via a smart lock. Because else it could happen, that you would see status “Locked“, although the door is still open. But with this helper, you will get in this situation “Open, Locked“.

To emphasize such a situation even more clearly, you can of course also add some icon colors.

[Home Assistant] Motion sensor in combination with Adaptive Lightning

I have some lights in my garden which are turned on in the night and are controlled by the Adaptive Lighting component, to automatically adjust brightness and color during the night. But if someone comes home late and this is detected by a motion sensor, I wanted to increase the brightness of all the lights in the garden for a short time.

Increasing the brightness was easy, as it can be done by using the light.turn_on service. However, it took me a few minutes to figure out how to reactivate adaptive lighting on these lights when motion is no longer detected. But it’s actually super simple (and it’s directly written on the GitHub start page here and here). You just have to deactivate the “manually controlled” flag that got activated by “manually” increasing the brightness. Following an example with a single motion sensor (binary_sensor.haustuer_motion), a lamp (light.haustur_light) and the adaptive lightning switch entity (switch.adaptive_lighting_haustuer).

alias: Motion sensor front door
description: "Increase brightness for three minutes when motion is detected"
trigger:
  - platform: state
    entity_id:
      - binary_sensor.haustuer_motion
    to: "on"
condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - service: light.turn_on
    data:
      transition: 3
      brightness_pct: 70
    target:
      entity_id: light.haustur_light
  - wait_for_trigger:
      - platform: state
        entity_id:
          - binary_sensor.haustuer_motion
        to: "off"
        for:
          hours: 0
          minutes: 3
          seconds: 0
    timeout:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
  - service: adaptive_lighting.set_manual_control
    data:
      manual_control: false
      entity_id: switch.adaptive_lighting_haustuer
      lights:
        - light.haustur_light
mode: single

[Home Assistant] Dashboard – vertical-stack title

Just learned that you can directly provide a title for a vertical-stack. Until now, I always added a mushroom-title-card at the beginning of every new stack like that:

type: vertical-stack
cards:
  - type: custom:mushroom-title-card
    title: Lichter

But as you can directly provide a title for the vertical stack, you can get rid of this now unnecessary title card. The title can only be set via code editor.
The only difference is the smaller gap between title and content, which in my opinion looks even better this way.

type: vertical-stack
title: Lichter

[Home Assistant] Conbee II Firmware Update

The firmware update is done in just a few minutes. Connect the Conbee II to your PC, install the deCONZ software, download the latest firmware and use the command line tool to flash it.

Guide: https://github.com/dresden-elektronik/deconz-rest-plugin/wiki/Update-deCONZ-manually#update-in-ubuntu-or-debian

deCONZ: http://deconz.dresden-elektronik.de/ubuntu/stable/

Firmware: http://deconz.dresden-elektronik.de/deconz-firmware/

[Home Assistant] Ikea Traefdri Reset Script / Pairing mode

Handy script, to put Ikea Bulbs into pairing mode by using a Zigbee Switch: https://community.home-assistant.io/t/handy-script-to-reset-ikea-tradfri-bulb/435622

Just go to Settings -> Automations -> Scripts and paste the following YAML script:

alias: Reset IKEA bulb with Switch
sequence:
  - repeat:
      count: "5"
      sequence:
        - service: switch.turn_off
          data: {}
          target:
            entity_id: "{{ smart_plug }}"
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 900
        - service: switch.turn_on
          data: {}
          target:
            entity_id: "{{ smart_plug }}"
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 500
variables:
  smart_plug: switch.REPLACE_SWITCH_NAME
mode: single

Now just insert your light bulb with a light socket into the plug and run the script.

To use the script with other bulbs, just adjust the counter and seconds to your needs, e.g. like here for Ledvance bulbs:

alias: Reset Ledvance Gardenpole with Switch
sequence:
  - repeat:
      count: "5"
      sequence:
        - service: switch.turn_off
          data: {}
          target:
            entity_id: "{{ smart_plug }}"
        - delay:
            hours: 0
            minutes: 0
            seconds: 5
            milliseconds: 0
        - service: switch.turn_on
          data: {}
          target:
            entity_id: "{{ smart_plug }}"
        - delay:
            hours: 0
            minutes: 0
            seconds: 5
            milliseconds: 0
variables:
  smart_plug: switch.REPLACE_SWITCH_NAME
mode: single

[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 Assistant] Midea Comfee MSAF5-12HRDN8-QE R32

Vor kurzem haben wir uns eine Klimaanlage zugelegt. Diese nutzen wir zum Heizen und Kühlen unseres Büros. Dabei handelt es sich um dieses Gerät der Marke Midea (in DE vor allem als Comfee vermarktet).

Der schlimmste Teil der Installation war wie so häufig nicht die Montage, sondern die Einrichtung des Innengerätes über die App. Um das Gerät in das lokale Wifi zu bringen, muss man sich mit einem Access Point des Gerätes verbinden und dann in der App eine Einrichtung durchlaufen. Nach mehreren gescheiterten Versuchen mit einem Android Telefon, habe ich dann zu einem iPhone gegriffen. Hiermit klappte die Einrichtung erheblich besser! Obwohl das Gerät dann im lokalen Netz erreichbar ist, erfolgt die Steuerung dann über eine Cloud… mit entsprechend langsamen Reaktionszeiten. Meiner Meinung nach quasi unbenutzbar.

Um das Gerät ohne großes manuelles Zutun betreiben zu können (also ohne App oder Fernbindung), habe ich daher nach einer entsprechenden Home Assistant Integration gesucht.


Also erstes stieß ich auf diese: https://github.com/nbogojevic/homeassistant-midea-air-appliances-lan

So ganz habe ich dabei nicht verstanden, ob die Integration nun lokal oder via der Cloud steuert. Zumindest musste man beim Einrichtung seine Cloud Zugangsdaten angeben und darüber wird dann das lokale Gerät ermittelt. Beim Testen fiel mir auf, dass sobald man diese Integration nutzte, das Gerät nicht mehr über die App steuerbar war (und umgekehrt). Der Grund ist, dass man den gleichen Zugang nicht auf zwei verschiedenen Geräten nutzen kann. Nach einer Einrichtung eines zweiten Accounts trat das Problem nicht mehr auf und man konnte beides parallel nutzen.

So richtig zuverlässig funktionierte das Ein- oder Ausschalten des Gerätes bei mir jedoch nicht. Ggf. weil die Befehle auch über die Cloud liefen und nicht lokal!?

Auch die Entities der Integration schienen für die Klimaanlage nicht vollständig zu sein. Insgesamt schien die Integration eher für anderen Midea Gerätetypen geeignet zu sein, als Klimaanlagen.


Darauf hin habe ich mir diese Integration angeschaut und bin aktuell auch bei dieser geblieben: https://github.com/georgezhao2010/midea_ac_lan

Die Integration bietet die Möglichkeit, selber die entsprechen Sensoren und Controls zu aktivieren. Man muss also durch Trial-and-Error herausfinden, welche von dem eigenen Gerät unterstützt bzw. publiziert werden

oder in den Developer Tools nach der zugehörigen Climate Entity suchen und sich die Werte anschauen.

Nach etwas herumprobieren, bin ich bei dieser Auswahl geblieben.

Leider funktioniert die Realtime Power nicht, aber immerhin der Gesamtverbrauch. Ich habe daher noch eine Zigbee Steckdose mit Strommessung davor geschaltet, um den Verbrauch in Echtzeit zu überwachen. Außerdem konnte ich die Indoor und Outdoor Temperature Werte noch nicht wirklich nachvollziehen. Sie verändern sich m.M.n. recht merkwürdig. In der vorherigen Integration wurden hier irgendwie genauere Werte angezeigt. Jemand hat dazu auch bereits ein Issue aufgemacht.


Eine entsprechende Thermostat Card wird auch direkt auf dem Dashboard erzeugt.

Eine etwas schönere Anzeige bekommt man mit der Simple Thermostat Card:

type: custom:simple-thermostat
entity: climate.146235046568457_climate
step_size: 1
sensors:
  - entity: sensor.lumi_lumi_weather_temperature
    name: Büro
header: {}
layout:
  mode:
    icons: true
    names: true


Der wirklich interessante Teil ist dann natürlich erst durch Automationen zu verwirklichen. Ich lasse die Klimaanlage z.B. automatisiert bei entsprechenden Uhrzeiten und Temperaturen einschalten. Oder auch, wenn z.B. grade ausreichend Strom von dem Balkonkraftwerk erzeugt wird. Und natürlich wird sie automatisch ausgeschaltet, wenn alle das Haus verlassen.

Insgesamt funktioniert die Integration nun seit einigen Wochen sehr zuverlässig.


Update 08.07.2024: In diesen Reddit Thread wird mehrfach erwähnt, dass man ggf. auch den Wi-Fi-Stick mit einer ESP basierten Lösung ersetzten kann, wie z.B. dieser hier. Das werde ich aber erst testen, wenn es mit der aktuellen Lösung zu Problemen kommt.