Value template if case for different output depending on input?

Hi all,
Hope the title isn’t too confusing - it’s the only way i can think of that applies here.

So… i’m using the timeofdaysensor to render entities in a template:

    counter.greet_{{ states('sensor.time_of_day') }}

This works fine for when times are morning, afternoon, but sometimes a timeofday will be ‘early morning’ and it will render as such. Whereas i created counters that are called counter.greet_early_morning.

How can i work around this? I could update the status of the timeofday sensor to simply add a underscore in between, but that would look ugly in the frontend.

Could i use a if statement of some sort, saying if it’s “Early Morning” make it “Early_Morning” instead?

Hope this makes sense. I can provide the timeofday sensor setup if needed.

Thanks!

{{ counter.greet_{{ states('sensor.time_of_day')|replace(' ','_') }}
1 Like

Fantastic - as usual. I will try this right away.
So if it has no underscore it will just leave the output intact ?

It wil replace all spaces with underscores. That is all.

1 Like