I have a template sensor that creates a text string with a description and a time to help me do things in time. The generated string is based on the current time and various sensors upon which I create some logic.
A short example of the template sensor:
{# States #}
{% set ts_now = as_timestamp(now()) %}
{% set asleep = states('input_boolean.is_asleep') %}
{# Event times #}
{% set leftbedtime = states('input_datetime.left_bed')|as_timestamp %}
{% set most_recent_med_time = states('input_datetime.latest_medicine')|as_timestamp %}
{% set most_recent_food_time = states('input_datetime.latest_food')|as_timestamp %}
{# Relative times #}
{% set timesincebed = (now()|as_timestamp)-leftbedtime %}
{% set timesincemedicine = (now()|as_timestamp)-most_recent_med_time %}
{% set timesincefood = (now()|as_timestamp)-most_recent_food_time %}
{% if asleep == "on" %} Wake up! (06:30)
{% elif timesincemedicine > 6*3600 %}
Take medicine! ({{leftbedtime+10*60|timestamp_custom('%H:%M:%S')}})
{% elif timesincefood > 6*3600 %}
Eat! ({{most_recent_food_time +8*3600|timestamp_custom('%H:%M:%S')}})
{% endif %}
So when I am asleep, the sensor will always tell me to wake up at 6:30.
If I left bed at 6:45, it will tell me to take medicine at 6:55.
After having taken the medicine, it will tell me to eat, and a time 8 hours after previous meal.
Now, I would want to separate the description (âwake upâ, âeatâ, âtake medicineâ) from the suggested time, into two sensors. My idea is to let this template sensor deliver a list entry and then create two other sensors that just present the first or the second part of that list as its sensor value.
Problem is, I tried to generate a list in the template editor, but it only worked with static strings, not with variables. Can you suggest a way to change the template above so that it returns a list instead of a text?