Pass date and time to automation

Hi,

I’m new to HA and been setting up some automations and my latest challenge is to set my alarm using HA.

My idea is to have a dimmable switch that will gradually increase and that part is easy. The hard part is to create a calendar event to start at the desired time.

I’ve created a date and time helper and a button helper to trigger an automation that should create an entry in my calendar. The problem is that I’m not finding a way to pass my datetime helper into the calendar.

Below my YAML for the automation and would appreciate some help on how I can get it to work. End date is fixed for testing purposes, and when I manage to pass the start date and time, I’ll focus on getting 1 second added to my end time (will be another question :wink:)

alias: 022-Set Alarm at specific time
description: ""
trigger:
  - platform: state
    entity_id:
      - input_button.set_alarm_button
condition: []
action:
  - service: calendar.create_event
    data:
      summary: Alarm
      start_date_time: input_datetime.alarm_date_and_time
      end_date_time: "2023-10-19 06:00:01"
    target:
      entity_id: calendar.automations
mode: single

What am I doing wrong? Been reading the documentation and checking other examples, but not getting it.

Thanks

start_date_time: "{{ states('input_datetime.alarm_date_and_time') }}"

Reference

Templating - States

Thanks, that worked.

My second question, any way to add 1 second to my input, so I cam use as end_date_time?

If you want to start dimming a light at a specific time, why not simply use a Time Trigger? It supports an Input Datetime directly.

trigger:
  - platform: time
    at: input_datetime.alarm_date_and_time

That would work to setup a single alarm, but my plan is to set multiple alarms throughout the week and they can be at different times. For example, on Sunday I set all alarms for coming week.

Got it fixed with

{{(((state_attr('input_datetime.alarm_date_and_time' , 'timestamp')) + 60) | timestamp_custom('%Y-%m-%d %H:%M:%S', true))}}