Binary Sensor with Attributes

I have a binary sensor which has 4 attributes. I want to split these attributes into individual entities.

windowstatusfrontleft: INTERMEDIATE_POSITION
windowstatusrearleft: CLOSED
windowstatusfrontright: CLOSED
windowstatusrearright: CLOSED

The attributes have 3 values and I want to set the state depending on these attributes.

Values are INTERMEDIATE_POSITION, OPEN, CLOSED. If OPEN or INTERMEDIATE_POSITION state would be ‘ON’ if CLOSED state would be ‘OFF’

Can anybody assist??

Hey markdias and welcome back :partying_face:
You probably want to create a template binary sensor (has on/off as state, can appear in the Frontend as open/closed when you specify a device_class): https://www.home-assistant.io/integrations/binary_sensor.template/

binary_sensor:
  - platform: template
    sensors:
      window_frontleft:
        device_class: window
       # Replace binary_sensor.windowstatus with the correct sensor name
        value_template: >-
          {{ is_state_attr('binary_sensor.windowstatus', 'windowstatusfrontleft', 'OPEN')
             or is_state_attr('binary_sensor.windowstatus', 'windowstatusfrontleft', 'INTERMEDIATE_POSITION')  }}

You can add more information, like an availability_template. With the upper config the window will appear as closed when the binary_sensor you get the information from is unavailable.

Haha, yeah been away for while but home assistant has come on such a long way its!

Thank you so much for your help. I will try this!!

1 Like

Brilliant, Thanks!

Almost had it but was trying to use the attribute like ‘binary_sensor.windowstatus.windowstatusfrontleft’

You can, in your automations if you wanted to.
As in the example I’ve pasted you should access it like state_attr('binary_sensor.windowstatus', 'windowstatusfrontleft')
This will give you OPEN, INTERMEDIATE_POSITION or CLOSED for the specified window

You could use template triggers in your automations then, however setting up binary sensors is a pretty clean way of doing it too :man_shrugging:

I’ll have a play around. Thank you again for your help!

1 Like