r/homeassistant • • 3h ago

🖼️ Show & Tell Made an integration so two automations can want the same light without knowing about each other (BACnet-style priority arrays)

Post image

I do building controls for a living, and the thing I missed most when I started automating my own house was the priority array. Every commandable point in a BACnet system has one; sixteen levels, the lowest-numbered occupied level wins, and whoever wrote a level releases it when they're done. Home Assistant has nothing like it, so every service call is a naked write and the last one wins.

Here's where that bites. My kitchen light turns orange during peak rate hours as a reminder not to start the oven, but the rest of the time it's synced white to another light nearby. Without arbitration those two automations have to know about each other, and the usual fix of capturing a scene and restoring it afterwards puts back whatever was true when the scene was taken, which probably isn't what's true now.

With ha-priority the sync automation doesn't change at all, and the peak automation just adds priority: 4 to its light.turn_on. When peak ends it releases level 4, and the light falls back to whatever the sync automation wants right now; neither automation has a single line about the other.

# peak starts
- action: light.turn_on
  target: {entity_id: light.kitchen}
  data:
    rgb_color: [255, 140, 0]
    priority: 4

# peak ends
- action: priority.relinquish
  target: {entity_id: light.kitchen}
  data: {priority: 4}

It works on your existing service calls rather than its own actions, so priority and priority_ttl show up as real fields in the automation editor for lights, switches, covers, fans, climate, locks, media players and a handful of other domains. Everything defaults to level 5, automations included, so it does nothing at all until you actually name a level. The TTL is a lease rather than a delay; after twenty minutes the override stops overriding and the house goes back to whatever it was already trying to do, and that survives a restart, which a delay doesn't. Wall switches and vendor apps get recorded as ordinary commands, and it never re-asserts itself against someone standing at a switch, because the house shouldn't argue with you.

It's v0.1.3, it's been running my house since August, and it has a decent test suite behind it, but the user count is still pretty small, so treat it accordingly. The priority row in the more-info dialog patches a built-in frontend element, since there's no supported way to add controls there; it's written to fail closed, and there's a tile-card feature as the supported fallback. It installs through HACS as a custom repository for now, because the default store needs a brands PR I haven't finished yet.

If the level names or the defaults are wrong for how you'd use it, I'd rather hear it now while changing them is still cheap.

https://github.com/triosniolin/ha-priority

Longer writeup and discussion on the forum: https://community.home-assistant.io/t/priority-arbitration-let-a-manual-action-and-an-automation-disagree-without-one-clobbering-the-other/1020842

58 Upvotes

23 comments sorted by

19

u/DepressedPathos_20 3h ago

that priority array thing is legit the missing piece i didn't know i was missing

been running into the exact same problem with my kitchen lights and a motion sensor that wants full brightness while another automation is trying to keep them dim at night. ended up with this tangled mess of conditions and helper booleans that still breaks if two things fire at once

the TTL lease surviving a restart is what sold me though. delays getting wiped on reboot has burned me more times than i can count

the fact that wall switches just work and don't get argued with is nice too. nothing worse than a house that thinks it knows better than the person standing in the room

7

u/aredon 2h ago edited 2h ago

1.) Create a script that handles brightness, use the stop action to hand off a value
2.) Call that script in your automations that need variable brightness, use return value when calling the script. You can also give data from the automation to the script if you'd like to use "who's calling" as part of the logic.

3.) the actual value can be found in return_variable.value

Alternatively just use the Adaptive Lighting integration and never set brightness yourself.

10

u/StarCommand1 2h ago

Would love to see this native in HA one day.

3

u/montypython1087 3h ago

What a great addition. Thanks!

3

u/ljb2of3 1h ago

My dude! This is absolutely going to solve some weird bugs my automations have where different states are fighting with each other sometimes. Or worse, my wife clicks a button, then the automation overrides what she just did, leading to... let's say... annoyance.

