Last update of value older than x Seconds

Hello, I integrated a load management for the winter in my house. For that I´m using my inverter (charge / discharge battery in the night with cheap prices.

Sometimes the program from the inverter in linux hang up and send no new values. If that happen, the load management couldn´t be safe and must switch off charging battery.

All values from interter comes via MQTT.
image

Now my idea is to read via Nodered, if the program hangs up and send no new values. I realized that in a different way with Blockly like this:
"Current time" minus "last change from that value" > 1 minute
image

I´m not sure, what should be the best: Last change from that value or last update / new information from that value. I think I must try what is the best, because Mosquitto maybe send permanent values - I don´t know currently- have to test that.

I tried that with Trigger nodes, but it didn´t work as I thougt:

Anyone an idea how I can realize that in NodeRed?

Sorry my brain isn't working too good just now.

But looking at your last picture

I don't understand what the inject and trigger node are doing.

Then, those two nodes go into another trigger node.

That's where I get lost.

The first trigger node sends data every 250ms.
That goes into the second trigger node that is set to 1 minute.

If you have the inject sending the timestamp it will always be changing so it won't help you detect non-changing messages either.

  1. You can implement a reaction to missing messages process using a single trigger node.
    Let's say that messages normally arrive from the inverter at 1 minute intervals and you want to take action after 2 minutes without news.
    Set the trigger node to send nothing, wait 125 seconds, then send an alert. Check "Extend delay if new message arrives".

  2. Take a look at the MQTT Last Will & Testament feature.
    With this the MQTT broker and client (the inverter) send an intermittent handshake. If the client does not respond to the handshake for 30 seconds, the broker publishes a LWT message for the client which Node-red can subscribe to.
    There is a Birth message too, sent when the client reconnects.

That was a really good idea.
If the program is hanging up, the MQTT didn´t receive any message. After 10 times no new message command kill for the program and restart after delay 5 min. that program with dex. Great.

With your Last Will & Testament - I think that should be QoS 0, 1, 2
In the past I didn´t use that. Maybe that is a good idea, but with the point above my problem is done.

Thanks to all!

I don't believe QOS has anything to do with it.

If a client has a birth, close or will message set up (in Node-red they are on the Messages tab of the server setup), these messages are sent to the broker when the client first connects.
The birth message is sent to subscribers immediately.
The close message is sent when the connection is closed gracefully.
An exchange of handshake messages allows the broker to spot if the client has crashed or hung up. After a period of time with no successful handshake, default 30 sec, the will (aka LWT) message is sent to subscribers.

OK, new for me, and I found that.
image
But I think with every 5 seconds a new message should receive I´m in the end of my problem. Otherwise I can add the LWT :wink:

You are right the trigger node should be sufficient for your requirement.

The only extra value of LWT for you would be if a third machine was subscribed to the LWT of both your Node-red machine and the source of your messages, you would have the possibility of detecting if either goes down.

1 Like

Hello again,

today the role should be work, but it doesn´t.

The program is hangig up and no new values comes - value is ever the same.

The trigger must react after 45 seconds and restart the program. But the problem is: The program isn´t really hanging up, only the USB connection to the inverter. That means, the program sends continously new messages, every 5 seconds to MQTT and then to NodeRED. But the value didn´t change, it´s freezed.

Node looks so:

So now is the question, how the trigger can detect, if the current value 0789 change latest after 45 seconds. If the value didn´t change, the trigger send the restart command.

Sorry but I thought the problem was fixed in our last discussion in that topic. Thanks for your help again.

Trigger looks so:

So messages are continuing to be received by the MQTT node, but the value doesn't change?

You can put a filter node between mqtt and trigger to remove duplicates.

Make sure that the trigger time is more than twice the normal message frequency so that occasional valid duplicates don't trigger the reset.

Thanks @jbudd.

It´s clear and I understand that with the "more than twice normal messages".

Every 5 seconds new values should come and I set the trigger to 45 seconds. Enough time for messages or maybe one lost messages.

I tried your proposal with easy inject nodes and reduced time:

It works with the testing nodes :wink: I hope it works also if the failure comes again.
Again thank you very much. :star_struck:

If the connection to the inverter has failed why are you still getting data every 5 seconds?

Is there any activity with the LWT from the device?

As mentioned in post 3?

(Just a thought......)
If the problem is back, remove the solved flag too.....
That way it is shown as not solved. :wink: