Custom Firmware that reads information from a BLE device and creates entities of it

Hi,

I am searching for some input for solving an issue I have with a remote location… and maybe, this is the right place to kickoff some ideas / or maybe, even get some input on how to solve this.

First, the problem:
We noticed some rats in a remote location which is a bit off from our house - so we are not there regularely.

I found a rat trap, which comes with a “smart connect” app - but, this device only communicates with your Smartphone via Bluetooth, when you are in range…

My Idea was, to install this together with an ESP32 - the ESP could connect to the trap via Bluetooth - read the information, creates the required entities and then, provide them in HomeAssistant.

I found some information about the BLE signals the device is sending:

but I am not sure, on how to start this with the ESP programming…

I think you might have an easier way by making the ESPHome a bluetooth proxy and then use the sensor info you found with the BLE integration in HA.

hm… okey could be :slight_smile:
I will check it out - but having this as a finished esphome firmware would also be a nice addition … ^^

1 Like

Hey Christoph,
How did you get on with this. I have several Goodnature traps and would love to get them into homeassistant. I’m considering adding an accelerometer to one and have that trigger an esp when the trap has been set off but it seems it should be easier than that.

Cheers

haven’t started with this yet… still waiting on the traps :slight_smile:

I’ve played around a bit - but haven’t had much success so far.

Using a BTProxy (ESP32) - I could get the following somehow to work:

text-sensor:
  - platform: ble_scanner
    name: "BLE Devices Scanner"

the device is showing a Text Sensor with A LOT of BLE Advertisments from different devices.
It appears, that one of the traps does also appear here:

It is the “GN” (GoodNature) - and the Mac-Address is also the correct one, from what I could figure out.

But the following code does only return “unknown”

sensor:
  - platform: ble_rssi
    mac_address: 1E:E8:20:C2:C6:9A
    name: "GoodNature MouseTrap RSSI"

Based on the Documentation, this should also work and should at least report the RSSI…

But even then, I am not sure, how I should continue…atm :frowning:

I don’t see this device covered there, but maybe somebody would be interested in figuring it out.

Some devices advertise all the necessary information, which makes it easy, others only give it to you if you connect and ask nicely.

I use the Theengs Gateway (which uses the decoder) and MQTT, since I do things outside of HA mostly. It does work with HA too.

so - maybe, this does help a bit…
yet, I haven’t figured out on how to continue…

but I am running the following on one of my ESPHome devices:

ble_gateway:
  id: blegateway
  devices:
    - mac_address: 1E:E8:20:C2:C6:9A
    - mac_address: C1:0B:0C:26:94:7F
  on_ble_advertise:
    then:
      homeassistant.event:
        event: esphome.on_ble_advertise
        data:
          packet: !lambda return packet;

esp32_ble_tracker:

1E:E8:20:C2:C6:9A is the GoodNature MouseTrap

The ESP logged some communication, which I’ve tried to interprete…

[12:04:37][D][goodnature.mousetrap]: [E1:E8:20:C2:C6:9A] Packet 043E24020100019AC6C220E8E11802010603030D600CFF59006084D0B200040600040309474EAC
[12:04:38][D][goodnature.mousetrap]: [E1:E8:20:C2:C6:9A] Packet 043E24020100019AC6C220E8E11802010603030D600CFF59006084D0B200040600040309474EAC
[12:04:40][D][goodnature.mousetrap]: [E1:E8:20:C2:C6:9A] Packet 043E24020100019AC6C220E8E11802010603030D600CFF59006084D0B200040600040309474EAC
[12:04:41][D][goodnature.mousetrap]: [E1:E8:20:C2:C6:9A] Packet 043E24020100019AC6C220E8E11802010603030D600CFF59006084D0B200040600040309474EA9
[12:04:44][D][goodnature.mousetrap]: [E1:E8:20:C2:C6:9A] Packet 043E24020100019AC6C220E8E11802010603030D600CFF59006084D0B200040600040309474EAD
[12:04:45][D][goodnature.mousetrap]: [E1:E8:20:C2:C6:9A] Packet 043E24020100019AC6C220E8E11802010603030D600CFF59006084D0B200040600040309474EAC
[12:04:46][D][goodnature.mousetrap]: [E1:E8:20:C2:C6:9A] Packet 043E24020100019AC6C220E8E11802010603030D600CFF59006084D0B200040600040309474EAA
[12:04:50][D][goodnature.mousetrap]: [E1:E8:20:C2:C6:9A] Packet 043E24020100019AC6C220E8E11802010603030D600CFF59006084D0B200040600040309474EA9
[12:04:51][D][goodnature.mousetrap]: [E1:E8:20:C2:C6:9A] Packet 043E24020100019AC6C220E8E11802010603030D600CFF59006084D0B200040600040309474EAF

