Alert2 - a new alerting component

So the functionality you’d be implementing is that in Alexa you say “turn off [alert name]” and it does an old-Alert-1-style ack? Hmm. I like the idea of enabling voice control/monitoring of alerts, but I’m not enthusiastic about mapping the Alexa on/off language onto the old Alert ack semantics. It seems somewhat klunky & confusing.

I also don’t understand how HA/Alexa works well enough to understand what kinds of synchronization issues might arise. Even if AlertVoiceAlertSwitch always refers back to the Alert2 entity, it could be that some part of HA/Alexa integration is doing some caching, or not polling frequently, etc.

I wish it were easier in HA/Alexa to add new verbs and richer capabilities into Alexa so we could properly support Alert2 actions like ack, snooze, etc.

My inclination is to suggest you do the Alexa support first as a separate component that watches the Alert2 event stream and creates/updates entities as necessary. I think there’s enough detail in the events to track what you need, and we could add more detailed events as necessary.

Thoughts?
Josh

Well, it does the new-style ack as turning the switch on and off is mapped directly to Alert2 ack and unack calls, but yeah, it’d be triggered by “turn off [alert name]” and “turn on [alert name]”.

I don’t love this design myself (it wasn’t my first choice to try, after all); but the problem with implementing this is unfortunately upstream constraints. It would, in theory, be possible to design an Alexa “Custom Skill” that includes all the necessary verbs to fully support Alert2, but the problem then becomes that that only works for people who host their own Alexa skills, plus the AWS functions to support them, as well as expose the relevant HA endpoints directly to the Internet/AWS. The built-in Alexa-through-HA-Cloud support only supports “Smart Home Skills”, which rely on exposing devices to Alexa that it understands, and that’s a limited list of which about the only useful one for our purposes is “switch”.

(List of platforms possible to use available here; also why rolling your own Alexa support is enough of a PITA that Alexa-through-HA-Cloud is a really nice feature to have.)

If there were a way to do custom-skill type work via HA Cloud, I’d be a lot more enthusiastic about richer-capability options, but as it is… well, I’m still open to better interfaces for it; I just haven’t been able to think of any thus far that fit inside the constraints.

Synchronization-issue-wise, I believe - and my testing seems to confirm - that entity state-changes are pushed up to Alexa promptly, and vice-versa. I’ve used my code quite thoroughly on my system, and haven’t run into any sync failures yet; overall, I’m pretty confident that any synchronization failures here will be the result of Internet failures blocking HA<->HA Cloud<->Alexa communications, in which case it’s a bigger network issue that’s not something we can solve inside an integration.

Erk. My read on that approach is that it would make synchronization failures much more likely, because the separate component is going to need to keep its own internal representation of the necessary Alert2 entity state, and as soon as you’ve got two copies of the same state it’s possible to get HA-internal sync failures where you couldn’t before, including possible orphaned-entity issues.

I’m not saying it’s impossible, or that I couldn’t do it, but I do think it adds a lot of potential failure modes and complexity that I wouldn’t court unless I had no other choice.

Hmm. Well, I just submitted a ticket to Nabu Casa asking if they were open to help adding new verbs to their Alexa capabilities. I figure it’s worth at least asking.

If we’re stuck with just the “on/off” verbs, how would you propose handling naming of things? So say we have an alert, alert2.kitchen_temp_too_high. What extra entity names do you envision that mapping to?

I imagine the actions people might want are:
ack/unack
snooze/unsnooze

as well as queries like:
which alerts are firing
is alert xxx firing now
how long has alert xxx been firing
(I’ve no idea if the voice support supports queries like these)

Josh

Oh, oops! Sorry, I should have been clearer. The limitation on verbs and devices is mostly one originating from the Alexa side, not the Nabu Casa one. Alexa Smart Home Skills use a limited number of capability interfaces which define what a device can do, and then you group them together into device templates to define what the devices are.

You can see the list in their dev docs here.

