Homekit, RFLINK and Sensors

Hi,

First post here, and I don’t seem to be able to find anything quite like the issue I have by searching the forums and docs, or googling the hive mind.

I have Hassio running on a PI3b+, with a Nodo RFLINK attached. I have all of my old 433Mhz motion sensors connected as binary sensors, and they all work great. Homekit is presenting them through to Apple home OK as well.

All of the motion sensors have 3 on/off binary states for motion, tamper and low battery. I’ve discovered all of the device IDs for these different devices - they’re all pretty similar with just a few bytes of the ID changing:

{'id': 'chuango_1115c9_02', 'command': 'on'} - motion
{'id': 'chuango_1115cc_02', 'command': 'on'} - tamper
{'id': 'chuango_1115c2_02', 'command': 'on'} - low battery

I have the motion sensor portion set in configuration.yaml:

binary_sensor:
    - platform: rflink
      devices:
            chuango_1115c9_02:
                name: Landing Motion
                device_class: motion
                off_delay: 5
                force_update: true

As mentioned, this works perfectly. What I would like to do, but am failing is set the low battery warning. If I add it as another binary sensor, I get another entry on the Hassio status page, and another accessory on the HomeKit bridge in the iOS home app. Reading the docs, it would appear that it’s possible to link two sensors together:

I’ve tried this with the binary sensor entry for the low battery warning, and this gives an error. Yaml:

homekit:
    filter:
       include_entities:
            - binary_sensor.landing_motion
        exclude_entities:
            - person.admin
    entity_config:
        binary_sensor.landing_motion:
            linked_battery_sensor: binary_sensor.landing_motion_battery

# RF Sensors    
rflink:
    port: /dev/serial/by-id/usb-Arduino__www.arduino.cc__0042_7573030313935160C170-if00
    wait_for_ack: false

binary_sensor:
    - platform: rflink
      devices:
            chuango_1115c9_02:
                name: Landing Motion
                device_class: motion
                off_delay: 5
                force_update: true
            chuango_1115c2_02:
                name: Landing Motion Battery
                device_class: battery
                force_update: true

error:

Invalid config for [homekit]: Entity ID 'binary_sensor.landing_motion_battery' does not belong to domain 'sensor' for dictionary value @ data['homekit']['entity_config']['linked_battery_sensor']. Got None. (See /config/configuration.yaml, line 21). Please check the docs at https://home-assistant.io/components/homekit/

I’ve also tried splitting the battery low out as a manually added rflink sensor - but that gives a different set of errors - it complains that the sensor itself is missing from the dicitonary… I assumed that was due to me trying to add it manually, with the auto add disabled as It does not appear on an auto discover.

Has anyone got an on/off low battery warning tied to another sensor in HomeKit? Is it possible? Am i on a wild goose chase here?

Thanks in advance,

Jason

I have a feeling that HomeKit’s linked_battery_sensor doesn’t accept a binary_sensor as input because a binary sensor can only have two states like ‘0/off/low/closed/false’ and ‘1/on/high/open/true’. I haven’t checked but I think HomeKit expects a percentage or a string from a normal sensor. Try to create a template sensor which represents the real battery sensor as percentage or with ‘normal/low’ and try to input this to the linked_battery_sensor.

1 Like

I’ve come to this conclusion as well, and the template sensor approach is how I’ve sorted it out.

I’ve set all of the low battery signals as switches rather than binary sensors of type battery:

switch:
    - platform: rflink
      devices:
            chuango_xxxxx2_02:
                name: Landing Motion Battery
            chuango_yyyyy2_02:
                name: Study Motion Battery
            chuango_zzzzz2_02:
                name: Master Bedroom Motion Battery
            chuango_aaaaa2_02:
                name: Hall Motion Battery
            chuango_bbbbb2_02:
                name: Living Room Motion Battery
            chuango_ccccc2_02:
                name: Dining Room Motion Battery

I’ve then used templated sensors to dummy values when the low battery comes on for each:

sensor:
    - platform: template
      sensors:
            landing_motion_battery:
                value_template: "{% if is_state('switch.landing_motion_battery', 'on') %}10{% else %}100{% endif %}"
            study_motion_battery:
                value_template: "{% if is_state('switch.study_motion_battery', 'on') %}10{% else %}100{% endif %}"
            master_bedroom_motion_battery:
                value_template: "{% if is_state('switch.master_bedroom_motion_battery', 'on') %}10{% else %}100{% endif %}"
            hall_motion_battery:
                value_template: "{% if is_state('switch.hall_motion_battery', 'on') %}10{% else %}100{% endif %}"
            living_room_motion_battery:
                value_template: "{% if is_state('switch.living_room_motion_battery', 'on') %}10{% else %}100{% endif %}"
            dining_room_motion_battery:
                value_template: "{% if is_state('switch.dining_room_motion_battery', 'on') %}10{% else %}100{% endif %}"

And finally linked the the actual binary sensor entries for each of the PIRs with their respective battery warnings:

homekit:
    entity_config:
        binary_sensor.landing_motion:
            linked_battery_sensor: sensor.landing_motion_battery
        binary_sensor.study_motion:
            linked_battery_sensor: sensor.study_motion_battery
        binary_sensor.master_bedroom_motion:
            linked_battery_sensor: sensor.master_bedroom_motion_battery
        binary_sensor.hall_motion:
            linked_battery_sensor: sensor.hall_motion_battery
        binary_sensor.living_room_motion:
            linked_battery_sensor: sensor.living_room_motion_battery
        binary_sensor.dining_room_motion:
            linked_battery_sensor: sensor.dining_room_motion_battery

Now, if the battery goes low on a PIR, it trips its battery warning switch, with in turn sets the value of the templated sensor to 10, which is below the default battery low level in HomeKit. That causes the HomeKit app to show that PIR with a battery warning, and flags it on the status summary ‘home’ page.

I also have it setup so that all the battery ‘switches’ are in a separate group on the Home Assistant UI:

So once I’ve replaced the battery in whichever sensor has gone low, I can reset the warning. Also makes it easier to check that HomeKit is actually sending the warnings out - no need to stick the sensor on a lab power supply and dial back the voltage til it cries. :wink:

Cheers

Jason

1 Like