The MouseTrap does behave different than the rat-trap.
While the RatTrap will only be activated after it has triggered (and then will send over BT until the app receives the data) - the other device is communicating all the time.

Taking one of the packeges, the part in bold will be the MAC Address - but written reverse.

043E24020100019AC6C220E8E11802010603030D600CFF59006084D0B200040600040309474EA9

In the whole communication I captured, only the last two chars are different…
But yet, I count not interpret the information more deeply.

Once I figured out more, I will update again.

after digging further into this and reading some posts again and again, I hopefully came up with an ‘easy’ solution… even though, I don’t know if it is working in the end.

  1. get the MacAddress of your Trap
    This is probably easier for the MouseTrap than for the A24 Rat & Stoat Trap.
  • I got the MacAddress by just activating the device, and searched for new devices on my Smartphone.
    It was then shown as “GN” - and I could write down the MAC Address.
  • For the A24 Trap, I had to use a Bluetooth Scanner app on my phone and searched for another “GN” device.

With both MacAddresses, I created the following configuration in ESPHome:

esp32_ble_tracker:

binary_sensor:
  - platform: ble_presence
    mac_address: xx:xx:xx:xx:xx:xx # MAC-Address Trap A
    name: "GoodNature Mouse Trap"

  - platform: ble_presence
    mac_address: xx:xx:xx:xx:xx:xx # MAC-Address Trap B
    name: "GoodNature Rat Trap"

After flashing the ESP, both sensors were shown in HomeAssistant.
image

I changed the DeviceType to Vibration - but you can also use Tamper…

In theory, whenever the trap will strike, it should send a signal through Bluetooth - and the Signal should be set in the Sensor… (we will see, if this is working)

Then, I created a helper (one for each sensor).
The helper is type counter to count the amount of strikes.

With an automation, I do check, if either Trap A or Trap B hit - and if so, I increase the corresponding counter by +1

alias: Count catched Mice and Rats
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.water_meter_garden_goodnature_mouse_trap
    from: "off"
    to: "on"
    id: MouseCatch
  - trigger: state
    entity_id:
      - binary_sensor.water_meter_garden_goodnature_rat_trap
    from: "off"
    to: "on"
    id: RatCatch
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - MouseCatch
        sequence:
          - action: counter.increment
            metadata: {}
            data: {}
            target:
              entity_id: counter.mousetrap
      - conditions:
          - condition: trigger
            id:
              - RatCatch
        sequence:
          - action: counter.increment
            metadata: {}
            data: {}
            target:
              entity_id: counter.rattrap
mode: single

As a customer you could contact the manufacturer and ask if they would like to disclose their local Bluetooth API for local Home Assistant integration.
Some manufacturers are doing it (Switchbot for example), and HA being a significant users base, Good Nature may be interested by an integration.

I’ve already tried to contact the company - haven’t got any reply from them :frowning:

But the above solution seems to work…
At least, it was triggered, when also the app did receive a signal.
But - I think it is more of a workaround, rather a full solution.

1 Like