Is it worth getting fancy with templates for turning on/off groups?

Title says it all. Lets say you have a group with 10 lights in it.

Does it make sense to just do:

- service: homeassistant.turn_off
  entity_id: group.indoor_holiday_lights

Or is it better/faster/more efficiency to use a fancy jinga to parse the list for ON devices? Like this:

- service: homeassistant.turn_off
  data_template:
      entity_id: >
          {{ states | selectattr('entity_id', 'in', state_attr('group.indoor_holiday_lights', 'entity_id')) | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list | join(', ') }}

I’d think group turn off is faster. All speculation though.

Edit: I know that searching all the objects is slow. Where as under the hood, the state machine uses hashing or a dictionary to quickly get things based on the entity id. That’s my only reason for my speculation

Well I don’t know but the second one makes my head hurt.

The way I see it with vs the states object:

  • group is looping through items in the group only.

  • data_template is looping through all items in the state machine and finding the on group items.

So in essence, the time difference is longer with the data_template/state machine. But in all honesty, thats on the order of milliseconds. Might be longer with slow hardware.

I also find that state keeping is very unreliable. Not because of HA but a device might appear off be actually be on for many many reasons. Better to just send the off signal to the things you want to be off.

The question is does HASS send a command if it’s state tables indicate it’s not required?

For example if a device state in HASS is off; but in reality it’s on; and you send a off command does it get sent? Or does HASS filter based on it’s understanding of state?