There are times when a binary sensor is used in an unconventional application where I would like to reverse open vs closed, wet vs dry, etc. I would be nice to have a switch or checkbox in the entity customization menu or manually through yaml to invert the displayed state.
Depending on the device class, open and closed, wet and dry, clear and detected would be reversed based on the sensor state.
This would eliminate the need to hide the original sensor and create a separate template sensor for this purpose.
THIS. I have a contact sensor on my bathroom door and I always have to remember to reverse it in automations. Thanks for the tip about using a template sensor for this though.
Inverting the actual states would be nice. However, if it is more difficult to implement or causes unforeseen negative side-effects, then the display version would still be helpful.
Here is a simple way to invert the state using a template sensor.
binary_sensor:
- platform: template
sensors:
new sensor name:
friendly_name: 'xxxxx'
value_template: '{{ is_state("binary_sensor.original_sensor", "off") }}'
device_class: xxxx
attribute_templates:
battery_level: '{{ state_attr("binary_sensor.original_sensor_,"battery_level") }}'
Remember to grab your attributes from the original sensor if you want them to appear on the new one.
Another application for this would be where the status of a relay is on to switch something off, and you are viewing the state of the relay for the state of the device
I’m having a hard time getting the battery level to get passed through. Anyone have a thought as to how to handle that? The original sensor ID is: sensor.window_door_sensor_battery_level My code is: