I have been trying to setup a couple of buttons to add local calendar entries. The idea is that have a couple of buttons to setup a new calendar event to heat our geyser the next day for a specific window.
For example:
And so on. I was hoping I can use a template to set tomorrow’s date at a specific time. But I get parsing errors when trying to do that.
I have tried a couple of different things, and the documentation isn’t quite clear on it. Can you use templates for the start / end date of an event?
In the example below I just wanted to test the start/end for now, but didn’t seem to work.
type: custom:mushroom-template-card
primary: '6:25'
secondary: ''
icon: mdi:alarm
entity: calendar.geyser_timer
layout: vertical
hold_action:
action: none
double_tap_action:
action: none
tap_action:
action: call-service
service: calendar.create_event
target:
entity_id: calendar.geyser_timer
data:
summary: Workout
description: ''
start_date_time: '{{ now().strftime("%Y-%m-%d %H:%M:%S") }}'
end_date_time: '{{ now().strftime("%Y-%m-%d %H:%M:%S") }}'
If it is possible, any chance someone has an example for me?
I originally had this boi:
start_date_time: <-
{%- set desired_time = "06:25:00" -%}
'{{- (now().replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(days=1)).strftime('%Y-%m-%d') + " " + desired_time -}}'
end_date_time: <-
{%- set desired_time = "07:00:00" -%}
'{{ (now().replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(days=1)).strftime('%Y-%m-%d') + " " + desired_time }}'
Example of the error I get, which makes me think it doesn’t support templates:
Failed to call service calendar/create_event. Invalid datetime specified: <- {%- set desired_time = "06:25:00" -%} '{{- (now().replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(days=1)).strftime('%Y-%m-%d') + " " + desired_time -}}' for dictionary value @ data['start_date_time']
The likely issue is that you are trying to do this directly in a card… The Mushroom template card docs do not explicitly say actions can contain templates. This is common in most dashboard cards. The method used for button cards and other card with actions is to have the action call a script which contains your templating.
I don’t understand how that is related, the actions themselves are base HA stuff isn’t it? I see what you mean. It only has a few fields supporting templates.
Any suggestions on anything else I can use to achieve this? Will a regular button do?
You will have the same issue with a button card.
Create a script that does what you want:
alias: Set Geyser Calendar
description: 'Create a custom entry in the Geyser Calendar at a specific time'
fields:
summary:
name: Event Summary
description: The summary or title for the calendar event
example: Workout
start:
name: Event Summary
description: >
The time the calendar event should start ("HH:MM").
Times of day after the current time will be pushed to tomorrow.
example: "06:25"
end:
name: End Time
description: >
The time the calendar event should end ("HH:MM").
Times of day after the current time will be pushed to tomorrow.
example:
sequence:
- service: calendar.create_event
target:
entity_id: calendar.geyser_timer
data:
summary: "{{ summary }}"
description: ''
start_date_time: >
{% set x = today_at(start) %}
{{ x + timedelta(days=1) if now() > x else x }}
end_date_time: >
{% set x = today_at(end) %}
{{ x + timedelta(days=1) if now() > x else x }}
Setup your card(s) to call the script and pass the relevant variable values:
type: custom:mushroom-template-card
primary: '6:25'
secondary: ''
icon: mdi:alarm
entity: calendar.geyser_timer
layout: vertical
hold_action:
action: none
double_tap_action:
action: none
tap_action:
action: call-service
service: script.set_geyser_calendar
service_data:
summary: Workout
start: "06:25"
end: "07:00"
1 Like
Awesome thank you Drew! Much appreciated, I will try it out
Works like a charm, thank you so much Will teach me to learn about the scripts a bit more