Homekit location to trigger automations in Home-assistant, using a software switch. Requires no Homekit-hardware!

I have it in /home/USER/homebridge_status

The place shouldn’t matter, it’s more of not giving R+W-permissions to the user homebridge to a path that it shoulnd’t have.

This can also be used to get updates from homekit-hardware that is not supported in HA. For example I have an Elgato EVE door&window-sensor. I bought this before starting with HA and it does not communicate with HA.

In your homekit-app (I use eve-app), you can turn on a command when the door sensor is triggered.
By importing this information into HA, I can determine with a motion sensor if the door was opened for a person that left or that is entering my home.

1 Like

Awesome, thanks! Worked like a charm.

Next step would be to integrate Siri, right? :slight_smile: Is there any approach?

Yes you could use this method for Siri. Or just use homeassistant plugin for homebridge. :wink:

This is a good solution if you wan HomeKit location to trigger HA or you want HomeKit devices that doesn’t communicate with HA normally.

This can be modified into a little more elegent way, instead of creating a folder we can use the HA REST-api to directly turn on or off a input_boolean.

I’m on my job now, but I’ll modify the post when I’m home to give an example.

1 Like

As promised, a little more sofisticated way to update our location. This is also a bit faster since we call the built-in HA REST-API directly instead of using a sensor to check if a folder exists.

If you do this, please remove the “no password” for homebridge user by removing the line you added in the first post

sudo visudo

later revoke the R/W-permissons for the user homebridge to the path that you chose above in post 1

sudo setfacl -m u:homebridge:r /path-in-post-1-where-you-created-the-folder aka "PATH OF CHOICE"/

##Create an input_boolean in HA

input_boolean:
    USERishome:
      icon: mdi:home
      name: Home

##Call HA REST-API
Now create the following .sh files and places them where you want, I placed them in /var/homebridge/ as my congif.json-file is located there:

  • USERhome.sh
  • USERaway.sh
  • USERstatus.sh

USERhome.sh

curl -X POST -H "Content-Type: application/json" -d '{"entity_id":"input_boolean.USERishome"}' "http://IP-to-HA:8123/api/services/input_boolean/turn_on"

USERaway.sh

curl -X POST -H "Content-Type: application/json" -d '{"entity_id":"input_boolean.USERishome"}' "http://IP-to-HA:8123/api/services/input_boolean/turn_off"

USERstatus.sh

curl --silent -X GET  "http://IP-to-HA:8123/api/states/input_boolean.USERishome" | grep -i '"state": "on"'

Make all 3 .sh-files excutable, eg.

sudo chmod +x /path/USERstatus.sh

Modify homebridge configuration

Change the following rows that you added in first post

"on_cmd": "/dir-.sh-file/USERhome.sh",
"off_cmd": "/dir-.sh-file/USERaway.sh",
"state_cmd": "/dir-.sh-file/USERstatus.sh"

In my case since I placed the .sh-files in /var/homebridge I modify the config-file according to

"on_cmd": "/var/homebridge/rittehome.sh",
 ....

Restart homebridge and home-assistant and you’re good to go!

Let me know if any step is unclear, I’ve tested this “improvement” during the evening and it should work as well as the method in post 1, but this is a little more nice solution and quicker since we call the REST-API directly instead of using a sensor that checks if a folder is present or not.

1 Like

I am curious why you need to use a directory or HA rest-api. I do something similar but simply use the switch that homekit turns on as the trigger. Do you do it like that to help preserve the state on restart?

I created a blank / dummy command line switch called home and exposed it to homekit through homebridge. Homekit is automated to turn the switch.home on if i’m home and off when I leave. HA can read the state of that switch to determine if homekit see me home or not.

I don’t see the difference beside a slightly different approach? I wanted an entity in HA that represents my status. This could be great if I want to modify the look of the entity. Also I can trigger the status in HomeKit by switching on/off in HA.

If I understood what you do:
HomeKit turns on a command line switch, HA automation reads the status of this.

What I do:
HomeKit turns on an input boolean, HA automation reads the status of it.

I have tiny single step more that is command line to turn on input boolean in HA.

As long as both ways works, it should matter right? :slight_smile:

Please share your setup if somebody wants an alternative method (that maybe is working better or is more stable).

Hi guys! I really liked this idea, mostly because whatever I do I don’t seem to make device tracking with ping, nmap or snmp reliable…

I don’t get it however. It works brilliant for me, but when I told my kids to do the same it doesn’t any more. The automations in iOS home app doesn’t distinguish between me and my kids.

Am I doing something wrong?

Regards,
Johan

Hi Johan, did you create separate files for your children? HomeKit doesn’t support multiple users for location triggers. (Ios11 introduces this).

What you need is to redo the steps in step one for each of your children and have unique trigger rule in HomeKit for each child. The scripts above should be named uniquely also.

This is a really good idea. Since I’m already using homebridge-homeassistant, I actually ended doing what RobDIY suggested, and created an input_boolean in HA that is exposed in HomeKit. (With the REST api setup, I had 2 switches in HomeKit, and if I hit the cmd switch, both turned on).

I set up an automation in the Home App to switch the boolean to on when I arrive home, and off when I leave. So far it is working great. Now I want to set up the same for my wife.

My question is this. In the Home App, my wife isn’t able to set up automations, since she is not the ‘owner’ of the HomeKit setup. Does the Eve app allow other users to set up automations based on their location?

EDIT: I just saw you answered that question in the previous post… iOS11. Whoops!

I prefer to be able to set the state in home-assistant, especially for restart. I think it’s great when using appdaemon too.
Anyway, it’s the same logic and really doesn’t matter.

As I said, you don’t need iOS 11. You can just trigger different inout_boolean.:

  • X’s home app triggers X_isHome
  • Y’s home app triggers Y_isHome

Then you can put both input_boleans in a group and set rules based on the state of the group. If somebody is home, then the group is set to on. If both is away, the groups state is off.

Glad you liked it!

1 Like

You are right. I realized that I needed to grant my wife the ability to edit in the Home app. Now she has the ability to create automation, and we got a new trigger added for her.

So far it is working well, and seems much faster than other methods.

You can use the same concept to control any homekit device from HA. I use it for a schlage sense lock.,

or magnet sensor

Yes, I wrote that a couple of post up. I’m using it for my elgato eve door sensor.

No, I actually followed RobDYIs method. But I think you’re correct, that doesn’t really work for more than one person per “Homekit home”…

Thanks, will try your method during the weekend!

/Johan

I just setup everything with the input_boolean method too… need to try how well it works. In any case, why you think it won’t work for more than one person per HomeKit home?

Ios10 doesn’t support multi-user automation, it’s a limitation in ios10. It’s fixed in ios11.

If you have ios10 and multiple users, use this:

ah! I’m on iOS11 already… checking the Home.app from Apple it was letting me create multiple automations with different users so I was wondering why it won’t work hehe

Hmm, I don’t have ios11 but it should work according to the news from WWDC.

It’s a beta so hopefully they’ll fix it soon.

Anyway, my method would work in ios 11 too :wink:
Just follow the steps in the link above.