There’s no device_class that can make a binary_sensor display its states in the UI as yes/no so you’ll have to settle for on/off. If that’s unacceptable, then it will have to be defined as sensor because it can display whatever you want.
I’ll post examples for both. Personally, I would choose a binary_sensor but it’s your choice.
This is the template for a binary_sensor. You can test it by pasting it into the Template Editor.
{{ state_attr('input_datetime.vacation_first_date', 'timestamp') <= now().timestamp() <= state_attr('input_datetime.vacation_last_date', 'timestamp') }}
Here are two ways to define a Template Binary Sensor in Home Assistant. The first one is the new way and the second is the traditional way (now called “legacy”).
click to reveal
template:
binary_sensor:
- name: On Vacation
state: >
{{ state_attr('input_datetime.vacation_first_date', 'timestamp') <= now().timestamp() <= state_attr('input_datetime.vacation_last_date', 'timestamp') }}
binary_sensor:
- platform: template
sensors:
on_vacation:
friendly_name: On Vacation
value_template: >
{{ state_attr('input_datetime.vacation_first_date', 'timestamp') <= now().timestamp() <= state_attr('input_datetime.vacation_last_date', 'timestamp') }}
This is the template for a sensor. You can test it by pasting it into the Template Editor.
{{ 'yes' if state_attr('input_datetime.vacation_first_date', 'timestamp') <= now().timestamp() <= state_attr('input_datetime.vacation_last_date', 'timestamp') else 'no' }}
Here are two ways to define a Template Sensor in Home Assistant. The first one is the new way and the second is the traditional way.
click to reveal
template:
sensor:
- name: On Vacation
state: >
{{ 'yes' if state_attr('input_datetime.vacation_first_date', 'timestamp') <= now().timestamp() <= state_attr('input_datetime.vacation_last_date', 'timestamp') else 'no' }}
sensor:
- platform: template
sensors:
on_vacation:
friendly_name: On Vacation
value_template: >
{{ 'yes' if state_attr('input_datetime.vacation_first_date', 'timestamp') <= now().timestamp() <= state_attr('input_datetime.vacation_last_date', 'timestamp') else 'no' }}
EDIT
Correction. Removed unnecessary hyphens.