Hey Siri, should I open my window 🤔 ?
It's been pretty cool (up until recently 😒) at night and I enjoy going to bed with the windows open. I don't know what it is but for some reason, the cool fresh air and increased oxygen in the bedroom make for a night of very enjoyable sleep. 😴
I'm faced with the same question every night and that is "should I open the window?" To answer this I launch the Ecobee app on my phone, drill into the temperature sensor for the bedroom, make note of the temperature, and then look at the weather app for the current outside temperature and compare them. If it's cooler I open my windows otherwise I keep them shut. After doing this for a while I thought to myself I'm too good for this! And wouldn't it be great if Siri could just tell me if I should open my window? After all, she's a personal assistant, isn't she? It's her damn JOB!
Well, it turns out Siri can't do this. Not without help anyway. So I need to implement a solution myself. I need to get the bedroom temperature, the temperature outside, throw some logic in there, and then wire it up all up with Siri.
I need to access my thermostat programmatically and to do that I need to sign up for an Ecobee developer account. This was more difficult than I expected because their sign-up system was not working for me! At first, I thought it was my browser and I tried all the usual browsers Chrome, Safari to no avail, it was something to do with my account. I got on their support chat and thirty minutes later we figured out it was because I have 2FA enabled on my account and their signup is incompatible with it. I had to turn off 2FA within my app and then I was able to sign up.
That's great. I created an app and started reading their API page and figured out how to authenticate and get the proper tokens to make requests. After spending more time with their API I was able to pull the temperature from the bedroom sensor! Step 1 is now complete! 😁
Next, I need to get the outside temperature. In the past, I've used DarkSky's API but unfortunately, they sold out to Apple last year and their API is going to be discontinued after 2021. Bummer. I signed up for Open Weather Map API. Easy signup. Unfortunately, it takes some time for their API keys to be effective so I spend that time looking at how Apple Shortcuts work.
To request your first API in Shortcuts, you create the URL that points at the API “endpoint” that you want to talk to, and then pass that UR
Easily enough. Looks like I need to set up an HTTP server. I downloaded Fastify and started playing with their routes. At this point, my weather API key works so I was able to pull the outside temperature and put it all together.
Next, I created a new shortcut and named it the question I wanted to ask Siri. So I would only need to say "Hey Siri, should I open the window" and Siri will run the shortcut and give me the answer.
Note in the video you can't hear me say the command because the iPhone's screen recording doesn't record the sound from the mic.
This also works from the Apple watch.
The source code is here. https://github.com/hyperlink/open-window-service












