Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alarm support #32

Merged
merged 2 commits into from
Jan 21, 2022
Merged

Add alarm support #32

merged 2 commits into from
Jan 21, 2022

Conversation

tomrosenback
Copy link

@tomrosenback tomrosenback commented Jan 17, 2022

Adds alarm support for both MQTT and HTTP API.

Still work in progress, but please have a look and let me know if you want anything specific changed. Worth to note, first in this branch is untested.

Fixes issue #31 when merged

@Jalle19
Copy link
Owner

Jalle19 commented Jan 18, 2022

@tomrosenback I think we should treat the list of alarms in two different ways:

  1. The HTTP API would return a list of triggered alarms, along with the date/time they were triggered and whether they're dismissed or not.
  2. The MQTT binary sensors would be one per alarm type, and be on when the alarm has occured and is not dismissed, otherwise off.

The problem with the current (albeit draft) implementation is that it doesn't allow for the same alarm to happen twice. IMO that's the normal case, e.g. you end up with the same "tuloilma kylmä" for example couple of times per winter when your LTO roller freezes shut.

What do you think?

@tomrosenback
Copy link
Author

For HTTP API, sure, I can agree with that, but isn´t the most recent alarm of any type the most interesting? What I mean is if say "tuloilma kylmä" has an active state, we are only interested in knowing that? I at least go and reset any errors after issue is fixed so the list of errors is mostly empty.

Also in regards of dismissed or not, isn´t that basically the same thing, it takes a short while if the problem does not persist and the error goes away, so with that said as on MQTT side only interesting statuses are ON, and OFF (dismissed goes under this also).

To conclude

  1. HTTP API; You mean would want all alarms here that are active (only ON), repeated alarms aswell? This could of course be implemented as an array of dates, to make it not differ too much from how alarms are handled on MQTT.
  2. This is the way it is implemented already, or did I miss something? Date when last active could be push as an attribute aswell here.

@Jalle19 What do you think? Am I totally off?

@Jalle19
Copy link
Owner

Jalle19 commented Jan 18, 2022

For the HTTP API I'm thinking something like this:

"alarms": [
  {
    "code": "TE10",
    "name": "TE10InletAfterHeaterCold",
    "description": "Tuloilma LTO:n jälkeen kylmä",
    "timestamp": "2022-01-18T12:58:05Z+0200"
  },
  { ... },
]

I.e. if there are no alarms then the list is empty.

  1. This is the way it is implemented already, or did I miss something? Date when last active could be push as an attribute aswell here.

Yes, I guess that's true.

In this case I think it would make sense to use different approaches for the HTTP and MQTT APIs. MQTT is more limited in being simply "on" or "off", while HTTP can expose the alarm history as well (which is basically what you get on the control panel as well).

@tomrosenback
Copy link
Author

HTTP API, ok with me.

MQTT, ok.

Will make adjustments accordingly,

@Jalle19
Copy link
Owner

Jalle19 commented Jan 18, 2022

I'm not entirely sure what a Pandion machine looks like, but on my Pingvin it's easy to trigger an alarm by removing the LTO drum temporarily.

@tomrosenback
Copy link
Author

Biggest difference I guess is size.

@tomrosenback tomrosenback marked this pull request as ready for review January 18, 2022 21:36
@tomrosenback
Copy link
Author

Please test this out, have tested both HTTP and MQTT API and to me it looks ok now.

@tomrosenback
Copy link
Author

Seems to throw unhandled promise rejections now, any idea?

@Jalle19
Copy link
Owner

Jalle19 commented Jan 19, 2022

Seems to throw unhandled promise rejections now, any idea?

Can you show me the logs from when it happens?

@tomrosenback
Copy link
Author

Seems to throw unhandled promise rejections now, any idea?

Can you show me the logs from when it happens?

Doesn´t seem to happen anymore, no changes to code...

@tomrosenback
Copy link
Author

Seems to throw unhandled promise rejections now, any idea?

Can you show me the logs from when it happens?

Doesn´t seem to happen anymore, no changes to code...

`node eda-modbus-bridge.mjs --unhandled-rejections=warn -d /dev/ttyUSB0 --http false -m mqtt://localhost:1883

... discovery messages ...
... callback messages ...
... random idle duration ...

node:internal/process/promises:265
triggerUncaughtException(err, true /* fromPromise */);
^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#".] {
code: 'ERR_UNHANDLED_REJECTION'
}

Node.js v17.4.0
`

@Jalle19
Copy link
Owner

Jalle19 commented Jan 19, 2022

I think the rejection warnings is a bug in modbus-serial, but I haven't been able to track it down 🤷

Copy link
Owner

@Jalle19 Jalle19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, thanks a lot! I'll test this locally ASAP and merge if it works.

@tomrosenback
Copy link
Author

Looks good now, thanks a lot! I'll test this locally ASAP and merge if it works.

You are welcome! I have mock tested both MQTT and HTTP locally, and it works, currently no alarms in my system so can´t tell if it really works, but if you have an easy way to test, please do to verify it with a "real" alarm.

@Jalle19
Copy link
Owner

Jalle19 commented Jan 21, 2022

Sorry, I accidentally pushed directly to your branch when I thought I was pushing to my remote. Didn't know I had write access :D

@Jalle19
Copy link
Owner

Jalle19 commented Jan 21, 2022

Probably best if you force push your changes again

@tomrosenback
Copy link
Author

Sorry, I accidentally pushed directly to your branch when I thought I was pushing to my remote. Didn't know I had write access :D

No worries.

@tomrosenback
Copy link
Author

Probably best if you force push your changes again

What I can see your changes are not here anymore.

@tomrosenback
Copy link
Author

Probably best if you force push your changes again

What I can see your changes are not here anymore.

You have started from my add-alarm-support branch, which made it show up here.

@Jalle19
Copy link
Owner

Jalle19 commented Jan 21, 2022

@tomrosenback I took your changes for a spin. Turns out my alarm history was full (all 20 slots populated). There were some weirdness with null values in the array, and I figured it would make more sense to expose an "alarm history" through HTTP and "alarm states/statuses" over MQTT. I made some changes so that the MQTT part (alarm statuses) are determined based on the alarm history (no historic active alarm == no current active alarm, since it's all in the history), can you try this branch: https://github.com/Jalle19/eda-modbus-bridge/tree/alarm-test ?

This has the added benefit of being (IMO) simpler since there's no onlyActive and distinct booleans to keep track of.

@tomrosenback
Copy link
Author

Works, and looks good to me. My history is also full so can´t say what an empty slot would look like.

Less is more, removing onlyActive and distinct with added benefits sounds very good.

@tomrosenback
Copy link
Author

Easiest for now would be to merge this PR, and then add a new PR for your changes? Or then ditch this PR all together and just use your branch? Which ever is fine.

@Jalle19
Copy link
Owner

Jalle19 commented Jan 21, 2022

Let's merge this so the author information is not lost, I'll then PR my changes on top of this.

@Jalle19 Jalle19 merged commit 3633461 into Jalle19:master Jan 21, 2022
@tomrosenback tomrosenback deleted the add-alarm-support branch January 22, 2022 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants