Using Timepick and Sensor to set wakeup alarm

Hello everyone,

I’ve been trying to set up a timestamp sensor for my needs for a few days now.

The origin is the implementation of the blueprint:

This requires a sensor with a timestamp:

I have set up a helper for this and built the following card:

grafik

type: vertical-stack
cards:
  - type: markdown
    content: '## Wecker'
  - type: horizontal-stack
    cards:
      - type: vertical-stack
        cards:
          - type: vertical-stack
            cards:
              - type: markdown
                content: >-
                  ### {{ as_timestamp(states("sensor.alarm_time_paul") |
                  as_datetime | as_local) | timestamp_custom('%d.%m.%Y - %H:%M
                  Uhr') }}
              - type: entities
                entities:
                  - entity: automation.paul_wecker
                    icon: mdi:bed-clock
                    name: 'Wecker '
      - type: custom:time-picker-card
        entity: input_datetime.paulsetwecker
        hour_mode: 24
        hour_step: 1
        minute_step: 15
        layout:
          hour_mode: double
          align_controls: center
          name: header
          embedded: false
          thin: true
        hide:
          seconds: true
          icon: false
          name: false
        name: Weckzeit einstellen
        link_values: false
  - type: markdown
    content: Wenn ausgeschaltet, erfolgt keine Erinnerung an das Wiegen

My sensor in the configuration looks like this:

template:
  - sensor:
      - name: "alarm_time_paul"
        state: '{{ states("input_datetime.PaulSetWecker") | as_datetime | as_local }}'
        device_class: timestamp

The intention is that when the alarm time is selected, this time is set for the next day and is also automatically active for all subsequent days. I have specified a workday sensor accordingly in the blueprint and manual deactivation is possible using a switch.

My problems, and I’m hoping for help because I don’t know how to go about this:

a) When selecting the time using the timepicker, not only the time should be set, but also the next days or even 24 hours (86400 seconds) should be added.

b) The timestamp must always be set automatically for the next day. I think this is where I need to start with the sensor, but I honestly don’t know how.

Many thanks in advance for your help

Chris

Half solved, for the winter time changeover I have to adjust something again. It would be nice if this worked every 6 months without any adjustments.

Unfortunately, I haven’t found a solution to my problem, but I think I’m doing something wrong.

In any case, I had to adjust some templates after the time change.

Solved.

{{ (now().replace(
    hour=states('input_datetime.paulsetwecker')[-8:][:2]|int,
    minute=states('input_datetime.paulsetwecker')[-5:][:2]|int,
    second=states('input_datetime.paulsetwecker')[-2:][:2]|int
)).astimezone().isoformat() }}

That would show today also in the evening, when the alarm should go off next day. To add a day to the alarm after it goes off, try this (untested):

{{ states('input_datetime.paulsetwecker') | as_datetime | as_local + timedelta(days=1) }}

Hey, thank you, but with the solution, I have to make the adjustment again for the time changes. I had a solution like this before. I have now found a better solution and posted about it here. Thank you for taking the time.

If it does not work, then timedelta does not respect the difference between a day and 24 hours when adding to a date with time zone information. That is a hame, because it should be different when daylight savings changed inbetween. In that case, a day is not 24 hours but 23 or 25.