Switch with difference calls depending on time of day

Hi

Im trying to make a, goodmorning, goodnight kinda switch.
I want it to change “name or whatever” depending on the time of day.
So for example when the switch is pushed between 05:00 and 10:00 it will call my “goodmorning script”
And pushed between 21:00 and 02:00 it will call a “goodnight script”

So in my front end i want the switch to be named either goodmorning or goodnight, depending on the time of day.

What is the best way to do this. ?

Best regards

don’t think you can change the name dynamically but you can defo have the switch do something different with a service_template

Thanks
I will definitely try this.
Do you know how the if syntax with a time condition should look like.

ex.
If (time after 9:00 and before 11:00)
script.goodmorning
else
script goodnight

best regards

try this:

service: script.turn_on
data_template:
  entity_id: >
    {% if (as_timestamp(now()) | timestamp_custom("%H") | int) >= 8 and (as_timestamp(now()) | timestamp_custom("%H") | int) < 11 %}script.goodmorning{% elif (as_timestamp(now()) | timestamp_custom("%H") | int) < 2 or (as_timestamp(now()) | timestamp_custom("%H") | int) >= 21 %}script.goodnight{% endif %}