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

How to force MQTT Discovery message? #280

Open
sumitbirla opened this issue Jan 3, 2025 · 9 comments
Open

How to force MQTT Discovery message? #280

sumitbirla opened this issue Jan 3, 2025 · 9 comments

Comments

@sumitbirla
Copy link

I have had to reset my Home Assistant and MQTT servers. Since then I haven't been able to re-add BLE entities in Home Assistant as Theengs Gateway doesn't re-publish the discovery payload:

DEBUG:BLEGateway:Already discovered or filtered: 90CEB8807040
DEBUG:BLEGateway:Sent `{"name": "Sd8a4d92e2d30a94eC", "id": "90:CE:B8:80:70:40", "rssi": -80, "brand": "GENERIC", "model": "iBeacon", "model_id": "IBEACON", "type": "BCON", "mfid": "4c00", "uuid": "74278bdab64445208f0c720eaf059935", "major": 0, "minor": -23587, "txpower": -59}` to topic `home/TheengsGateway/BTtoMQTT/90CEB8807040`

Is there any way to force a republish of the discovery payload?

{
    "adapter": "",
    "bindkeys": {},
    "blacklist": [],
    "ble": 1,
    "ble_scan_time": 5,
    "ble_time_between_scans": 600.0,
    "discovery": 1,
    "discovery_device_name": "TheengsGateway",
    "discovery_filter": [
        "IBEACON",
        "H5072/75"
    ],
    "discovery_topic": "homeassistant",
    "enable_tls": 0,
    "enable_websocket": 0,
    "general_presence": 0,
    "hass_discovery": 1,
    "host": "mqtt.local",
    "identities": {},
    "log_level": "DEBUG",
    "lwt_topic": "home/TheengsGateway/LWT",
    "pass": "***",
    "port": 1883,
    "presence": 0,
    "presence_topic": "home/TheengsGateway/presence",
    "publish_advdata": 0,
    "publish_all": 1,
    "publish_topic": "home/TheengsGateway/BTtoMQTT",
    "scanning_mode": "active",
    "subscribe_topic": "home/+/BTtoMQTT/undecoded",
    "time_format": 0,
    "time_sync": [],
    "tls_insecure": 0,
    "tracker_timeout": 120,
    "user": "***",
    "whitelist": []
}
@DigiH
Copy link
Contributor

DigiH commented Jan 3, 2025

@sumitbirla

Did you stop and restart Theengs Gateway?

@sumitbirla
Copy link
Author

Yes, numerous times. I was able to republish Discovery message my changing the Discovery topic name (-Dt). But if I left it to default "homeassistant", it would not republish upon restart.

@DigiH
Copy link
Contributor

DigiH commented Jan 3, 2025

So when you view the homeassistant topic with MQTT Explorer. Do you see any discovery messages as subtopics at all?

@DigiH
Copy link
Contributor

DigiH commented Jan 3, 2025

DEBUG:BLEGateway:Already discovered or filtered: 90CEB8807040

This really looks as if the discoveries have been published fine, also to the home assistant topic, and therefore won't be published again.

Very likely that your HA and MQTT Broker resetting still left something unfinished for HA to cruelty recognise these discovery messages again for processing.

MQTT Integration also installed again?

@sumitbirla
Copy link
Author

Taking Home Assistant out of the equation, here is a test you can do to reproduce this:

  1. Manually delete the relevant HA Discovery topics from the MQTT broker (homeassistant/sensor/*).
  2. Restart TheengsGateway
  3. Check if the discovery topics have bee re-created. In my case, they are not recreated.

@DigiH
Copy link
Contributor

DigiH commented Jan 3, 2025

  • Manually delete the relevant HA Discovery topics from the MQTT broker (homeassistant/sensor/*).

I even deleted the whole homeassistant topic, so all the previous discovery messages.

Then Starting up Theengs Gateway again, all the discovery messages are being created again correctly as expected. I confirmed this procedure twice now.

I really wonder what the issue might be with your setup. Are you on

theengsdecoder 1.8.3
TheengsGateway 1.5.0

if you are also using a pip install of Theengs Gateway?

@DigiH
Copy link
Contributor

DigiH commented Jan 3, 2025

Hold on ;)

"ble_time_between_scans": 600.0,

So you wait 10 minutes before each BLE scan, which also means there won't be any discovery messages until at least 10, possibly 20 or 30 minutes, depending how many and which devices might be discovered in the 5 seconds scan window. You might want to change that to a shorted time, at least until you have all your discovery messages agin. Could that have been your issue?

And

"discovery_filter": [
"IBEACON",
"H5072/75"

I I take it that you do NOT want any H5072/75 devices to be discovered, correct?

@sumitbirla
Copy link
Author

These are the versions:

theengsdecoder 1.8.3
TheengsGateway 1.5.0

I set the ble_time_between_scans to 10 minutes to conserve battery on the sensor. In any case, I let the system run for a whole day and HA never received a new discovery message. Maybe TheengsGateway doesn't post the discovery message with the retain flag, so if HA is restarted, the devices are not rediscovered.

For now, I have manually pushed a discovery message to MQTT with the retain flag. This appears to work even after HA is restarted. Also, I get more specific entity names by doing this manually:

{
    "device": {
        "identifiers": "GVH5075_12FE",
        "name": "Govee Outdoor Thermometer",
        "manufacturer": "Govee",
        "model": "H5075",
        "serial_number": "A4:C1:38:86:12:FE"
    },
    "origin": {
        "name": "TheengsGateway",
        "sw": "1.5.0",
        "url": "https://gateway.theengs.io/"
    },
    "components": {
        "temperature": {
            "name": "Temperature",
            "platform": "sensor",
            "device_class": "temperature",
            "unit_of_measurement": "°C",
            "unique_id": "govee_12fe_temperature",
            "state_topic": "stat/BLE/A4C1388612FE",
            "value_template": "{{ value_json.tempc }}"
        },
        "humidity": {
            "name": "Humidity",
            "platform": "sensor",
            "device_class": "humidity",
            "unit_of_measurement": "%",
            "unique_id": "govee_12fe_humidity",
            "state_topic": "stat/BLE/A4C1388612FE",
            "value_template": "{{ value_json.hum | round(0) }}"
        },
        "battery": {
            "name": "Battery",
            "platform": "sensor",
            "device_class": "battery",
            "unit_of_measurement": "%",
            "unique_id": "govee_12fe_battery",
            "state_topic": "stat/BLE/A4C1388612FE",
            "value_template": "{{ value_json.batt }}"
        },
        "rssi": {
            "name": "RSSI",
            "platform": "sensor",
            "device_class": "signal_strength",
            "unit_of_measurement": "dBm",
            "unique_id": "govee_12fe_rssi",
            "state_topic": "stat/BLE/A4C1388612FE",
            "value_template": "{{ value_json.rssi }}"
        }
    },
    "availability_topic": "stat/BLE/status",
    "qos": 2
}

@DigiH
Copy link
Contributor

DigiH commented Jan 8, 2025

"model": "H5075",

As I stated above, if this is the device you wanted discovery messages for, you shouldn't have added it to the "discovery_filter" list, as this list contains the model_ids of the devices you want to filter out to not be discovered.

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

No branches or pull requests

2 participants