This is great for device manufacturers since they don’t have to worry about defining voice commands or anything; they can just define what their device is, and Alexa takes care of the rest. If their device is on the list - otherwise, they have to figure out a method to squeeze its capabilities into interfaces Alexa does understand. (Which in practice usually turns out to be “pretending to be a switch or relevant kind of sensor”.)

So we’re constrained at two points: one being what Alexa Smart Home Skills actually allow, and the other being how Home Assistant’s Alexa-via-the-HA-cloud maps Home Assistant domains onto Alexa device capabilities.

Leaving aside for the moment what Nabu Casa may be willing to do in response to your ticket, the issue we have is how many people we want this feature to work for. As I see it, at the moment, it looks like the top-level choices are:

  • Work within the Alexa SHS and HA Cloud constraints. Very limiting, hence my current cram-it-into-one-switch fallback design, but on the other hand, works for the largest number of people.
  • Write our own Smart Home Skill for Alert2. This lets us throw HA Cloud constraints out the window and use arbitrary generic controllers, so we could have a better but still limited interface. Drawback: HA Cloud users can’t use it; only people willing to both host their own Alexa support functions on AWS and install a copy of our skill using Alexa Skill Developer Console. (Or we host the functions/skill centrally, but I don’t think either of us wants to get into that game.)
  • Write our own Custom Skill for Alert2. Maximum flexibility, on one hand, since we can define all our own intents and options. This is what we want to do to fully satisfy the all-actions-plus-queries-like-those requirement; on the other hand, it has all the issues I previously mentioned for writing our own Smart Home Skill, plus defining our own voice model for it.

Getting down to the questions of entity naming and queries depends very much on which of these you want to go with.

(For myself, I started out with the very simple user story of wanting to be able to ack my door-left-open alerts by voice when I’m out in the workshop, hands either full of stuff or filthy such that I don’t want to dig my smartphone out to ack from the dashboard, which is why I’m personally willing to accept a lot of constraints to get that working and then built out better features from there.

But I do understand if that’s not the road you want to go down. I say this just so you know where I’m coming from.)

Perhaps the existing Alexa SHS/HA-cloud is best. If that’s the case, what do you have in mind for entity names or other design aspects?
J

So I sat and thought about this. Then I put it on the back burner for a while, and then thought about it some more. Then I asked Claude to analyze the problem for me to find whatever I’d missed, which turned out to be quite a bit, depending on how, ah, klugy we want to go. But that’s why it’s taken me a while.

Current Design

So you’ve seen my current minimalist approach, which implements only current state and ack/unack, and does it by squeezing them both into one switch - basically replicating the Alert 1 behavior. I give the switch in that the friendly name of the Alert2, because I think making the common cases easy is beneficial.

Separating Firing from Acking

It’s doable, but not at zero cost.

To represent whether or not the alert is firing, as I see it, we have two ways to go. One of them is to use a switch that can’t actually be turned on or off (but Alexa won’t know that, so that’s something users would have to remember) to represent the state of the alert, which is a misuse of the switch but which allows us to use the natural language “Is such-and-such alert on?” utterance.

The other option is to use a binary sensor. The trouble is that Alexa only understands binary sensors as contact or motion sensors (intended for use with alarm systems and the like), so you we have to rephrase questions as something like “Is such-and-such alert open?”

I really don’t like the second one. I can’t say I like the first one much, either, but…

For acking, we could use a separate switch. The annoying thing here is that Alexa enforces a strict “only one entity of a given name” constraint, so instead of being able to say “turn [on|off] workshop door left open”, you would have to say “turn [on|off] workshop door left open acknowledgement”, which is one of the issues I had that lead me to the Alert 1 emulation design in the first place.

Claude, however, had a better idea. If you use button entities in Home Assistant, they can be exposed to Alexa and come through as scenes, which can be triggered by just saying their friendly name. So we could have “acknowledge workshop door left open” and “unacknowledge workshop door left open” as valid utterances.

This one, I like. The drawback, of course: two additional voice-support entities per alert.

Other features

Notifications enable/disable: we can do that per-alert at the cost of an additional switch; it’s already a boolean, so that’s fine. That gives us “turn off workshop door left open notifications”, which is natural enough.

