OMG I already built that… ughhhhhhh it’s in my sensor dir…
- platform: template
sensors:
bed_sensor_contact:
value_template: >-
{% if is_state('binary_sensor.bed_sensor_contact2', 'closed') %}
In Bed
{% else %}
Out of bed
{% endif %}
Just need to modify it a bit… Sorry for wasting everyone’s time. Thank you!
Interesting or I’m missing something really simple but I get no change from this…it still says Open
- platform: template
sensors:
bed_sensor_contact:
value_template: >-
{% if states('binary_sensor.bed_sensor_contact_2', 'Open') %}
Out of Bed
{% else %}
In bed
{% endif %}
- platform: template
sensors:
bed_sensor_contact:
value_template: >-
{% if is_state('binary_sensor.bed_sensor_contact_2', 'on') %}
Out of Bed
{% else %}
In bed
{% endif %}
- platform: template
sensors:
bed_sensor_contact:
value_template: "{{ 'Out of Bed' if is_state('binary_sensor.bed_sensor_contact_2', 'on') else 'In Bed' }}"
Look in developer tools / sates. That is the best place to see what the actual state of your entity is.
Lovelace can change the display of binary sensors from states on or off and display them as other formats depending on what device class is applied. This does not change the underlying state that is always on or off though. Look at all the display possibilities for the on or offstates here:
That was what I was on about before. You could apply the device_class occupancy to your bed sensor and Lovelace would show Occupied or Clear and this would not require an additional template sensor.
You can apply any device class to your bed binary sensor using customize.
Added the customize to customize.yaml - Developer tools says ‘on’ my HA screen says Detected…since it’s now an occupancy device but nothing is changing what I want to show on the screen… which is in bed or out of bed…
This is what the Developer Tools state shows:
Since I changed the device type to occupancy this is what my screen shows:
I also have this:
- platform: template
sensors:
bed_sensor_contact:
value_template: >-
{% if is_state('binary_sensor.bed_sensor_contact_2', 'on') %}
Out of Bed
{% else %}
In bed
{% endif %}
So it looks like I have too many wires crossed and it’s just not working…
Ok so the device class is working. It’s just that the documentation is incorrect. The text says “occupied” but the image shows “detected”. I’ll update the docs.
Undo the the device class additions and go with petro’s solution.
Yes I have this in my config… not actual sensor section but a seperate file
sensor: !include_dir_merge_list includes/sensors/
And I have put this called bed.yaml in the sensor dir
- platform: template
sensors:
bed_sensor_contact_2:
value_template: >-
{% if is_state('binary_sensor.bed_sensor_contact_2', 'on') %}
Out of Bed
{% else %}
In bed
{% endif %}
And I still get 'Open" on the frontend … so not sure what’s going on. The Developer Tools says ‘on’ so I used that… so in theory it should be working… it’s just not.