Guidance with Groups of Binary Sensors

2019-09-04_11h37_09

Above is my groups.yaml file. I am trying to get the lovelace UI to show open if any of the windows are open.

Instead it shows:

image

I tried changing the groups.yaml to “binary_sensor” but it didn’t work. Any help would be appreciated.

I couldn’t find an answer to this either so I just used a template binary sensor, albeit for only 2 windows (to combine 2 opening windows in a single frame).
You could just add all the binary sensors to the value_template with ‘or’

    living_room_window:
      friendly_name: "Living Room Window"
      device_class: window
      value_template: "{{ is_state('binary_sensor.living_room_window1', 'on') or is_state('binary_sensor.living_room_window2', 'on') }}"

Thanks for looking into it. I have been mad searching all over these forums with no luck.

A template sounds like a great solution. Thanks for the help.

An easy template:

    window_status:
      friendly_name: "Window Status"
      entity_id:
        - binary_sensor.back_window_... etc
      device_class: window
      value_template: "{{ expand('group.window_status') | selectattr('state','eq','on') | list | count > 0 }}"

You’ll need to add each sensor individually inside the group the entity_id attribute.

I have been trying to figure this code out.

I get the error:

Log Details (ERROR)
Wed Sep 04 2019 14:35:02 GMT-0500 (Central Daylight Time)
Invalid config for [sensor.template]: [window_status] is an invalid option for [sensor.template]. Check: sensor.template->window_status. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/

My configuration.yaml

sensor:
  - platform: template
    window_status:
    friendly_name: "Window Status"
    entity_id:
     - binary_sensor.back_window_2_contact
     - binary_sensor.bedroom_window_3_contact
     - binary_sensor.dining_room_contact
     - binary_sensor.front_bedroom_contact
     - binary_sensor.front_window_1_contact
     - binary_sensor.front_window_2_contact
     - binary_sensor.nursery_window_1_contact
     - binary_sensor.nursery_window_2_contact
     - binary_sensor.office_window_1_contact
     - binary_sensor.office_window_2_contact
    device_class: window
    value_template: "{{ expand('group.window_status') | selectattr('state','eq','on') | list | count > 0 }}"

This is what I was attempting. I tried to put it outside of the sensor and without the - platform: template but it didn’t like that either.

This is my groups.yaml but I don’t think I need it

Contact Sensors:
  name: Window Status
  entities:
    - binary_sensor.back_window_2_contact
    - binary_sensor.bedroom_window_3_contact
    - binary_sensor.dining_room_contact
    - binary_sensor.front_bedroom_contact
    - binary_sensor.front_window_1_contact
    - binary_sensor.front_window_2_contact
    - binary_sensor.nursery_window_1_contact
    - binary_sensor.nursery_window_2_contact
    - binary_sensor.office_window_1_contact
    - binary_sensor.office_window_2_contact
    

you’re missing a space, and the sensors section header.

sensor:
  - platform: template
    sensors:
      window_status:
        friendly_name: "Window Status"
        entity_id:
          - binary_sensor.back_window_2_contact
          - binary_sensor.bedroom_window_3_contact
          - binary_sensor.dining_room_contact
          - binary_sensor.front_bedroom_contact
          - binary_sensor.front_window_1_contact
          - binary_sensor.front_window_2_contact
          - binary_sensor.nursery_window_1_contact
          - binary_sensor.nursery_window_2_contact
          - binary_sensor.office_window_1_contact
          - binary_sensor.office_window_2_contact
        device_class: window
        value_template: "{{ expand('group.window_status') | selectattr('state','eq','on') | list | count > 0 }}"

This looks great, I’m gonna use this for my alarm groups and dorr and window groups - Thanks @petro

1 Like
Log Details (ERROR)
Wed Sep 04 2019 16:32:04 GMT-0500 (Central Daylight Time)
Invalid config for [sensor.template]: [window_status] is an invalid option for [sensor.template]. Check: sensor.template->window_status. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/

I get a similar error. I copied and pasted your code in.

sensor:
  - platform: template
    sensors:
      window_status:
        friendly_name: "Window Status"
        entity_id:
          - binary_sensor.back_window_2_contact
          - binary_sensor.bedroom_window_3_contact
          - binary_sensor.dining_room_contact
          - binary_sensor.front_bedroom_contact
          - binary_sensor.front_window_1_contact
          - binary_sensor.front_window_2_contact
          - binary_sensor.nursery_window_1_contact
          - binary_sensor.nursery_window_2_contact
          - binary_sensor.office_window_1_contact
          - binary_sensor.office_window_2_contact
        device_class: window
        value_template: "{{ expand('group.window_status') | selectattr('state','eq','on') | list | count > 0 }}"

I deleted the groups.yaml and now get:

Wed Sep 04 2019 16:45:22 GMT-0500 (Central Daylight Time)
Invalid config for [sensor.template]: value is not allowed for dictionary value @ data['sensors']['window_status']['device_class']. Got 'window'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/`

Im trying!

I took out the device_class and tried to put under customize.yaml. It didn’t throw errors but now it says false

customize.yaml

sensor.window_status:
  device_class: window

configuration.yaml

sensor:
  - platform: template
    sensors:
      window_status:
        friendly_name: "Window Status"
        entity_id:
          - binary_sensor.back_window_2_contact
          - binary_sensor.bedroom_window_3_contact
          - binary_sensor.dining_room_contact
          - binary_sensor.front_bedroom_contact
          - binary_sensor.front_window_1_contact
          - binary_sensor.front_window_2_contact
          - binary_sensor.nursery_window_1_contact
          - binary_sensor.nursery_window_2_contact
          - binary_sensor.office_window_1_contact
          - binary_sensor.office_window_2_contact
        value_template: "{{ expand('group.window_status') | selectattr('state','eq','on') | list | count > 0 }}"

2019-09-04_16h57_44

Something is very wrong somewhere because the error messages don’t appear to be identifying valid problems.

  • It shouldn’t be identifying window_status as an ‘invalid option’.
  • Deleting groups.yaml shouldn’t cause a complaint about device_class.
  • device_class is a valid option for a Template Sensor.

There’s a missing clue to explain these strange results …


Out of curiosity, which version of Home Assistant are you using?
Do you have other sensors defined in configuration.yaml?

Surely you need to keep the group as the value_template references it ?

I figured group.window_status made a group from the entities listed in the window_status?

Yes, the group is needed but without it the template will simply fail quietly. The weird thing is that deleting group.yaml caused a seemingly unrelated error message concerning the template sensor’s device_class. That’s a puzzling result and indicative that there’s something else happening here that hasn’t been revealed yet.

No it doesn’t. You must explicitly define the group if you intend to refer to it within the template.

I’ll repeat my previous question, do you have other sensors defined in configuration.yaml or is this Template Sensor the only one?

Also, wouldn’t a template binary sensor be better suited here ?

Trying again!

groups.yaml
2019-09-04_17h14_54

Contact Sensors:
  name: window status
  entities:
    - binary_sensor.back_window_2_contact
    - binary_sensor.bedroom_window_3_contact
    - binary_sensor.dining_room_contact
    - binary_sensor.front_bedroom_contact
    - binary_sensor.front_window_1_contact
    - binary_sensor.front_window_2_contact
    - binary_sensor.nursery_window_1_contact
    - binary_sensor.nursery_window_2_contact
    - binary_sensor.office_window_1_contact
    - binary_sensor.office_window_2_contact
    

configuration.yaml

sensor:
  - platform: template
    sensors:
      window_status:
        friendly_name: "Window Status"
        entity_id:
          - binary_sensor.back_window_2_contact
          - binary_sensor.bedroom_window_3_contact
          - binary_sensor.dining_room_contact
          - binary_sensor.front_bedroom_contact
          - binary_sensor.front_window_1_contact
          - binary_sensor.front_window_2_contact
          - binary_sensor.nursery_window_1_contact
          - binary_sensor.nursery_window_2_contact
          - binary_sensor.office_window_1_contact
          - binary_sensor.office_window_2_contact
        device_class: window
        value_template: "{{ expand('group.window_status') | selectattr('state','eq','on') | list | count > 0 }}"

Error Log

Log Details (ERROR)
Wed Sep 04 2019 17:18:01 GMT-0500 (Central Daylight Time)
Invalid config for [sensor.template]: value is not allowed for dictionary value @ data['sensors']['window_status']['device_class']. Got 'window'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/

I included all my sensor code block just in case but I don’t see any conflicts there.

group needs to be:

group:
  name: window status
  entities:
    - binary_sensor.back_window_2_contact
    - binary_sensor.bedroom_window_3_contact
    - binary_sensor.dining_room_contact
    - binary_sensor.front_bedroom_contact
    - binary_sensor.front_window_1_contact
    - binary_sensor.front_window_2_contact
    - binary_sensor.nursery_window_1_contact
    - binary_sensor.nursery_window_2_contact
    - binary_sensor.office_window_1_contact
    - binary_sensor.office_window_2_contact

OK so done this myself and works fine (note slightly different group name as I already have that group)

Binary Sensor

  binary_sensor:
    window_status:
      friendly_name: "Window Status"
      entity_id:
        - binary_sensor.living_room_window
        - binary_sensor.kitchen_window
        - binary_sensor.toilet_window
        - binary_sensor.bathroom_window
        - binary_sensor.ensuite_window
        - binary_sensor.office_window
        - binary_sensor.bedroom_window
        - binary_sensor.alices_window
        - binary_sensor.bens_window
      device_class: window
      value_template: "{{ expand('group.windows') | selectattr('state','eq','on') | list | count > 0 }}"

Group

windows:
  name: Windows
  view: false
  entities:
  - binary_sensor.living_room_window
  - binary_sensor.kitchen_window
  - binary_sensor.toilet_window
  - binary_sensor.bathroom_window
  - binary_sensor.ensuite_window
  - binary_sensor.office_window
  - binary_sensor.bedroom_window
  - binary_sensor.alices_window
  - binary_sensor.bens_window