Snoozing: Snoozing is kind of a nightmare. There are three possibilities, really, all of which use the notifications enable switch to turn it back on and assume that it’s okay to have snoozed notifications and disabled notifications look identical from a voice perspective:

  1. Preset a snooze time in the config; generate one button/scene/utterance to snooze the alert. We can put the preset time in the button name, so that gives us “snooze workshop door left open for an hour”, or we can leave it at just “snooze workshop door left open”.
  2. Present multiple snooze times in the config, and generate one button each. Works just like the above, only with multiple entities and so multiple utterances. Drawback: multiplies the heck out of our secondary entities.
  3. We could, in theory, use a number entity to set the snooze time and a button to trigger the snooze. Drawbacks: two entities, Alexa’s units don’t include time units so you have to use a bare number in the utterance, and unless you remember what the snooze time is and it’s what you want, you have to use two utterances to snooze. “Alexa, set workshop door left open snooze time to 3600; Alexa, snooze workshop door left open.” Not loving it.

Also potentially worth implementing

  • An ack all button, for “Acknowledge all alerts”.
  • Anything firing switches/binary sensors, possibly by priority - “Are any alerts on?” or “Are any alerts open?”/“Are any high priority alerts [on|open]?”, etc.

Can’t dos

Sophisticated queries, since Alexa Smart Home skills don’t support list responses or dynamic speech. The best we can probably do are things like the anything-firing-by-priority options just above, or things like them as a substitute for “Which alerts are firing?”.

As for “How long has foo been firing?”, the only way we can get numeric sensors out are as temperature sensors, so we’d be publishing elapsed minutes as a fake temperature. That’s horrible and we should absolutely not do it.

Proposals

What would I do, if I didn’t do what I’ve already done?

  • Use a non-changeable switch for the state of the alert, and give it the same friendly name as the alert. (This does mean users could try to turn it on and off, which would be a silent no-op, but we’d have to live with that; at least it allows for reasonable natural language checking of the alert state.)
  • Implement acking and unacking using two buttons/scenes, for the most natural language there. (This doesn’t provide for a way of checking whether an alert is currently acked, but since acking or unacking twice is a no-op, that’s probably okay.)

For an initial release, I’d stop right there, because that covers what I see as the most important functions. I’d also probably make the ack/unack functionality - and other similar things added in later releases - an option, since as this path ends up with multiple proxy entities, I want to avoid accidentally polluting entity-space with them unless the user actually wants them.

Other things, in rough priority order, at least as I’d guess it:

  • Ack all/unack all buttons/scenes, which slightly contrary to their name would affect all firing alerts.
  • Are-alerts-of-this-priority-firing? switches/sensors, which might be refinable with some more thought into some more sophisticated group sensors. Use HA labels maybe? Needs some rumination.
  • I’d be tempted to declare both notification enable/disable and snoozing out of scope, given the multiplying number of entities involved and that we’d have already covered the most common use cases. But if we do want them, the former at least is easy; the latter is design hell.

That’s what I have thus far.

Hi - sorry for long delay responding. My free time disappeared.
I don’t have a strong opinion on the button vs switch and how they’re named. The scene idea might be a good approach. Whatever we do I think it’s going to be a hack that probably will change in the future.

I’m a little nervous about including it in Alert2 proper, but I’m up for giving it a shot. I’d say write the code in a way that’s pretty separate from the core Alert2 so it’s relatively easy to verify that it won’t destabilize the rest of Alert2 and so that it’s relatively easy to yank it out into a separate component if we need to. So I’m thinking you’d put the Alexa entity stuff in a separate python file. And maybe the code in that file even learns of Alert2 entity changes by just listening to the HA event stream for Alert2 events. Or I’m open to other ideas on that.

Like I’m imaging that when an alert2 entity is created (eg by a generator), your module sees the event and then creates the necessary entities for Alexa. And similarly for other events in the Alert2 lifecycle.
-J

Hi All,
I just released Alert2 + UI v1.21.

