Binary Sensor Changing State Text

Hello,

I hope you can help me. I want to change the text of the state from on/off to open/close.

I have this code in the configuration.yaml:

platform:
template sensors:
Garage open/close:
friendly_name: Garage open/close
entity_id: binary_sensor.shelly1_bcddc277829e_external_input
value_template: > {% if is_state(‘binary_sensor.shelly1_bcddc277829e_external_input’, ‘on’) %}open {% else %}closed{% endif %}

Wenn i check the configuration the system writes a failure.

Can you help me to reach my result?

Thanks in advance,
Dominik

Please format your pasted code so we can see what is wrong.

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly

If you apply the garage_door device class it will change the displayed state to open/closed (the actual state will still be on/off). The garage icon will change from open to closed with the state as well.

https://www.home-assistant.io/integrations/binary_sensor/#device-class

Hello! Thanks for your answer! I cannot change the device class. When I change the class, a few moments later the class is “Power”.

Thanks!!

Here is the formatted code:

- platform: template
  sensors:
    Garage:
      friendly_name: Garage offen/geschlossen
      entity_id: switch.shelly1_bcddc277829e
      value_template: 
        {% if is_state('binary_sensor.shelly1_bcddc277829e_external_input', 'on') %}
          Running
        {% else %}
          Stopped
        {% endif %}```

Here is also a Screenshot of the binary sensor

This is confusing. Which entity are you trying to change the icon of, the switch or the binary sensor?

I think all you need to do is go to Configuration / Entities and find binary_sensor.shelly1_bcddc277829e_external_input.

Click on it and change the “Show As” dropdown list selection.

I want to change the binary sensor. Now it Shows only on/off. And I want the status open/close of my Garage door.

Thanks

Go to Configuration / Integrations and select your Shelly device. Find the binary sensor on the device page and click on it. There should be a setting for “Show As”, set that then click the update button.

If there is not a a Show As option then put this in your configuration.yaml file:

homeassistant:
  customize: !include customize.yaml

Create the file config/customize.yaml and put this in it:

binary_sensor.shelly1_bcddc277829e_external_input:
  device_class: garage_door
1 Like

Thanks for your help! Now it works fine!!!

Did you do it though the UI or by using customize.yaml?

1 Like

Yes! Because the Show As option is not available

There are the settings of the binary sensor. Unfortunately no Show As option. But your code in the customize.yaml works fine.

But another question.

Is it possible to change the Icon depending on state?

Closed should be icon “mdi:garage-variant”
Open should be icon “mdi:garage-open-variant”

thanks!

The device class should do that automatically. Are you not seeing this?

No, unfortunally the class take the same Symbol.

Now its closed. Here you can see the screenshot

Yeah I’ve just noticed my device classes aren’t applying icons correctly either. I’ll open an issue.

1 Like