So I have what I think is called a template value sensor in configuration.yaml:
# TOD@Home - Time Of Day
- platform: template
sensors:
time_of_day:
friendly_name: TOD@Home
value_template: >
{% set t = now() %}
{% if (as_timestamp(t) - state_attr('input_datetime.offset_time', 'timestamp')) | timestamp_custom('%Hh:%Mm') < as_timestamp(states.sensor.date.state ~ " 06:30:00") | timestamp_custom('%Hh:%Mm') %} Night
{% elif (as_timestamp(t) - state_attr('input_datetime.offset_time', 'timestamp')) | timestamp_custom('%Hh:%Mm') < as_timestamp(states.sensor.date.state ~ " 07:30:00") | timestamp_custom('%Hh:%Mm') %} Early Morning
{% elif (as_timestamp(t) - state_attr('input_datetime.offset_time', 'timestamp')) | timestamp_custom('%Hh:%Mm') < as_timestamp(states.sensor.date.state ~ " 09:30:00") | timestamp_custom('%Hh:%Mm') %} Morning
{% elif (as_timestamp(t) - state_attr('input_datetime.offset_time', 'timestamp')) | timestamp_custom('%Hh:%Mm') < as_timestamp(states.sensor.date.state ~ " 16:15:00") | timestamp_custom('%Hh:%Mm') %} Day
{% elif (as_timestamp(t) - state_attr('input_datetime.offset_time', 'timestamp')) | timestamp_custom('%Hh:%Mm') < as_timestamp(states.sensor.date.state ~ " 17:45:00") | timestamp_custom('%Hh:%Mm') %} Afternoon
{% elif (as_timestamp(t) - state_attr('input_datetime.offset_time', 'timestamp')) | timestamp_custom('%Hh:%Mm') < as_timestamp(states.sensor.date.state ~ " 19:15:00") | timestamp_custom('%Hh:%Mm') %} Dinner
{% elif (as_timestamp(t) - state_attr('input_datetime.offset_time', 'timestamp')) | timestamp_custom('%Hh:%Mm') < as_timestamp(states.sensor.date.state ~ " 21:30:00") | timestamp_custom('%Hh:%Mm') %} Evening
{% elif (as_timestamp(t) - state_attr('input_datetime.offset_time', 'timestamp')) | timestamp_custom('%Hh:%Mm') < as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom('%Hh:%Mm') %} Evening
{% elif (as_timestamp(t) - state_attr('input_datetime.offset_time', 'timestamp')) | timestamp_custom('%Hh:%Mm') < as_timestamp(states.sensor.date.state ~ " 23:00:00") | timestamp_custom('%Hh:%Mm') %} Turn Down
{% else %} Night
{% endif %}
Now this works just perfect, except one minor thing… When I create an automation, and I would test the value of the TOD@Home, I can not get it to create a drop down list of possible choices, I just seem to get a free text field. This I think is due to me not getting a correct understanding of how all this template sensor works. Now I know there is the “helpers” (under integration) , so I tried that but no difference, so it is clear for me I don’t understand this, or it is not supported?
How can I change the above to enable only the valid “text” (Day, Night and so on in this case) to be availabel when triggering an automation?