Changes

  1. You can now specify a template for numeric_state in triggers when used with a generator
  2. fix deprecated home_assistant_start parameter
  3. Fix console error related to panel-loading hack to get radio buttons to work

I’m playing around with adding an action config field to specify an action to invoke when an alert fires. The two use cases that I have are:

  • shutting off house water valve when a substantial water leak is detected
  • shutting off a pump when a sensor indicates it’s pumping air rather than water (for a water garden)

It’s possible to make this work today by specifying an HA automation, and have the automation trigger an alert as one of its steps. But then the logic to detect and handle the problem is in two different places, which isn’t ideal.

It seems to me that if you invoke an action, you kinda want an alert to stay on until the counter-action is done. E.g., if a water leak is detected and an action turns off a valve, you kinda want the alert to keep firing even if the water leak stops. The reason is that presumably someone needs to investigate and decide if it’s ok to turn back on the valve.

So maybe the action field only works with condition_on or something?

I welcome thoughts, just playing around with some options at present.

EDIT: I’m not super familiar with the trace support that actions in automations have - it looks somewhat heavily UI-based. So I may skip supporting traces for now.
-J

I just released v1.22 of Alert2 and the UI.

Changes

  • Support actions_on config field, which lets you specify automation actions to run each time a condition alert starts firing.
  • Fix delayed notifications that use the new notifiers
  • Add continuous integration testing - runs HA server-side unitests on every push
  • Fix a few JS bugs in more-info popup and loading of HA HTML elements

-J

I’ve got to make a rather awkward apology here. I’m afraid I’m not going to be able to get this working.

(I looked at possible implementations, and between not being able to come up with a design that wasn’t notably worse than the Alert1-alike I’d already tried and not being able to come up with a good architectural solution that met both our requirements… I just can’t do it. I’m sorry.)

So that’s the first part. The really shamefaced part of the apology is that in the course of hacking on and around this I wrote a lot of experimental alert-proximal code, and then with this in mind and also some of the other ways in which our visions of how alerting ought to ideally work, a bunch of that work turned into a spec for a differently-architected alerting integration. Which I, ah, am about to release. Independently developed; not a fork.

Which I hasten to add is not intended as a criticism of Alert2! It’s a great integration and inspired a lot of ideas that ended up in my solution, which I was clear about giving it and you credit for. It’s just a different approach to how to handle various aspects of alerting and how they fit together, that’s all.

In any case, I wish Alert2 much success, and if there are any ideas or code in Alert Redux that you find useful, you’re entirely welcome to them.

@cerebrate - looks like a neat project! Glad Alert2 could inspire you. Let’s keep in communication - I’m especially interested in aspects of Alert Redux that Alert2 could benefit from.
The biggest things that jump out to me are:

  • Lovelace card included in integration rather than in a separate repo
  • Handling of missing data
  • Support for voice control and AI

I’ll take a look at your repo to see how hard it is to put Alert2-UI into Alert2. I also like the look of your Lovelace UI. I’ll find some time to dig into your code and see what else Alert2 can benefit from.

And let me know if you have ideas for parts of your project that you think would improve Alert2.
-J

Happy to keep in touch! The way I see it, we may be heading in different directions overall, but if we keep learning from each other’s work, we both end up with better integrations, and who can say no to that? :slight_smile:

Adding your cards to your integration repo should be an easy thing to port over - I think the relevant code is just frontend.py, plus the calls to it from init. (I saw another integration (Recorder Throttle, I think) handle it that way, and was struck by the question of why mine didn’t.)

Hi All,
I’ve just released Alert2 v1.23. Inspired by Alert Redux, I have integrated the Alert2 UI repository into Alert2.

Alert2 now automatically loads the frontend UI code, and you no longer need the Alert2 UI repository.

If you have installed Alert2 UI, remove it so it doesn’t cause javascript conflicts.
I released a Alert2 UI that adding an appropriate warning, so you should know if you’ve removed it successfully or not.

Also, you can check the versions running by clicking on the “Alerts” of the Alert2 Overview card. It should show v1.23 for both the Alert2 & Alert2 UI.

-Josh