Device_class motion for a group?

Hi, I have two motion sensor (binary_sensor.motion_1 and _2) that I put together in a group group.motion_sensor_1_and_2

I would like that this group icon and behaviour should be as a motion sensor (the icon and icon behaviour when motion is triggered with a little man running and turning yellow), but I am not clear how to achieve this.

IS it possible?

I think not for a group, but you can use the Template Binary Sensor to group the motion sensors.

binary_sensor:
  - platform: template
    sensors:
      motion_group:
        device_class: motion
        value_template: "{{ is_state('binary_sensor.rpi_motion', 'on') or is_state('binary_sensor.wz_motion', 'on') }}"
1 Like

I see, but what about the behaviour.

I need trhis behaviour:
this grouped binary sensor go ON when only one of the two motion sensor go ON
this grouped binary sensor go OFF when BOTH motion sensor go OFF

Logic is simple, if there is partly motion (only 1) for me is motion ON for the group; if there is no motion (both OFF) then the grouped motion is OFF

Is it so?

Just give it a try and you’ll see.
You can control it with the or or an and in the template.

Did you end up finding a way to make such groups based on device_class?
I understand that the template binary sensor can act the same way but i’d like something more automated than adding multiple entities to that code.
Thanks in advance

1 Like

I stole this code from someone in the community a while back, and modified it to my needs:

script:
#...[]...
  create_group_all_motion_sensors:
    sequence:
    - service: group.set
      data_template:
        object_id: all_sensors_motion
        entities: "{{ states.binary_sensor \n    | selectattr('attributes.device_class','eq','motion')\
          \ \n    | map(attribute='entity_id') \n    | reject('eq', 'binary_sensor.all_motion_sensors_off')\n\
          \    | reject('eq', 'binary_sensor.motion_sensor_158d0003cbf138')\n    | reject('eq',\
          \ 'binary_sensor.motion_sensor_158d0002f8f2c9')\n    | reject('eq', 'binary_sensor.motion_stairs')\n\
          \    |  join(', ') }}\n"
  create_group_all_opening_sensors:
    sequence:
    - service: group.set
      data_template:
        object_id: all_sensors_opening
        entities: "{{ states.binary_sensor \n    | selectattr('attributes.device_class','eq','opening')\n\
          \    | map(attribute='entity_id') \n    | reject('eq', 'binary_sensor.all_doors_closed')\n\
          \    | join(', ') }}\n    \n    \n"

They essensially get all sensors with a specific device class, in my case motion and opening and put them in a group. I also exclude some sensors i didnt want included.

Those two scripts run on my startup routine with this automation:

- alias: Startup Stuff - Notifications
  id: cea3ed9689054b0dac9a73ac9fc63091
  trigger:
  - event: start
    platform: homeassistant
  action:
  - data:
      message: HomeAssistant is up
    service: notify.mobile_app_sm_n975f
  - alias: Create All Groups
    entity_id: script.create_group_all_motion_sensors, script.create_group_all_opening_sensors
    service: script.turn_on

Hope it helps someone.

ping @Tpm369

1 Like

Thank you for your suggestion. I used it and entered a third motion sensor. Once I entered the below code in the my configuration yaml, I used “binary_sensor.motion_group” as a trigger for my automation using the automation UI (Note, “Garage Group Motion” is the friendly name that pops up when searching the Entity for the trigger but once I click on it, the name defaults to “binary_sensor.motion_group” . This makes me wonder what will happen if I try to make another motion group; will its default name also be “binary_sensor.motion_group” but have a different friendly name? I just haven’t had a need for a second motion group yet. Thanks for the help!

Note: When I click the reply button, it gives me a" Unformatted Code Warning" even though I have the ``` before and after the below code… This is my first time posting code.

# For GARAGE motion detection
  - platform: template
    sensors:
      motion_group:
        friendly_name: Garage Group Motion
        device_class: motion
        value_template: "{{ is_state('binary_sensor.ewelink_ms01_76186722_ias_zone', 'on') or is_state('binary_sensor.ewelink_ms01_b1f16622_ias_zone', 'on') or is_state('binary_sensor.ewelink_ms01_89436822_ias_zone', 'on') }}"
  - platform: template
    sensors:
      motion_group_1: # <- this name must be unique
        friendly_name: Garage Group Motion
        ...
      motion_group_2: # <- this name must be unique
        friendly_name: Another Group Motion
        ...
1 Like