Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save petersem/51b02c79c4686b1d2d66ab37bafd96fb to your computer and use it in GitHub Desktop.
Save petersem/51b02c79c4686b1d2d66ab37bafd96fb to your computer and use it in GitHub Desktop.
Home Assistant - Notify when time to leave for work
# binary_sensors.yaml
#
# Work day
#
- platform: workday
country: AU
workdays: [mon,tue,wed,thu,fri]
# templates.yaml
#
# Leave for work
#
- trigger:
- platform: time_pattern
minutes: "/1"
# the /1 signifies to refresh every minute.
- platform: homeassistant
event: start
sensors:
leave_for_work:
friendly_name: "Leave for work"
icon_template: "mdi:clock"
# time to leave value is decimal, so 8.5 = 8:30, 9.25 = 9:15, etc
value_template: >-
{% set t = strptime(states.sensor.time.state,'%H:%M') %}
{% if (( t.hour + (t.minute/60)) > (8.5 - states.sensor.waze_city | int /60)) and (( t.hour + (t.minute/60)) < 8.5 ) and (is_state('binary_sensor.workday_sensor','on')) %}
true
{% else %}
false
{% endif %}
# automations.yaml
alias: leave for work
description: Trigger an alert if it is time to leave for work
trigger:
- platform: state
entity_id:
- sensor.leave_for_work
to: 'true'
condition: []
action:
- service: telegram_bot.send_message
data:
message: Time to go
title: Leave for work
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment