WiFi/MQTT car presence sensor for garage door automation

This is rather genius @luma, have uploaded the code and configured the automation, going to test it tomorrow. Can you please elaborate about the antenna connection part ? I’ve yet to figure out the exact parts to order and how to connect them, thanks a lot in advance

The video posted by @Mukund up there is probably the best explanation I can find of the process. On the WeMos Pro there is a 0-ohm 0603 resistor that is used to bridge the antenna connection either to the on-board ceramic antenna (default configuration) or to the u.FL antenna connector for attaching an external antenna. If you want to use an external antenna, you’ll need to rotate that resistor.

In my testing, the external antenna didn’t make a heck of a lot of difference, but if I ever make good on my promise of sending RSSI details I might be able to actually declare how well this does or doesn’t work.

From my testing it’s working quite well for me with the on-board antenna, again some fine automation and a clear explanation, thanks a lot for that @luma

1 Like

@luma - where did you get that project box for this - just curious if you had a link or made it your self?

Thanks!

I designed that simple enclosure for easy 3D printing, and the top/bottom parts are available in STL format in the github link in the OP. If you don’t have a printer available, you might try checking https://www.3dhubs.com/ to find a local provider which can print it out for you. Pricing may vary by area but I’m getting quotes under $5 to print both pieces here in Michigan.

1 Like

@luma - thanks for the input on that case - much appreciated!

Wonder no more! I’ve updated the Arduino code in the GitHub repo to add a new sensor, once again created automatically via MQTT Discovery (you must have this enabled in your configuration.yaml!) which will periodically report signal strength while the device is connected. The reporting interval can be adjusted in the code, currently it will send the observed RSSI in dBm every 5 seconds. Feel free to adjust as your needs require.

1 Like

Love it. I just started to tinker with this today for a sensor uptime (in seconds).

Basically in the same loop for the signal strength have it report how long the wemo has been up. This is another way you could calculate arriving or leaving.

I would think you would then want the Last will and testament to set the up-time back to 0 when the disconnect happens.

I will see how bad I can butcher your code if you think this is outside of your scope.

also just tried your code and cant get the new signal sensor to show up. I can see the mqtt discovery and state messages get pushed but the sensor does not show up in HA

unless its my setup… If i manually setup the mqtt sensor with a different name it works. Auto discovery does not seem to be working.

Make certain that you have modified the PubSubClient.h like so:

#define MQTT_MAX_PACKET_SIZE 512

Yes that is set and by using MQTTbox I can see the state get set.

{"name": "device_jeep", "device_class": "sensor", "state_topic": "homeassistant/sensor/device_jeep/state", "unit_of_measurement": "dBm", "value_template": '{{ value }}'}
qos : 0, retain : true, cmd : publish, dup : false, topic : homeassistant/sensor/device_jeep/config, messageId : , length : 211

Huh. Does it ever publish the RSSI value when watching w/ MQTTbox?

yes.

-61
qos : 0, retain : false, cmd : publish, dup : false, topic : homeassistant/sensor/device_jeep/state, messageId : , length : 43

and I set up a manual mqtt sensor and it reads correctly.

- platform: mqtt  
  state_topic: "homeassistant/sensor/device_jeep/state"  
  name: "jeep2"  
  unit_of_measurement: "dBm"  
  value_template: '{{ value }}'

image

Huh. Don’t really have much more to add on this, the functionality for MQTT discovery is a core hass feature and from what you’ve posted it seems like it should be working. I wonder if you published a properly-formatted discovery message manually if it’d show up in hass?

Something like:
mosquitto_pub -h mqtt -t 'homeassistant/sensor/device_jeep/config' -m '{"name": "device_jeep", "device_class": "sensor", "state_topic": "homeassistant/sensor/device_jeep/state", "unit_of_measurement": "dBm", "value_template": "{{ value }}"}'

mosquitto_pub -h mqtt -t 'homeassistant/sensor/device_jeep/state' -m '-123'

Pasting those two lines into a bash shell creates a sensor.jeep entity with the state set to -123:

This might be challenging due to how the ESP8266 (poorly) handles time. While Arduino uses a 64-bit counter for millis() yielding a 49-day window (which is probably good enough for “how long has my car been turned on”), the Espressif SDK’s system_get_time() returns a 32-bit millis(), meaning the uptime counter will roll over approximately every 72 minutes. edit: I wonder if the source I pulled this from is correct as the numbers don’t add up when I run them. I’m going to give this a shot and see what happens.

In unrelated news, I’ve updated the enclosure model to include a viewport for the LED so you can see if the device is connected.

Thanks to adding the RSSI info I’ve also discovered that I’m a huge idiot that shouldn’t be allowed near RF projects: The antenna + uFL to SMA whip that I bought as a package deal were not the same polarity (ugh) and I never noticed it. The result as that my external antenna was never physically connected. Swapping around for a correct-polarity whip I had on-hand for another project immediately yielded much better signal strength.

It’s almost as if actually connecting your antenna results in a better signal…

1 Like

I ended up having to change a line in your code.

Line 23 I had to change ’ to " around {{ value }} in order for the sensor to work.

const String mqttDiscoSignalConfigPayload = "{\"name\": \"" + mqttNode + "\", \"device_class\": \"sensor\", \"state_topic\": \"" + mqttDiscoSignalStateTopic + "\", \"unit_of_measurement\": \"dBm\", \"value_template\": \"{{ value }}\"}";

1 Like

OK great work! The MQTT sensor docs use single quotes for value_template while the discovery doc uses quotes like you’ve suggested. Still not clear why it has problems on your side and not here but I’m going to update the repo with this change as your approach is directly indicated in the discovery docs. Thanks for tracking this down.

Allright some additional changes:

  • Added <devicename>-signal and <devicename>-uptime sensors
  • Use double quotes in value_template
  • Minor change to enclosure to align viewport for LED
  • Added LED twinkle effect when connected to broker for easier LED visibility in daylight
4 Likes

I saw you fixed this by changing . to - in the sensor names.

I had actually changed mine to _ to follow the documentation for entity’s. I also divided the millisecond counter to seconds just to make the sensor a litle more useful.

Thank you for this. Now to hard wire them to the car.

Hackaday just ran a piece on this project. My first HaD FP!

2 Likes