How do I configure a sensor that will tell me if today is a work day?
Currently I have this but it display no before and after work start and end time. I want it to say yes all day unless it’s my day off, which means there will be nothing in the calendar.
jamie_work_day:
friendly_name: "Is Jamie due at work today"
value_template: >-
{% if as_timestamp(now()) | timestamp_custom('%Y-%m-%d') == as_timestamp(states.calendar.jamie_work.attributes.start_time) | timestamp_custom('%Y-%m-%d') %}
Yes
{% else %}
No
{% endif %}
This is a classic problem. This template sensor will not update when time changes because the template does not contain any entity that changes with time.
I didn’t know this existed and it might be useful for some things but I think I’d rather stick with calendar so I can just delete an event when someone has a day off.
You’ll have to tell us a bit about how the state of calendar.jamie_work, and especially its attributes, or at least its start_time attribute, changes throughout the day.
From your first post I had guessed that the issue was you hadn’t written the template correctly (i.e., not using an entity that changes with time.) But now apparently the issue has more to do with your calendar.jamie_work entity. You need to describe its behavior.
Then the template sensor should not be changing to No, so you’re probably wrong about that assumption.
Do you know how to query HA’s database to retrieve all the state changes of this entity? If not, then the next best thing is to turn on some debugging and then check home-assistant.log when it doesn’t work as expected. All the details of all state changes will be recorded in the log. To enable the debug mode add this to your config:
logger:
default: info
logs:
homeassistant.core: debug
The state of the calendar changes after work because that’s when the event is over. The sensor then changes to ‘no’ because it’s looking at the next event which is my next work day.
So as it stands, this will never work as desired because of this.
Might have to go back to the drawing board on this or look into @sleeepy2’s suggestion.