Last active
May 7, 2022 02:03
-
-
Save petersem/51b02c79c4686b1d2d66ab37bafd96fb to your computer and use it in GitHub Desktop.
Home Assistant - Notify when time to leave for work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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