I have the following automation which is partly working.
It sends a message the day before the trash event starts. So if tomorrow is an google calendar event, I receive a notification via telegram, that tomorrow the trash will be collected. But it also sends a notification on the trash day at 18 o clock?
Whats wrong with my code?
id: garbage-notify-1
alias: ‘Yellow Bin Notfication’
trigger:
platform: time
at: ‘18:00:00’
condition:
Anyone an idea how to solve this? I only want to send a notification if tomorrow is a specific event…see my last post.
@sparkydave I already tried to use your code but I observed a weird behaviour. I getting notification for events which are not today / tomorrow. Do you have a working example with the whole code?
# Package to track bin days based on Google Calendar entries and perform reminders
input_boolean:
bin_reminder:
name: Bin Reminder
icon: mdi:delete-outline
initial: on
# https://community.home-assistant.io/t/need-template-assistance-please/80237/7
sensor:
- platform: template
sensors:
recycling_bin_tomorrow:
entity_id:
- calendar.recycling_bin_day
- sensor.time
friendly_name: "Recycling Bin Tomorrow"
value_template: >
{% set e = strptime(
states.calendar.recycling_bin_day.attributes.start_time,
'%Y-%m-%d %H:%M:%S') %}
{{ e.strftime('%j')|int - now().strftime('%j')|int == 1 and now().hour >= 12 }}
- platform: template
sensors:
green_waste_bin_tomorrow:
entity_id:
- calendar.green_waste_bin_day
- sensor.time
friendly_name: "Green Waste Bin Tomorrow"
value_template: >
{% set e = strptime(
states.calendar.green_waste_bin_day.attributes.start_time,
'%Y-%m-%d %H:%M:%S') %}
{{ e.strftime('%j')|int - now().strftime('%j')|int == 1 and now().hour >= 12 }}
- platform: template
sensors:
recycling_bin_today:
friendly_name: "Recycling Bin Today"
value_template: "{{ is_state('calendar.recycling_bin_day', 'on') }}"
- platform: template
sensors:
green_waste_bin_today:
friendly_name: "Green Waste Bin Today"
value_template: "{{ is_state('calendar.green_waste_bin_day', 'on') }}"
automation:
- alias: Bin Reminder TTS
initial_state: 'on'
trigger:
- platform: state
entity_id: sensor.recycling_bin_tomorrow
to: 'True'
- platform: state
entity_id: sensor.green_waste_bin_tomorrow
to: 'True'
- platform: state
entity_id: sensor.recycling_bin_today
to: 'True'
- platform: state
entity_id: sensor.green_waste_bin_today
to: 'True'
condition:
- condition: state
entity_id: input_boolean.bin_reminder
state: 'on'
action:
- wait_template: "{{ is_state('binary_sensor.kitchen_multi_sensor_sensor', 'on') }}"
timeout: '10:00:00'
continue_on_timeout: 'false'
- wait_template: "{{ is_state('media_player.googlehome3019', 'off' or 'idle') }}"
- service: tts.google_say
entity_id: media_player.googlehome3019
data_template:
message: "Dont forget you need to put out the {{ trigger.to_state.attributes.friendly_name }}"
The main reason I have those templates in there is to create a window of time where the sensor: true because I didn’t just want to know if the calendar entry was tomorrow, but only be true in the evening of the day before. You can play with / remove that function however you want.
Once you have a sensor: true, just use that as a trigger for your notification. I only use it for a conditional Lovelace card and the TTS.
I didn’t include it this time because it isn’t needed. That was something I coded in case I was to tell Google to turn off the reminder one day, but the way my wait_template works in the automation, I only get the TTS once anyway. I could just delete it since its actually pointless being there. It was just that I had a thought to remove the wait_template and have the automation fire every time I went into the kitchen until I turned off the reminder input_boolean, but I didn’t go that route in the end.
@sparkydave
Seems to be working - but when I use {{ trigger.to_state.attributes.friendly_name }} in the data_template, no message will be send.
EDIT:
Ok, it seems that data_template is not supported for telegram notifications. Also, when I use only “data” instead of “data_template”, the code in the brackets doesnt work…
The bracket stuff IS the template so HA requires you to use data_template rather than just data. Are you able to try another notification platform in place of telegram for testing purposes? I wasn’t aware of that restriction with Telegram, which I hope can be worked around because I was considering moving my Pushbullet stuff over to Telegram…
When I use telegram with another variable like {{ states.sensor.dark_sky_temperature.state }}, its working fine.
So there is a problem with {{ trigger.to_state.attributes.friendly_name }}
I suddenly remembered why I put the “Reset Bin Reminder” automation in my code… it’s because I have the TTS set to give a reminder the day before AND on the day of bin collection, however if I hear the TTS the day before and go and put the bins out then I dont want the TTS the next day, so I turn OFF the bin reminder input_boolean (using voice with Google Assistant), then the input_boolean will get reset later on the collection night, ready for the next week of TTS announcements. The reason I forgot about that was because I have only just coded this and haven’t yet actually bothered to ask Google to turn off the reminder… I’ve just been letting it run the TTS both days. I need to get in the habit of doing so if I put the bins out the day before, which is very common for me.
Has anyone worked out how to find a calendar event which does NOT match a string ?
I want to find the next event ignoring ones with a certain phrase in.
@petro thanks for responding. Look up google calendar integration. When setting up the calendar settings there is one called ‘search’ which, at the simple level, will cause it to only include events which contain a string. But there is an indication that it uses regex. I tried ^((?!Airbnb).)*$ to exclude items with Airbnb in to no avail.