jaroschek / home-assistant-myuplink

Custom Home Assistant integration for devices and sensors in myUplink account.
39 stars 8 forks source link

Request: Ask for active alarms just as often as the status updates are done #68

Open siggeb opened 5 months ago

siggeb commented 5 months ago

Since I am currently having some issues with my heat pump (partially this is why I am digging so deep into it now), I am really keen on getting notified when an Alarm has been triggered. It was clear to me today when there was an alarm, that none of the sensors actually give away this. There are two APIs for this /notifications and /notifiations/active, as I have seen in the swagger site. I am not sure which one would be appropriate and how. Maybe the active one is enough, since all the history will be kept in HA. Since I am not getting the swagger auth to work for me, I cant really try them out.

jaroschek commented 5 months ago

I have also thought about this as well. But I have to admit, that I have no idea how to integrate these notifications into Home Assistant.

When you query the API endpoints, you get a result containing information about the number of notifications incl. paging and the alarm details:

{
  "page": 1,
  "itemsPerPage": 10,
  "numItems": 1,
  "notifications": [
    {
      "id": "abc",
      "alarmNumber": 123,
      "deviceId": "xyz",
      "severity": 3,
      "status": "Active",
      "createdDatetime": "2024-01-09T17:14:55+0",
      "statusHistory": null,
      "header": "Add heat external blocked",
      "description": "= blocking additional heat",
      "equipName": "EB100-EP14"
    }
}

I think it would not make sense to search through all notifications. Just the active one would be important.

As the alarm contains the deviceId it is possible to get the matching device.

But then... what to do with this information?

I have not played with notifications in Home Assistant yet. May be it would be possible to notify the user about active alarms when they happen?

siggeb commented 5 months ago

I was also thinking the same thing when I asked the question, what to do with it. But after some consideration, I think the way that is the least complicated and straight forward, would just be to add it as another "Alarm status" sensor, similar to the General status and Heat pump status sensors. Ie Alarm status would be 0 or none by default, and when there is an active alarm you put that.

Looking at the parameters in the above JSON, Im not really sure which ones to set the status to, but I think the most valuable ones would be header+description. Attaching an image of what I get in an email from myUplink, that is basically it. And the timestamp is wrong as well, so I wouldnt actually trust that to be correct, but rather the time it reaches HA.

That solution would totally be enough for me, and then track just that status change. I use Homey for all automation still, and HA is for all data gathering and monitoring for now. And I would be able to use that sensor in Homey to actually create notifications. At the moment, I am tracking power consumtion and triggering an alarm when power has been zero for 1h. This is not good enough =(

image

jaroschek commented 5 months ago

I took "a look around" in other integrations and found in HACS itself a quite useful solution:

A simple sensor that monitors the number of alert as numeric value. And the sensor hold additional details for all alerts in the extended attributes of the entity.

I have implemented the additional data model and request for the API and added the sensor in the diagnostic category of the device: image This is how it looks for me in my local development instance. The different historic values in the screenshot come from debugging/testing during development.

You can try this with the latest alpha release, which also features the firmware update and connectivity sensors but is still in development too. https://github.com/jaroschek/home-assistant-myuplink/releases/tag/1.2.0-alpha6

siggeb commented 5 months ago

Hey! So I installed the alpha version, and have now seen how the notifications are now shown. And I am not really seeing how I can use this.

First of all, what I see is that I still have 1 active notification. This is the alarm I got 9 days ago and is not active at all.

Second, I am obviously not really used to HA yet, but I have found it easiest to work with sensors. A sensor I can also read and send easily to Homey, where I currently have most of my flows. This "Diagnostic", I havent found how I can use it.

So while I can understand possibly the needs for diagnostics like this for a long term thing, I would still appreciate if the single /notifications/active just populated a sensor for an active alarm, to be able to act on it. I guess with current implementation it seems this alarm is still active, so maybe something is wrong on the api side.

image

jaroschek commented 5 months ago

Hello, I understand what you want. But let me first explain my current solution:

This is in fact a sensor. It ist just not a binary (on/off) sensor but a numeric sensor that you could validate. If the number is not 0 then there is at least 1 alarm (or even more as the number increases). It should be possible to validate the value of this numeric sensor as well.

And about the details: From my perspective this is seems to be a common way in Home Assistant to provide detailed information about the current sensor state. These details could be used somehow in complex dashboards or just for manual observation, like I do.

The details should be removed as soon as the alarms have gone away and the endpoint does not deliver any alarms. But it seems there is still a bug, because the state of the sensor in your screenshot is already 0 and the details are still there.

siggeb commented 5 months ago

Ok, I see that this could be used. But my current problem was that it was still showing 1, and that it is active still. So for some reason myUplink has missed that was dismissed the same day on the heat pump. I Now went into the mobile app and dismissed the notification there, and after some minutes that did the trick.

I guess you are using the /notifications endpoint that is the full collector? Somehow I am thinking I would only need the reply from /notifications/active, but I guess that would still be invalid in my case, since it is showing as active here as well. So basically I am not sure that this is being shared correctly by the API.

I will work with this for now =) Thanks!

jaroschek commented 5 months ago

The notifications already use only the active endpoint: https://github.com/jaroschek/home-assistant-myuplink/blob/67115491baca37240b7aea730a429d69d3f6362d/custom_components/myuplink/api.py#L518

If there are already dismissed alarms still in the response of this endpoint, this must be an error in the api itself.