So I am new to HA, been using Hubitat for a long time and used webcore for my rules. I want to slowly work on moving over to HA, but struggling with rules.
Lets start with something easy.
I have a group of doors (5), Lets call it “Exterior Doors” that I want to put into a global variable (I do this with webcore currently)
then I want to take that “Exterior Doors” group and have a rule that says if any door in the “Exterior Doors” group changes to open, then speak what door triggered it and then opened.
so it would end up like “Front Door Opened” But I have no idea how to set that is or where to do glabal variables and such.
That trigger fires on every state and attributes change of every entity in your system. Even with a small number of entities it is practically useless, because it fires so often it will overwhelm the queue.
I know I can do it off "Device, trigger, contact, but how can I do it for a helper where I list the ones I want. I have 100’s of rule I need to move over and if I need to make a change, updating a global is way easier than editing 100’s of rules. Like if a device dies and needs to be replaced. I don’t want to edit every rule.
That will fire on any state or attribute change of that binary sensor, but the template is non-sense for that trigger.
You could use that, and then use templating to get the most recently changed entity, but it will leave a lot of edge cases where you won’t get a message.
I have also tried node red, but cant seem to get very far. seems like programming HA is way harder and not as straight forward. I want to switch as Habitat seems to be slowly going away.
You can create a group of your door sensors. that’s kind of similar to a global variable but not really. then you can trigger off the state change of that group since the group will be on/off depending on the state of each door sensor in the group. If one binary sensor in the group is on (door open) then the group will be on.
then to read out which door or doors are open you can read template out each member of the group to tell you which entities are on.
I use this exact setup (except I don’t use the group as a trigger) in my alarm setting automation.
here is basically my setup:
group:
access_sensors:
name: Access Sensors
icon: mdi:walk
entities:
- binary_sensor.computer_room_window_sensor
- binary_sensor.foyer_door_sensor
- binary_sensor.garage_man_door_sensor
- binary_sensor.kitchen_door_sensor
- binary_sensor.main_bath_window_sensor
- binary_sensor.sunroom_door_sensor
- binary_sensor.sunroom_east_pe_beam
automation:
triggers: lots of stuff
actions:
- other stuff
# the one you care about...
- service: notify.alexa_media
data:
target:
- media_player.kitchen_dot
data:
type: announce
message: >
{% set open = expand('group.access_sensors') | selectattr('state', 'eq', 'on') | map(attribute='attributes.friendly_name') | join(',') %}
{% if expand('group.access_sensors') | selectattr('state', 'eq', 'on') | list | count > 1 %}
"You tried to activate the alarm system but some doors or windows aren't closed yet. The {{ open |replace(',' , " and ") }} are open.
{% else %}
"You tried to activate the alarm system but some doors or windows aren't closed yet. The {{ open }} is open.
{% endif %}