In this example, we want to monitor the temperature in a greenhouse. We want a notification to warn us if it gets too low or too high. Additionally, the Notification should include the current temperature. We can do this by overriding the Notification text when we trigger it.
We need three things to make this work.
- An Instant Notification that tells us that something is wrong.
- A Shortcut to trigger the Notification and replace its text and title.
- An Automation to trigger the Shortcut.
We’ll use a simple Instant Notification that we’ll receive as soon as the Automation is triggered. Our Shortcut will later overwrite its text and title.
- Go to Notifications, add the new Instant Notification and give it a title. This is still important because it is part of the trigger URL.
- Select ‘time-sensitive’ as the interruption level because we always want to know if the temperature is off even when we’re in focus mode or something similar.
- Choose ‘Keep All Notifications’ as behavior because we want to see how often and how long the temperature was invalid.
- Finally, select the devices that should receive the Notification.
You can find the URL that will trigger this Notification at the end of the Notification settings. Copy it to your clipboard by tapping it. You’ll need that URL in the Shortcut that we’ll create next.
At this point, we need to build a connection between HomeKit and Controllers Notification Server. That is possible with Apple’s Shortcuts app. If you need to get more familiar with Shortcuts, you can learn more about them here.
- Open the Shortcuts app, switch to the Automation tab and tap the plus icon in the upper-right corner.
- Select ‘Create Home Automation. That will create an Automation in HomeKit, that we can customize in the next step.
- Select ‘A Sensor Detects Something’ as the event and tap next.
- We’ll change the start event later in Controller for HomeKit because Shortcuts can’t handle the events we need. However, first, we need to select a temporary event. Select the temperature sensor and tap next twice.
- Here you choose what the Automation will do. Scroll down to the bottom of the list and choose ‘Convert to Shortcut.’
- At this point, we have an HomeKit Automation that will trigger a Shortcut. In the Shortcut, delete the ‘Set Scenes and Accessories’ action.
- Use the search bar on the bottom to search for the ‘Get the state of <your home name>’ action and add it.
- Tap on ‘Accessory State’ and select your temperature sensor. That will read the current value and save it into a variable we can use later.
- Search for the ‘Get Contents of URL’ action in the search bar on the bottom and add it.
- Paste the URL you copied from our Notification in the URL field.
- Tap the arrow in the action to expand the advanced settings.
- Change the ‘Method’ from GET to POST. That allows you to send parameters to our server.
- Add a new field of the type ‘text.’ Use ‘title’ as the key. The text of this field will replace the title of your Notification.
- Add a second field of the type ‘text.’ Use ‘text’ as the key. The text of this field will replace the text of your Notification. Note that the keyboard suggestions will include ‘Current Temperature.’ Tap on this to insert the value of the variable into your text.
- Finally, tap next to finish the Shortcut.
When you tap ‘Test this Automation,’ you should receive the Notification with the title and text you just defined. It should contain the current temperature of your sensor. Finally, tap ‘Done’ and then close the Shortcuts app.
At last, we need to configure the Automation that will trigger the Shortcut. The previous step already created it, but we need to adjust it because the Shortcut app only supports a few possible Automation settings.
- Open Controller again, go to Automations, and open the new Automation.
- Give the Automation a more meaningful name.
- Now, we’re going to change the start event. Tap the current start event, select ‘Each value change,’ and tap ‘Save.’
- Now you’ll always get a message if your temperature sensor changes its value. However, that could get annoying quickly, so we’re going to add conditions now. Tap ‘AND the following conditions are met’ and choose Accessory.
- Navigate to your temperature sensor and select its Current Temperature. Use ‘less than’ as the comparison operator, and choose the lowest acceptable temperature as the value. I use 30°C in my example.
- Add another condition and choose your temperature sensor again. This time use ‘greater than’ and enter the highest acceptable temperature as the value. I use 40°C in my example.
- At last, switch from ‘All’ to ‘Any’ so your Automation will run if either of the conditions is true.
That’s it. Controller for HomeKit will now keep an eye on your temperature and let you know if it’s off. If you like this, look at our Advanced HomeKit Notifications Documentation. We have some other great examples there!