#```
1 messages · Page 1 of 1 (latest)
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
Yep, now every time one of those media players change, it should trigger
Yes; And how do I know which entity triggered it?
well that's a different story
Haha
but you can use the same template to get the last changed
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 %}```
you can, but that's only possible in yaml template sensors
Gotcha, I shall continue using that
I have this, but it relies heavely on states.* Is that bad?
no, it's just throttled to at most 1 update per second
the template itself
see the most recent pin in #templates-archived
https://i.imgur.com/s72CdD3.png
Looks good, last question that I can think of. Can i get it to only update on state change? instead of every second?
Oh, then maybe it's cause I got speakers buffering. I'll make one for speakers and one for chromecats
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
Gotcha,t hanks Petro!
np
I think I got it working!
Template sensor with active rooms: https://i.imgur.com/w9XTp8i.png
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