Hoping someone can help me figure out how to include a Google calendar’s event title and date/time in the notification.
The way I have it setup now I get the friendly name of an input boolean which works. What I’d like to happen instead is receive the calendar events message
and date_time
.
Here is how I currently have the setup.
I have 3 different “moon sensors” that turns ‘on’ 24 hours before the calendar event matches full_moon
, lunar_eclipse
or solar_eclipse
.
###### MOON SENSORS ######
- platform: template
sensors:
full_moon:
friendly_name: Full Moon
value_template: >
{% set ct = states('sensor.date_time') %}
{% set ct = as_timestamp(strptime(ct,'%Y-%m-%d, %H:%M')) %}
{% if as_timestamp(states.calendar.moon.attributes.start_time) - as_timestamp( strptime(states.sensor.date_time.state, "%Y-%m-%d, %H:%M" ) ) < 86400 and 'Full moon' in states.calendar.moon.attributes.message%}
on
{% else %}
off
{% endif %}
- platform: template
sensors:
lunar_eclipse:
friendly_name: Lunar Eclipse
value_template: >
{% set ct = states('sensor.date_time') %}
{% set ct = as_timestamp(strptime(ct,'%Y-%m-%d, %H:%M')) %}
{% if as_timestamp(states.calendar.moon.attributes.start_time) - as_timestamp( strptime(states.sensor.date_time.state, "%Y-%m-%d, %H:%M" ) ) < 86400 and 'Lunar eclipse' in states.calendar.moon.attributes.message%}
on
{% else %}
off
{% endif %}
- platform: template
sensors:
solar_eclipse:
friendly_name: Solar Eclipse
value_template: >
{% set ct = states('sensor.date_time') %}
{% set ct = as_timestamp(strptime(ct,'%Y-%m-%d, %H:%M')) %}
{% if as_timestamp(states.calendar.moon.attributes.start_time) - as_timestamp( strptime(states.sensor.date_time.state, "%Y-%m-%d, %H:%M" ) ) < 86400 and 'Solar eclipse' in states.calendar.moon.attributes.message%}
on
{% else %}
off
{% endif %}
When the sensor turns ‘on’ it triggers an automation to turn on an input_boolean
for that sensor.
- alias: 'Full Moon Input Boolean'
trigger:
- platform: state
entity_id: sensor.full_moon
to: 'on'
action:
service: input_boolean.turn_on
entity_id: input_boolean.full_moon
- alias: 'Lunar Eclipse Input Boolean'
trigger:
- platform: state
entity_id: sensor.lunar_eclipse
to: 'on'
action:
service: input_boolean.turn_on
entity_id: input_boolean.lunar_eclipse
- alias: 'Solar Eclipse Input Boolean'
trigger:
- platform: state
entity_id: sensor.solar_eclipse
to: 'on'
action:
service: input_boolean.turn_on
entity_id: input_boolean.solar_eclipse
Lastly, is an automation that runs every 3 hours between 8am and 10pm to check if one of three input booleans are turned on.
The input booleans are in a group together called group.moon
. The notification includes the friendly name of the input boolean that is turned on.
I would like to figure out if I can include the date and time of the calendar event in the notification. That way I will know when the lunar event is happening.
- alias: 'Moon Notification'
trigger:
- platform: time_pattern
hours: "/3"
condition:
- condition: state
entity_id: group.moon
state: 'on'
- condition: time
after: '08:00:00'
before: '22:00:00'
action:
- service: notify.shelby_and_drew
data:
title: "Moon Event"
message: >
{{ states | selectattr('entity_id','in', state_attr('group.moon','entity_id')) | selectattr('state','eq','on') | map(attribute='name') | join(', ') }}
- delay:
seconds: 5
- service: input_boolean.turn_off
entity_id: input_boolean.full_moon, input_boolean.lunar_eclipse, input_boolean.solar_eclipse