MQTT binary sensor from log OpenWrt

Hello.
Please tell me how to make a binary sensor for online identification of my device in OpenWRT?
There is an mqtt topic that sends openWRT registration:

DHCPACK(br-lan) 192.168.1.110 30:45:96:aa:02:3a Artem ROOter/syslog 19:38:48
DHCPREQUEST(br-lan) 192.168.1.110 30:45:96:aa:02:3a ROOter/syslog 19:38:47
wlan0-1: STA 30:45:96:aa:02:3a WPA: pairwise key handshake completed (RSN) ROOter/syslog 19:38:47
wlan0-1: AP-STA-CONNECTED 30:45:96:aa:02:3a ROOter/syslog 19:38:47
wlan0-1: STA 30:45:96:aa:02:3a IEEE 802.11: associated (aid 2) ROOter/syslog 19:38:47
wlan0-1: STA 30:45:96:aa:02:3a IEEE 802.11: authenticated ROOter/syslog 19:38:47
wlan0-1: STA 30:45:96:aa:02:3a IEEE 802.11: disassociated ROOter/syslog 19:38:38
wlan0-1: AP-STA-DISCONNECTED 30:45:96:aa:02:3a ROOter/syslog 19:38:38

When the helmet connects:

wlan0-1: STA 30:45:96:aa:02:3a IEEE 802.11: authenticated

When the helmet turns off:

wlan0-1: STA 30:45:96:aa:02:3a IEEE 802.11: disassociated

Hi piciolog,

I saw your post in Discord, I didn’t know how to answer it. I still don’t.

I don’t think any of what you shared has any info about an MQTT broker or the topic needed or anything, so there is nothing I can add really.

This tool can help you set up stuff in MQTT:
Troubleshooting MQTT? MQTT-Explorer can help you be successful!
If you have Add-ons available, try adding this Add-on repository to your Add-on list. GitHub - GollumDom/addon-repository.

Other that that you need to figure out the topic based on your software, have that software sign into the broker, and send the broker whatever topic. Then something on the other end has to be setup, probably HA to watch the topic and do something with it.
See the MQTT documentation in the HA docs, theres a lot of it.

Have a look at the “luci (openwrt)” integration. It provides device trackers for your use-case.

Unfortunately, this does not suit me, since openwrt is located outside my local network, and in another city. And it has a gray dynamic IP address :smiling_face_with_tear:.
It sends a copy of the log to an external mqtt broker, in one topic. And my local Mosquitto is configured with an external mqtt server in bridge mode.

I tried to do it this way, but HomeAssistant complains that it’s wrong:

mqtt:
  - binary_sensor:
      name: Artem
      state_topic: "ROOter/syslog"
      payload_on: "STA 30:45:96:aa:02:3a IEEE 802.11: authenticated"
      payload_off: "wlan0-1: STA 30:45:96:aa:02:3a IEEE 802.11: disassociated"

Please correct this

Show us the MQTT topic contents (MQTT Explorer, perhaps) for that topic in both states. Without that, we’re guessing.

I set it up according to these instructions

Thanks.

How does it complain?

Is this your first / only MQTT sensor? Where have you put that config — straight into configuration.yaml?

This is not your (complete) state topic, according to the picture

1 Like

I’ve been using this past year with no problem other than it becomes unresponsive every few days so I have HA restart early each morning. I also use fast connect on Openwrt as I have a router on each floor. I then use an automation to turn the binary sensor to off for the previous router when as soon as it picks it up on new router as it was faster than waiting for it to go off by itself.
I only use it for a few devices.

It doesn’t complain anymore, but in the binary sensor state it says “unknown”
All my sensors are placed in a file: /homeassistant/includes/mqtt.yaml
In configuration.yaml I have written: mqtt: !include includes/mqtt.yaml

image

Did you leave/join the wifi in the meantime?

Yes, of course. And I did it several times.

Well, if your state topic is correctly “secret1/secret2/router/lan/ROOter/syslog”, as in MQTT Explorer, the only reason I see would be that the values sent contains hidden characters (e.g. a carriage return)

@piciolog If weird characters are your problem, you could create an MQTT sensor with the topic contents as its state, then a template binary sensor that looks for substrings in that, if you don’t care about the MAC:

{{ 'on' if 'authenticated' in states('sensor.artem')
   else 'off' if 'disassociated' in states('sensor.artem')
   else this.state }}

I followed your advice.
Installed wifi-presence on my router.
Set up mqtt.
But it only sends me online or offline information of the router itself.
Please tell me how I can make it send me information about connecting and disconnecting devices?
I read there that you need to register all devices in a JSON file, but I didn’t understand where to put it and how to launch it.
image

If I understand correctly, then here it is:

image

The sensor state has not changed: changes the state to “unavailable”

I don’t think you did.

My suggestion is that you create an MQTT sensor.artem that contains the topic value as its state.

Then, in the UI, create a template binary sensor helper (nothing to do with MQTT) with that template.

mqttexp
Select this line to publish to.

BR-wifi-presence/config #mine
wifi-OpenWRT-V-Kvartire/config  #yours

Or what ever your device is

{
  "devices": [
    {
      "name": "hedgehog_laptop_backroom",
      "mac": "66:66:6B:62:66:66"
    },
    {
      "name": "?_up",
      "mac": "66:66:66:72:66:A2"
    },
    {
      "name": "laptop_backroom",
      "mac": "66:66:6C:22:66:26"
    },
    {
      "name": "chromecast",
      "mac": "F4:77:77:77:61:77"
    },
    {
      "name": "phone_backroom",
      "mac": "58:D5:0A:6C:3D:4B"
    }
  ]
}

Publish in that format above using mqtt explorer. You can add in more than just 4.I select retain in the box below.


It then creates a device tracker

image

The router sends only its status, it itself sends connections and disconnections of devices with MAC addresses.
You have separate topics with MAC addresses, but I don’t.