How to change time input with calculation?

Hey, I have lately been looking into improving my wake-up and good-night light automations. Their function is pretty obvious: slowly fade in in the morning and slowly fade out at night.
(Those who have colour-lamps and have not noticed yet: Take a look at the “flux light adjustment” component!)

My current setup is made a bit complex, but it works nicely and in the basics, that’s what I want to keep. On the frontend it shows up as following:

  1. Template Sensor: Reads out the following inputs (2+3) as time-format (HH:MM)
  2. Input-Slider: Sets the hour to call the service
  3. Input-Slider: Sets the minute to call the service
  4. Template Sensor: Shows if today is a workday (for wakeup) or if tomorrow is a workday (for sleep)
  5. Input-Select: Gives me a couple options to choose, workdays only, everyday or manualy selected only
    — These work in conjunction with Nr. 2+3, except Selected only.
  6. 7x an input-boolean followed by input_text for every day in the week. The input-boolean works as “override” on-off and text for the time to use instead.

So far, so good. Now what did bother me here? It’s the way I trigger the automation and how it works with setting the scene. See, scenes have the option to set a transition-time. Since it’s supposed to be a soft wake-up/good-night, they are quite longer than a few seconds. That means, if I want to set a wake-up time, I have to manualy adjust the time for when the automation should trigger, instead of when I set my alarm to wake me up. It’s a bit confusing for anyone else than me, apparently. I want my lights to go on early, and at their peak my alarm should go off.

After messing with templates, I managed to set my sliders accordingly. So actualy my setup is like this now:

  1. Template Sensor: Showing me the time I have set using my sliders. This is the time I want to get up.

  2. (not displayed) Template Sensor: Correcting the time in order to call the lights early by using this line of code:

    sensor:
    platform: template
    sensors:
    alarm_start:
    entity_id: input_number.alarm_hour, input_number.alarm_minute
    value_template: ‘{% if states(“input_number.alarm_minute”)|int < 30 %}{{ “%02d:%02d” | format(states(“input_number.alarm_hour”)|int - 1, states(“input_number.alarm_minute”)|int + 30) }}{% else %}{{ “%02d:%02d” | format(states(“input_number.alarm_hour”)|int, states(“input_number.alarm_minute”)|int - 30) }}{% endif %}’

(sorry for bad format, I can’t seem to fix it)
Then, in my automation I call it using this condition, along with time_pattern as trigger:

- condition: template
  value_template: "{{ states.sensor.time.state == states('sensor.alarm_start') }}"

This works perfectly with my two sliders, which are the easiest way to adjust time. However I don’t want sliders for all my week’s overrides, they clutter up my page and make it look messy. I have concidered moving from input_text to input_datetime, however, both give me headaches. I have not been able to find a solution on how to alter these two inputs into what I need - or alter it in any way.

Is there a way, similar to the above sollution, that I can use to change input_time? So that when I set time to “06:30” that I have a sensor that translates it to “06:00” for my automation?

Bump

Tldr
If I have a input_datetime time_only, and I input 06:00, how can I create a template_sensor that outputs 05:30?

Is there really no sollution?

This subtracts 30 minutes (1800 seconds) from the timestamp attribute of input_datetime.switch_on and then converts it from timestamp format to HH:MM format.

{{ ((states.input_datetime.switch_on.attributes.timestamp | int) - 1800) | timestamp_custom('%H:%M', false)  }}

The false in timestamp_custom indicates the supplied timestamp is referenced to UTC and not local time. I believe this is the correct setting for this particular application. If the result is skewed by several hours from your timezone, either set it to true or simply remove it (the default is true).

Thank you, this line of code does exactly what I need! Wonderful!