#```

1 messages · Page 1 of 1 (latest)

pale thorn
#

I am trying this solution;

I am unsure on what to do with the timestamp. Should I use it to see which entity triggered it? My ultimate goal is to avoid having per room automations. but instead house wide automations

merry python
#

Make a template sensor with that template

#

You can make it in the UI

pale thorn
#

We canmake tempalte sensors in the UI now?!

#

Damn nice.

#

Ok let me do that

#

Done

merry python
#

Yep, now every time one of those media players change, it should trigger

pale thorn
#

Yes; And how do I know which entity triggered it?

merry python
#

well that's a different story

pale thorn
#

Haha

merry python
#

but you can use the same template to get the last changed

pale thorn
#

Could I use an attribute on the sensor?

#

I have something like that here:

#
      - name: "amount friends home"
        unique_id: "amount_friends_home"
        state: >-
             {# Set friendshome to the amount of friends #}
             {% set friendshome = states('sensor.guest_wifi_count') | int - states('sensor.amount_partners_home') | int  %}
             {{friendshome}}
        unit_of_measurement: "friends"
        attributes:
          friends: >
            {% set ns = namespace(friends=[]) %}
            {% for device_tracker in states.device_tracker | selectattr('state','eq','home')  | selectattr('entity_id','search',"phone_") %}
             {% if  state_attr(device_tracker.entity_id, "essid") == "Chilling Hotspot" %}
               {% set name  = device_tracker.entity_id | replace('device_tracker.phone_','') | replace('_',' ') | capitalize  %}
              {% set ns.friends = ns.friends  + [name] %}
             {% endif %}
            {% endfor %}```
merry python
#

you can, but that's only possible in yaml template sensors

pale thorn
#

Gotcha, I shall continue using that

merry python
#

no, it's just throttled to at most 1 update per second

#

the template itself

pale thorn
merry python
#

it doesn't update every second, only state changes

#

it's a trottle

pale thorn
#

Oh, then maybe it's cause I got speakers buffering. I'll make one for speakers and one for chromecats

merry python
#

your last_changed, shouldn't be changing state

#

and if you're choosing the most recent playing one, it should be good

#

just make sure that you're getting the newest timestamp, not the oldest

pale thorn
#

Gotcha,t hanks Petro!

merry python
#

np

pale thorn
#

And the automation

#
description: Uses a regex template to do all lights
trigger:
  - platform: state
    entity_id:
      - sensor.rooms_active_motion_timestamp
condition: []
action:
  - variables:
      active_rooms: >        
        {{ state_attr('sensor.rooms_active_motion_timestamp', 'rooms') }}
      off_lights_in_room: >
        {{ active_rooms | map('area_id') | map('area_entities') | sum(start=[])
        | select('match', '^light.') | select('is_state','off') | unique | list
        }}
  - repeat:
      sequence:
        - service: light.turn_on
          metadata: {}
          data: {}
          target:
            entity_id: "{{off_lights_in_room[repeat.index - 1]    }}"
      for_each: "{{off_lights_in_room}}"
mode: restart