Hello all! Thank you for this update. It has allowed me to do something I’ve wanted to for over a year:
Create a “sensor” that turns on and off based on the Daytime High and Overnight Low temperatures, then pass these “sensors” on to HomeKit (which show up as Occupancy sensors) to allow for thermostat Automations in the Apple Home app.
It took me quite a few days (probably easy for a more advanced user…) to figure out how best to leverage the triggers, so I thought I would share my experience and some of the configurations below.
Tools Needed:
I currently use the DarkSky weather tool to detect these values:
- sensor.weather_daytime_high_temperature_0d
- sensor.weather_overnight_low_temperature_0d
- sensor.weather_temperature
Code in my configuration.yaml for DarkSky setup:
sensor:
# Weather Prediction
- platform: darksky
api_key: ---KEY---
name: Weather
forecast:
- 0
monitored_conditions:
- temperature
- temperature_high
- temperature_low
With this release, I was able to create the following Template Trigger in my configuration.yaml:
template:
- trigger:
- platform: time_pattern
minutes: "/30"
binary_sensor:
- name: "Hot Day"
state: >-
{% if states('sensor.weather_daytime_high_temperature_0d')|float > 22 %}
true
{% else %}
false
{% endif %}
device_class: heat
auto_off: 300
- name: "Cold Day"
state: >-
{% if states('sensor.weather_daytime_high_temperature_0d')|float < 22 %}
true
{% else %}
false
{% endif %}
device_class: cold
auto_off: 300
- name: "Hot Night"
state: >-
{% if states('sensor.weather_overnight_low_temperature_0d')|float > 16 %}
true
{% else %}
false
{% endif %}
device_class: heat
auto_off: 300
- name: "Cold Night"
state: >-
{% if states('sensor.weather_overnight_low_temperature_0d')|float < 16 %}
true
{% else %}
false
{% endif %}
device_class: cold
auto_off: 300
The configuration above creates a Trigger that runs every 30 minutes and checks the Daytime High and Overnight Low temperature and sets the appropriate binary_sensor to “on”, then turns them off after 5 minutes (300 seconds).
This update allowed me to turn them “off”. Previously, I did not have an automated way of turning the sensor “off” after it was triggered without rebooting HA or manually setting the sensor’s state to “off”. The reason I needed to turn them off was to allow for HomeKit to detect that the sensor had been turned “on” to run the Automations.
I use HomeKit Automations to run the AC or Heaters based on:
- if someone is home or not (different temperatures are set for Home vs Away)
- the time of day (Daytime or Nighttime) and
- if the specific sensor (Hot or Cold) is triggered for the time period.
I am certain there is probably an “easier” way to do this and that I can further clean up the configuration above, so I am definitely open to suggestions. Also, if you would like to see the Scenes and Automations I have in HomeKit, I can take screenshots and share. Please just let me know.
I know this was a fairly longwinded post, but I thought it might be useful to someone out there. Thanks for reading!