HA boolean to control HomeKit device works every other time

Hi ! I could not find anything related to my “problem”.

I’m new to HA and Homekit and all this stuff… thanks for your help in advance !

I have my Pi setup with Home Assistant. Added a input_boolean called lock_door.

Added it in Homekit, i can see it with not problem. I have my actual door lock (Schlage Sense) in Homekit and added automation so i can control the door through HA. I added 4 automations:

When door_lock (HA) is on, lock Schlage.
When door_lock is off, unlock Schlage.
When Schlage locks, set door_lock to on.
When Schlage unlocks, set door_lock to off.

It works… sometimes ! If i start the system, i can lock the door. Then, if i unlock, it wont work, and need me to lock again and then unlock to have the Schlage unlocked.

It’s like i have to call the “lock” action 2 times when an action have already been done.

Can someone help ?

Thanks !!!

Vincent

My guess is it’s going into a loop and throwing HA off. When the Schlage locks it sets door_lock to on which triggers your “when door_lock goes to on then lock Schlage” automation. I had something similar when I was keeping my thermostat target temp in sync with an input slider. My solution was to add a condition to my automations so only one will fire at a time.
So something like this:
When door_lock switched to on and Schlage is unlocked then lock Schlage.
When door_lock switched to off and Schlage is locked then unlock Schlage.
When Schlage locks and door_lock is set to off then switch door_lock to on.
When Schlage unlocks and door_lock is set to on then switch door_lock to off.

Seems logical :wink:

However, the latest software i have is an iPad with IOS 10. I think i can’t have an automation with multiple conditions.

Any other way you might think of ?

Thanks again ! It’s already helpfull !

Vincent

Can you provide your config and automation code (just the parts that are relevant to this issue)? Be sure to follow these guidelines when posting code.

I might not have been clear… automation is on Homekit (on iPad)

Ok, I do understand now. Sorry. I thought you were doing automation in HA and you exposed the lock to HomeKit so you could access it there as well. From what you explained it should be working. I don’t have experience with HomeKit so I’m not sure how to troubleshoot automation in HomeKit… Hopefully another user can chime in.

This sounds like it’s because you are using an input_boolean. Switch it to a switch template and it may work better.

Input_booleans have an issue where it won’t fire a command if the input boolean is already at that state. Example, if a light is off, calling off will do nothing, you need to call on then off.

Switch templates don’t care about the state, they just report the state and you can turn_on or turn_off to your hearts content:

Ok then. Maybe you can help me with the config… :slight_smile: I’m not sure how to add a simple switch.

switch:
  - platform: template
    switches:
      lock_door:
        value_template: "{{ is_state('switch.lock_door', 'on') }}"
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.lock_door
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.lock_door

Something might be wrong because when i turn on by lock, it goes back to off.

Thanks again !

Vincent

You need to tie the switch to the functions you want to run.

You don’t need the automation that the input boolean required. Whatever the action of that automation is, put it in your switch template. Do you have the yaml for your automation that was executed when using the input boolean?

automation is run on homekit (iPad) since the actual door lock is not available in HA but only in Homekit. So i need the switch to control a homekit device.

I have the Schlage sense (Bluetooth only) and a similar setup. I find that homekit automation is hit and miss with schlaage sense and HA homekit.

So to be clear, since i’m new and not sure if i get all the details…

Is it possible to have a Schlage Sense, controlled by Homekit, through HA ?

RobDYI, you seem to have a good experience since i started this based on your other post :slight_smile:

Thanks !

Yes it is. It works by creating 4 homekit automations. 2 homekit automation will change the lock based on a switch that HA controls. The other 2 automations will report the state of the lock to HA by changing a switch that HA sees.

Another way to think about it, if you have a light that you can turn on in HA and see in homekit. Create 2 automations that will lock the door when the light is on and lock it when the light is off.

I would guess the home kit automation works 75% of the time. I have a ATV3 within 10 ft of the lock. I am hoping the new HA homekit component will work better (not sure why it would) than homebridge I use now.

@vgibara Hi Vincent, I have the exact same setup as you and it works for me like 99% of the time no issues. I use an input_boolean and do all the automation on the homekit side. Not sure why this is causing an issue. The only difference is I use an Apple TV vs. an iPad for the home “hub”.

1 Like

Hi @Jer78 Do you mean as my first post with a input boolean, or the switch ?

As your first post using an input boolean

I have the same problem. I tried two different methods:
1- using homekit component: exposed input_boolean and set up rules on homekit side so that the homekit native switch and the input_boolean follow each other. Problem is when i toggle the input_boolean from HA, sometimes the status of this input_boolean doesn’t change in homekit. Sometimes it misses sometimes it works so it’s obviously a problem where HA command is not getting to homekit.
2- using homebridge component: same idea, however i have a different behaviour. If I toggle the input_boolean in HA, the change doesn’t go into homekit through homebridge until I open the home app on an ios device. The second I open it, the input_boolean status updates and the automation works…
So none of the two methods is working as I want them to…

Yeah it doesn’t always work reliably. I find I have to go into Home app every time I restart home Assistant. There is the Homekit Controller component that brings HomeKit devices into HA but it doesn’t yet support locks. Hopefully that will change soon.

I got it to work very reliably! I am using an ipad as a home hub.
I am using homebridge NOT the homekit component of HA.
The reason homebridge-homeassistant wasn’t working as expected before was down to SSL. I am using duckdns for my HA, and in homebridge config file I had the host as “host”: “https://localhost:8123”. With that setting, controlling a device in HA wouldn’t take effect in Home app until I open it on an iOS device. I changed the host to the actual duckdns website “https://myhome.duckdns.org:8123”, and now it works like a charm and I can control my homekit only devices from HA, using some automations on the apple home side.
And FYI, homebridge-homeassistant as opposed to homekit component supports locks and a variety of other devices. Good luck.

Just in case this helps some one else i got this to work with the HA homekit plug in. I had the same issue as mentioned using one input_boolean which is presented to homekit and then having homekit automation’s both directions and it resulting in having to switch the input_boolean twice in HA to have it do anything on the door lock. I presume it because the homekit automation’s get stuck in a loop as you can’t add conditions.

What i did to fix it so homekit didn’t loop its automation’s was make two input_booleans, one as the door lock switch in HA and one as a status switch for homekit to update. So when the door lock one is triggered in HA this has two automation’s in homekit to send command’s to the door lock to lock if on and unlock it if off. Then I have two more automation’s in homekit for the status input boolean that if the lock is locked or unlocked not using HA then update the status switch. Then i have two automation’s in HA that if the status switch is updated then update the door lock switch so it reflects the correct state of the door lock, a round about way of doing it but then i can just have HA talk direct to homekit.

Thus far this works 100% of the time no issue, i have an ipad as my homekit hub which is plugged in to charge full time, this also doubles as my HA dashboard near the front door for when i enter the house.