Binary_sensor open/close instead of on/off

Good morning,
I have correctly configured a number of sensors ( mysensors with serial gateway) .
The sensors are correctly seen as binary_sensors , and as " opening" category.
the only drawback is that the sensors have been like on / off , you can change it to open / close

Thanks
Mattia

1 Like

I think you can create a binary template sensor that shows custom binary values, based on the state of your mysensors binary sensor.

Would you be willing to provide a pointer or an example of this? I asked the same question in a template thread but got no response. The example in the documentation is a bit confusing and doesn’t really appy to situations like this. I think we’d both appreciate the help!

I have to correct myself. You can’t change what the state values are called for a binary sensor, even for the template binary sensor. They are always either on or off. You can change the sensor class, though. But I guess that wasn’t the question.

Thanks for the reply,
if i change the sensor class, which i can use to have open/close instead of on/off.

Many Thanks
Mattia

If I got it right you want something like this:

binary_sensor:
  platform: template
  sensors:
    viewonlysensor:
      value_template: "{%if states.switch.ENTITY_ID.state == 'on' %}ON{%elif states.switch.ENTITY_ID.state == 'off' %}OFF{% endif %}"
      friendly_name: 'Switch is on?'

I had some door sensors but they had that on/off switch, but I wanted them as view only. You can use templates and you can define a status. Check this thread at the end:

I have tested the solution suggested by @bogdan bogdan, and if i use the Dev Tools “Template Editor” its work , but if i insert the code in configuration.yaml don’t work.
This is the code that i have insert:

binary_sensor:
  platform: template
  sensors:
    viewonlysensor:
      value_template: "{%if states.binary_sensor.doorsensor_temp_5_1.state == 'on' %}Open{%elif states.binary_sensor.doorsensor_temp_5_1.state == 'off' %}Close{% endif %}"
      friendly_name: 'Sensor State'

The value_template is on a single line

2 Likes

The binary sensor have to be able to evaluate the state as true or false. Open and close probably don’t provide that.

I think I get what you are trying to do. I’ve made a feature request here: Customize text of `binary_sensor` on/off state

If it helps anyone, I have my doors reporting open/closed with the following in my configuration.yaml file

sensor:
  - platform: template
    sensors:
      bedroom_door_status:
        value_template: '{% if states.binary_sensor.fibaro_system_fgk10x_door_opening_sensor_sensor_26 %}
          {% if states.binary_sensor.fibaro_system_fgk10x_door_opening_sensor_sensor_26.state == "on" %}
            Open
          {% else %}
            Closed
          {% endif %}
          {% else %}
          n/a
          {% endif %}'
        friendly_name: 'Bedroom Door'
8 Likes

Formatting it exactly this way also eliminates the attribute: none errors on startup as well. I keep meaning to go back and redo my templates this way but I have so many of them…

Thanks!
Works like a charm with my Nexa binary sensor.

/G

I know this is a REALLY old topic :slight_smile: can anyone help me out how to have my drive gates switch show up as open or closed…I have tried and tried but jsut given up :frowning: this is my current code below which works AOK but shows off or on which obviously it isnt!


  • platform: mqtt
    name: Close Gates
    state_topic: “comfort2/response64”
    command_topic: “comfort2/response64/set”
    availability_topic: “comfort2/alarm/online”
    payload_on: “1”
    payload_off: “0”
    payload_available: “1”
    payload_not_available: “0”
  • platform: mqtt
    name: Open Gates
    state_topic: “comfort2/response32”
    command_topic: “comfort2/response32/set”
    availability_topic: “comfort2/alarm/online”
    payload_on: “1”
    payload_off: “0”
    payload_available: “1”
    payload_not_available: “0”
  • platform: template
    switches:
    gates:
    friendly_name: “Drive Gates”
    value_template: “{{ is_state(‘binary_sensor.drive_gate’, ‘on’) }}”
    turn_on:
    service: switch.turn_on
    data:
    entity_id: switch.Open_Gates
    turn_off:
    service: switch.turn_on
    data:
    entity_id: switch.Close_Gates
    icon_template: >-
    {% if is_state(‘binary_sensor.drive_gate’, ‘on’) %}
    mdi:garage-open
    {% else %}
    mdi:garage
    {% endif %}

Good solution, Thanks Phil !

Great Solution…Thanks

I think now a days, you can just use a “helper”.

Been messing around trying to sort this for a little while and kept coming across this post. If anyone wants to do this now in 2020, it is easier. Go to configuration, then to the very bottom under the sub headings General, Server controls, logs and info. You should see ‘Customizations. Customize your entities’

Once inside find your entity for your binary sensor and change your device class to door. That should do it.

Failing that, typing this is the yaml seemed to work for me

homeassistant:
  customize: !include customize.yaml
  friendly_name: binary_sensor.garagedoor
  icon: mdi:garage
  device_class: door
9 Likes

This one helped me out. Thanks!

This suggestion worked really well, thanks for sharing :grinning:

1 Like

Thanks @Gavin_Randall worked great just adding device_class: door to my ESPHome config. This way it stays together in Entities.

Value_template worked as well.

Thanks!

1 Like