HA boolean to control HomeKit device works every other time

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.

I’m trying to do this very thing. Can i have someone PM me or help me with a dummies version of this with some samples?

by the way, if anyone is still having problems with this, I figured out a clean solution that solves the OP’s issue, using only 1 input_boolean.

The trick comes down to making 4 HomeKit automations, ALL with conditions. You can not do this natively with Apple’s Home app, but you can with a 3rd party app like “Controller for HomeKit.” If you don’t use the conditions, you end up in a double loop and I think it causes HomeKit or HA to barf. Once you add the conditionals, it works very nicely.

Here is the setup:
HomeAssistant: create input_boolean.switch and expose it to HomeKit using the native method.
“real” HomeKit accesory you want to control: mySwitch

automation1:
trigger: input_boolean.switch turns on
condition: mySwtich is off
scene: turn mySwitch on

automation 2:
trigger: input_boolean.switch turns off
condition: mySwitch is on
scene: turn mySwith off

automation 3:
trigger: mySwitch turns on
condition: input_boolean.switch is off
scene: turn input_boolean.switch on

automation 4:
trigger: mySwitch turns off
condition: input_boolean.switch is on
scene: turn input_boolean.switch off

With all of these set, you can control mySwitch with Siri, and the state will be matched on the input_boolean.switch in Home Assistant, and you can also automate with Home Assistant and it will be synced across perfectly.

I hope this helps someone Cheers!

2 Likes

We just added a feature to automatically turn off non cancel-able scripts and support for scenes. Both are exposed as switches inside the Home App, but once activated, they will automatically turn_off after one second.

Those features will be in the next HA release 0.83

That is awesome! Can’t wait! That should make this a lot easier!

Went through this, you only need the conditions for the automations that are triggered by the actual homekit device.
Figured i mention this since it saves some time if you’re doing this for 20 devices like I had to.