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

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.

I’ve followed the other method but this command is not working

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"```

My HA setup has an API password so I get a 401: Unauthorized error. How do you add the password to this command? 

Thanks!

Ok I found the answer here https://home-assistant.io/developers/rest_api/

So from the original command you have to add

-H "x-ha-access: PASSWORDHERE"

Entire command would look like this

curl -X POST -H "x-ha-access: PASSWORDHERE" -H "Content-Type: application/json" -d '{"entity_id":"input_boolean.USERishome"}' "http://IP-or-host:8123/api/services/input_boolean/turn_on"

Yep, exactly.

@RobDYI please share your config

I can do it, I’m testing both approaches:

input_boolean.yaml

jonatanhome:
    name: Jonatan home
    initial: on
    icon: mdi:home

Then on Home.app (or other app that uses your HomeKit info) create 2 automations that turn on the switch when you arrive home and turn it off when you leave

3 Likes

Homebridge install instructions are here so that HA is exposed to homekit.

1 Like

Could you (or anyone else) show me you config.json file, I how you have the code for more than 1 person?

I had it running OK just for myself, but now I’ve added a second person their switch doesn’t work right :neutral_face:

Here’s the code I’m using, hoping I just have the formatting wrong or something

{
   "bridge":{
      "name":"Homebridge",
      "username":"WHATEVER",
      "pin":"031-45-154",
      "port":51826
   },
   "accessories":[

   ],
   "platforms":[
      {
         "platform":"cmdSwitch2",
         "name":"CMD switch",
         "switches":[
            {
               "name":"Jono is Home",
               "on_cmd":"/home/pi/.homebridge/JonoHome.sh",
               "off_cmd":"/home/pi/.homebridge/JonoAway.sh",
               "state_cmd":"/home/pi/.homebridge/JonoStatus.sh",
               "polling":"true"
            },
            {
               "name":"Jancy is Home",
               "on_cmd":"/home/pi/.homebridge/JancyHome.sh",
               "off_cmd":"/home/pi/.homebridge/JancyAway.sh",
               "state_cmd":"/home/pi/.homebridge/JancyStatus.sh",
               "polling":"true"
            }
         ]
      }
   ]
}

BTW, I added my HA password in a slightly different way (which is the same that I use for some IFTTT recipes triggering Home Assistant lights, scenes, scripts etc. via Alexa and Google Home).

curl -X POST -H "Content-Type: application/json" -d '{"entity_id":"input_boolean.jono_home"}' "https://PI-IP-ADDRESS:8123/api/services/input_boolean/turn_on?api_password=MY-HA-PASSWORD"

Age you adding a special rule and automation in each device?

See post 14 for more info. Each device to be needed to set with own rules and automations. This is due to that ios10 doesn’t support multi-user rules.

This will supported in ios11.

At the moment I’m showing the input boolean switches in Home Assistant and just testing them by turning off/on the switches in the iOS Home app, or switching them off/on in Home Assistant.

If I switch the 1st one on (my own) from iOS (mine or my wife’s phone) or Home Assistant is turns the other one on/off as expected.

If I switch my wife’s off/on it works now and then (more often not working more than working).

Does the code for my config.json file above look correct?

hey Jono!

Umm I don’t have 2 switches on the cmdSwitch2 platform so I’m not sure if it should work… does the cmdSwitch2 help says something about it?

Hey mate :grinning:

Ah, I thought you’d set two up.

Not to worry, I’ll wait until I switch over to the iOS 11 beta (I’ll wait a while until it gets more mature/stable :slight_smile: )

I don’t know if I follow your logic, but here’s how it should be.

Create every rule and trigger uniquely for each phone. Don’t couple then in homekit.
If you’re able to set up individual homekit rules for each user:

  • User A trigger switch A, user B can’t see switch. It’s a individual rule*.
  • User B trigger switch B, user A can’t see switch. It’s a individual rule*.

*By individual I mean that you’re setting up each phone as you’re pretending it’s the only phone you’re using with this method.

In hass, you can put the input_booleans in a group, and track the status of the group. Only homeassistant can/should understand that the input_booleans are realated, homekit should still think that it’s two entirely separated rules/buttons/process/whatever.

This is my config.json:

{
	"bridge": {
		"name": "Homebridge",
		"username": "C2:22:3D:E2:CE:31",
		"port": 51826,
		"pin": "031-45-154"
	},
	"description": "Insert below..",
	"platforms": [{
		"platform": "cmdSwitch2",
		"name": " CMD switch",
		"switches": [{
    		"name": "Ritte88 isHome",
    		"on_cmd": "/var/homebridge/Ritte88home.sh",
    		"off_cmd": "/var/homebridge/Ritte88away.sh",
    		"state_cmd": "/var/homebridge/Ritte88status.sh",
    		"polling": "true"
		},{
			"name": "Door isOpen",
			"on_cmd": "/var/homebridge/dooropen.sh",
			"off_cmd": "/var/homebridge/doorclosed.sh",
			"state_cmd": "/var/homebridge/doorstatus.sh",
			"polling": "true"
		}]
	}, {
		"platform": "Camera-ffmpeg-omx",
		"cameras": [{
		"name": "Living room camera",
		"videoConfig": {
			"source": "-re -i rtsp://XXX.XX.X/play1.sdp",
			"stillImageSource": "-i http://XXX.XX.X.X/cgi/jpg/image.cgi",
			"maxStreams": 3,
			"maxWidth": 1280,
			"maxHeight": 720,
			"maxFPS": 30

		}
	}]
}]
}

Haven’t check the indention too closely, there could be wrong when pasting into the forum.

Thanks, I think my code is OK.

The problem could be because I’ve shared my ‘HomeKit home’ with my wife, so both mine and her switches show up in both our iOS Home apps?

So both of you are connected to the same ‘HomeKit home’, and it works for both you and your wife?

Don’t share homekit.It will work if you really treat them as two entirely separated phones in homekit.
Connect them by placing the input_booleans in a group, in hass.

My wife and I share the same HomeKit, and both see everything for the house, including both switches. I had to give my wife the ability to edit in HomeKit. From my phone I set up an automation for my switch, and then we set up an automation for her switch from her phone.

Everything seemed to work great for both of us, but after a few days, her switch stopped getting triggered. I think it’s because she has a habit of killing all her background apps occasionally, and she killed the Home app. But we are on vacation at the moment, so I haven’t been able to test that theory.

Homekit is integrated in the OS, it doesn’t die if you close an app.
I’ve noticed that setting upp rules in the “home app” will not work after a couple of days. I rather use Eve elgato app to set up the rules.

And I think you should try to separate your homekit, don’t share it. I don’t think homekit handles that well.
Let hass make the connection.

Edit: In elgato eve app you can see when a rule was triggered. If the rule is triggered but hass doesn’t update then the configuration between homekit and hass is incorrect.
If the rule is not triggered, try to play with the radius when setting up the zone (it’s purely a homekit location problem at this stage.).

Thanks for the info :+1:
I might leave my wife’s phone for now and try it when iOS 11 is released.

Since my short period of testing I’ve noticed a problem with the default iOS Home app, not triggering the switch when entering or leaving the house (so that’s a problem with the iOS Home app/HomeKit, not this automation between Homebridge and Home Assistant).

Manually flicking the switch on the iOS app turns on the input boolean switch on my Home Assistant’s dashboard, and flicking the switch on Home Assistant’s dashboard turns on the switch in the iOS Home app, so that seems fine.

I’m now trying the other iOS Home app (made by an independent developer) to see if the location trigger works better. If not, I’ll give the Elgato Eve app a try.

Elgato eve app is free and really nice. I really like that I can track if a rule was triggered and when. And the automation seems to be working, don’t know why.