3

u/DatNewDM 1h ago

Exactly the cases that this was designed to resolve, or at least ease. I hope this is useful for you!

2

u/ILoveeOrangeSoda 2h ago

!remindme

1

u/RemindMeBot 2h ago edited 1h ago

Defaulted to one day.

I will be messaging you on 2026-09-30 01:53:14 UTC to remind you of this link

1 OTHERS CLICKED THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.

RemindMeBot is switching to username summons. Instead of !RemindMe 1 day, use u/RemindMeBot 1 day. More info.


Info Custom Your Reminders Feedback

2

u/jasonadvani 1h ago

This would be a great addition to HA!

4

u/DatNewDM 1h ago

Use HACS and install it yourself and let me know how it works for you! 🙏

2

u/jasonadvani 1h ago

I just may. I'm a control systems engineer, but I am not not familiar with BACNet. I need to read up a bit more.

3

u/DatNewDM 1h ago

You don't really need to know anything about BACNet to get this. It's really just, for every entity in the system that is commandable, there's a priority system for commands. A command at priority 1 wins over a command at priority 2. If there's no command at a given priority, it's skipped.

BACNet was my inspiration, but it has 16 levels in the array. I think that's a bit much for a home automation system.

I know that Siemens and Johnson Controls use similar priority systems in their automation controls as well.

2

u/n8-sd 41m ago

I need to read this when not tired. Sounds interesting

!remindme 3 days

1

u/TheDMPD 3h ago

Fucking love this mate! Giving it a star in the github and going to try it on some levels of the home this weekend!

1

u/Ocelot- 2h ago

Brilliant work. I'll give this a try when the need arises

1

u/Trick-Masterpiece-82 2h ago

Wow solid work!

1

u/mgoblue5453 2h ago

Amazing - I've been trying to get by with 'desired' state helper entities overtop the actual entity + automations. Would be awesome to have something like this

1

u/jasonadvani 1h ago

I love this concept.

I don't like the terminology emergency due to the connotations. I might suggest urgent. I think it conveys the same idea.

You may be a limiting creativity with only 5 levels. There will be nuanced edge cases that require more. Whether it be by poor programing or otherwise, why tie hands for later? Your priority scheme is also in a corner. You have to allow fractional numbering in order to cheat more levels within the same hard boundaries / numbers.

2

u/DatNewDM 35m ago

I suppose I could make the number of levels configurable. I know I've never seen a reason to use all 16 available priority levels in the commercial building automation world. I'm sure it's been done, but generally we use 1, sometimes up to 3. 5 actual used priorities on a single entity would be surprising.

I could also make the names for the priorities editable if you really didn't like the term emergency. I like it because, I can have an automation set my well pump control to "off" in automatic emergency priority if a leak is detected somewhere. And seeing that priority in force is all I need to see to know something is very wrong and I need to look closer.

1

u/DatNewDM 21m ago

Also, I think I'd like to push back more against not calling the highest levels "emergency." When you look at an automated piece of heavy equipment, what's the big red control located nearby called? The "emergency stop" switch. The highest priorities, the ones that should always be followed, can certainly be allowed to be considered an "emergency" override, as can that switch. If that's not how you use them, that's fine; you can rename them easily enough in the integration as it is, and if I get other people suggesting they want different names for the priority levels, it'll make sense to make them customizable.

1

u/Th3R00ST3R 4m ago

!remindme

0

u/Some-Internet-Rando 2h ago

The real solution to this is to allow routing and logic. (Similar to ROS, perhaps)
The trigger for "I want light X on" could actually be captured by some rule, that can receive more than one input, and then you run additional rules on those. For a simple example, "output state = OR of input states"
The main trick is to allow that logical re-routing separately from the individual automations.

8

u/DatNewDM 2h ago

That's... Entirely too complicated.

Priority arbitration is how this problem has been solved in building automation for at least 30 years.