I'm fairly new to HomeKit, but I have a fairly large amount of hardware for home automation (ecobee thermostat, Insteon door, motion and water sensors, Insteon light switches, Logitech Harmony hubs, etc.). Migrate everything from Indigo in recent weeks, including upgrading to an eero wifi network (great!) And using [Homebridge](https://homebridge.io) to bring the Insteon hardware (with [Homebridge Platform InsteonLocal](https://github.com/kuestess/homebridge-platform-insteonlocal#readme) plugin). Bringing the hardware and controlling it with basic steps was pretty straightforward. However, a major obstacle was my desire for Homekit / Homebridge to turn off the oven / air conditioning if a door was open for more than 10 minutes. And to put the thermostat back on when the last door was closed. This seemed like an easy task, but it seems that for many reasons it is not that simple. After experimenting (mixed with some frustration) I got to work. First of all, many contributors owe a lot of credit - we took many of your ideas and put them together for a specific solution. Two that particularly helped me on the path to a solution were: 1. How to integrate [HomeKit and JSON REST API](https://www.homekit.blog.com/r/HomeKit/comments/l1z82e/beef_up_your_homekit_automations_with_your_own/) 2. [How to work with SSH-Automations](https://www.homekit.blog.com/r/HomeKit/comments/f35ez9/got_a_homepod_then_start_working_with/) # Starting / stopping ecobee based on door condition ** Requirements ** * homebridge (running on a Mac Mini 2014, which also runs AppleScript ) * json-server - follow the excellent installation instructions and examples [here](https://www.homekit.blog.com/r/HomeKit/comments/l1z82e/beef_up_your_homekit_automations_with_your_own/) * [homebridge-dummy plugin](https://github.com/nfarina/homebridge-dummy#readme) * [Eve app](https://apps.apple.com/en/app/eve-for-homekit/id917695792) - exposes more of the HomeKit system than the Apple Home app * Home app - for configuring automation steps ** Accessories ** Create an accessory with the Homebridge Dummy plugin called "10 minutes open door check", by adding it to the config.json plugin. Set the "time" value to 1000 (ie 1 second) so that it stops immediately after starting. ** json-server and db.json ** Install the json server and familiarize yourself with its configuration using [examples](https://www.homekit.blog.com/r/HomeKit/comments/l1z82e/beef_up_your_homekit_automations_with_your_own/). For each door, you will need to create an entry in the db.json file (for me, located in ~ / .homebridge / db.json). Here's an example of mine (two-door): {"frontDoorState": [
{
"id": 1,
"lastOpen": "Feb 24, 2021 at 2:22 PM",
"lastClose": "Feb 24, 2021 at 2:22 PM",
"currentState": "Closed",
"doorName": "Front Door"
}
], "sideDoorState": [
{
"id": 1,
"lastOpen": "Feb 24, 2021 at 3:55 PM",
"lastClose": "Feb 24, 2021 at 3:55 PM",
"currentState": "Closed",
"doorName": "Side Door"
}
]
I use the latest LastOpen entries, lastClose as a kind of log entries that I can look at if needed. The current state values are the basis of AppleScript logic. I used [BBEdit](http://www.barebones.com) to create / edit this and you can check the integrity of any JSON file at [jsonlint.com](https://jsonlint.com). JSON can be ugly. Instead of typing the above (and possibly making mistakes), copy and paste them, then replace your information with things like "frontDoorState" and "doorName". All other values will be updated using the automations below. Before manually editing the db.json file, you should first shut down the json server (Ctrl-C). Edit it, then restart it with “json-server -H
Touch Show more. Set the method to PATCH. Touch "Add a new field". In the left column, enter "lastOpen" and tap CurrentDate (in the keyboard header bar) to add it to the right column. Add another field with the "currentState" key and the value "Open". Touch Next. Repeat for each door you want to monitor 3) For each door that has a sensor, you will need to create an automation for when it closes Very similar to the “open” setting above, only: it triggers when the sensor closes; uses "lastClose" as the key instead of "lastOpen"; and the value for "currentState" should be "Closed" You can use a web browser to monitor whether open and closed automations work. Use the URL http: //
AppleScript (see below) will evaluate the opening / closing status of all doors and return either "Open" or "Closed" as a result. To use the returned value, after the "Script over SSH" step, add an If-Otherwise statement. It should be: If "Shell script result" contains "Open", then turn off ecobee, otherwise turn ecobee into auto [Note: you will have to coerce the shell script result to be text. Tap on 'Shell Script Result' in the If statement. In the window that slides up from the bottom, choose 'as Text' from the popup menu]
** AppleScript ** AppleScript overcomes a number of limitations in the structure of the HomeKit in terms of decision making, etc. In essence, it goes through a list of all the doors and, for each door, extracts the JSON value for the current state of the door. If one or more doors are open, it returns the "Open" result to the speed dial command. If all the doors are closed, it returns "Closed". Create it in the Script Editor and save it to the path you named above. on run args set doorNames to {"sideDoorState", "frontDoorState"} set baseURL to "http: //
[2/25/2021, 2:17:15 PM] [10 minute door open check] The setting switches to true
[2/25/2021, 2:17:17 PM] [10 minute door open check] The setting switches to false
[2/25/2021, 2:17:18 PM] [InsteonLocal] Setting the power status of the ecobee to the car ... In the Terminal window where json-server is running, you will see entries for all JSON GET requests and commands PATCH PATCH / frontDoorState / 1 200 3,050 ms - 154 ...… GET / frontDoorState 200 2,633 ms - 172 I hope it helps you!
HomeKit.Blog is in no way affiliated with or endorsed by Apple Inc. or Apple related subsidiaries.
All images, videos and logos are the copyright of the respective rights holders, and this website does not claim ownership or copyright of the aforementioned.
All information about products mentioned on this site has been collected in good faith. However, the information relating to them, may not be 100% accurate, as we only rely on the information we are able to gather from the companies themselves or the resellers who stock these products, and therefore cannot be held responsible for any inaccuracies arising from the aforementioned sources, or any subsequent changes that are made that we have not been made aware of.
HomeKit.Blog Is A Participant In The Amazon Services LLC Associates Program, An Affiliate Advertising Program Designed To Provide A Means For Sites To Earn Advertising Fees By Advertising And Linking To Amazon Store (Amazon.com, Or Endless.com, MYHABIT.com, SmallParts.com, Or AmazonWireless.com).
The opinions expressed on this website by our contributors do not necessarily represent the views of the website owners.