Device update/Dashboard/MQTT

I’ve setup a dashboard that I want to display the statues of a device I.e. “Online” or “Offline”
I have a MQTT broker which the device is registered to. When I press the “Status” button on the dashboard it publishes a message to the device, I have an “If” statement that returns “Online” when it receives the published message. The issue is how do I know when it’s offline? If I press the status button it sends the msg.payload, but because the device is offline I don’t get a response. How do I get the dashboard to display’Offline” when I don’t receive a response within 10s?

Perhaps this gives you the little push

Certainly a little bit modification needed: the trigger is started by your push button and the mqtt message received should do the reset.

Yes Chris, that's what I thought initially (my deleted post above).
But the writer is using a push button to sent the MQTT msg, so unless he continually presses it every 10 secs, the trigger node will timeout, and send Offline.

See my edit ... the trigger should be started by the button.

But I use regular messages from my devices. When they don’t arrive in time (with a little headroom) the offline flow is triggered so I don’t need to initiate a ping

1 Like

If you investigate the MQTT feature, "Last Will and Testament" it may give you some ideas.

The way I do it is to get the device to send an MQTT "heartbeat" message every 50 sec. (so it is just under a minute). The LWT is a broker feature that if the broker doesn't receive a message from the client within the designated time period (say 60 seconds), it automatically "sends" the LWT message to itself.

Subscribe to the heartbeat topic and you will be notified if/when the device goes online or offline.

If the device can't talk MQTT directly, (say a serial device connected to your Node-RED device), I simulate the LWT processing using a trigger node.

That is the most elegant solution! I totally forgot LWT ... I use the homie convention in all my homebrew devices and the $state is set to “gone” by LWT - and $state=“ready” or other states are send in regular intervals.

1 Like

Just had a brief look at your flow. Only curious why you are using the “unconventional“ topic $online instead the $state topic?

I think I had something that generated $online and so I kept using it when writing my own code. Or maybe that was just where my mind was at at the time :grinning: I wrote that a long time ago now. I think that the homie "standard" topics have probably evolved quite a lot since I first (ab)used them.

I'm well overdue for a complete overhaul of my home automation flows, they've grown very messy and a bit long in the tooth in places. But unpicking code that evolved from my early involvement with Node-RED isn't so easy and as it mainly "just works", there isn't so much incentive to change.

Beginning to feel the limits of my 2 Pi's now though and my NAS is also quite old so I'm thinking of repurposing an old Lenovo laptop as a start to restructure things. Running Debian on it, it should easily handle the usual mix of InfluxDB, Telegraf, Grafana, MQTT broker and Node-RED. And it should also be able to take webmin and NGINX or Caddy as a reverse proxy/web-server.

I said goodbye to my raspberries a few years ago because I never got the running reliable for 24/7 - And as I’m not the linux guy I felt uncomfortable using copy/paste tutorials without really knowing what’s happening behind the scene.
Since then I use a refurbished dell small form factor i5 office desktop with ssd and server grade hdds - totally happy.
As longer I use the homie convention I’m convinced that it is well designed and has more capabilities than I recognized on the first look impressed only by the auto detection function. I’m more impressed using it as my “state server” together with mosquitto. No need to think about where to store the system state. Node-RED is simply a client as my devices are. Reboots, wd resets and other things aren’t a problem as long as the broker do it’s job.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.