Using an input boolean as a virtual door sensor?

So I configured the input boolean

input_boolean:
  chicken_door_input_boolean:
    name: Chicken Door
    icon: mdi:door

Then I did a template for a sensor like I’ve done in the past with my binary sensors but this time using the input_boolean

- platform: template
  sensors:
    chicken_door_sensor:
      value_template: '{% if states.input_boolean.chicken_door_input_boolean %}
        {% if states.input_boolean.chicken_door_input_boolean == "on" %}
          open
        {% else %}
          closed
        {% endif %}
        {% else %}
        n/a
        {% endif %}'
      friendly_name: 'Chicken Door Sensor'

But whenever I toggle the input_boolean the sensor never changes its state. I’ve double checked my spelling and as far as I can tell it looks like it “should” work. Tailed the logs while I was toggling it and the logs never dumped out anything in regards to the input.

Thanks for all of your help you wonderful community.

Not exactly sure why you would create a template sensor from an input_boolean :slight_smile:, but:

- platform: template
  sensors:
    chicken_door_sensor:
      value_template: >
        {{ 'open' if is_state('input_boolean.chicken_door_input_boolean', 'on')
           else 'closed' }}
      friendly_name: 'Chicken Door Sensor'
1 Like

I don’t have an actual door sensor on the chicken coop. But I have a virtual door sensor in SmartThings and since I"m moving over to HA. I have my automation setup to set the door sensor to open when the switch that opens the door is turned on in the morning and then closed when its turned on again in the afternoon. Its really simple and I couldn’t think of a better way in HA to create a virtual door sensor. :slight_smile: Always open to suggestions.

Also thank you for the fix it works like a champ. Now to wait for 20 mins post sunset for my new NodeRed automation to close their door and set the state.

What happens if you just customize the input_boolean and set a device_class to door? It can be done in the UI or via yaml with a simple change.

I think it should work… from the UI it will look like a door sensor, which I assume is what you want. The icon will show an open or closed door with different colors, and the display value will be “Open” or “Closed”. It will still function as an input boolean for automations and services.

Otherwise, I would use a binary sensor instead and classify it as a door sensor. I know that works since I use it for my Z-Wave sensors.

binary_sensor:
  - platform: template
    sensors:
      chicken_door_sensor:
        value_template: "{{ is_state('input_boolean.chicken_door_input_boolean', 'on') }}"
        device_class: door

Well, the same docs I linked say device_class is only supported for a few components, not including input_boolean, so that may not work.

I’ll give your snippet a whirl here, I like it.

Unfortunately, setting a device class on an input boolean throws an error as of Hass.io 102.2.
Invalid config for [input_boolean]: [device_class] is an invalid option for [input_boolean].