Hello,
I’m new to Home Assistant. I’m a long-time OpenHAB user and have a mix of OpenHAB, Node-RED, grafana/InfluxDB for home automation and dashboards. A lot of the stuff I play around with is a mix of wireless modules and sensors, and I thought this group might be interested in some low cost DIY BLE sensors I’ve built.
Over the years, it seems like the typical challenges of DIY wireless sensors are size, cost, battery life, and development tool complexity. I’m using these $5 Nordic BLE modules that are common on ebay and Aliexpress. And I made a set of ARM MBED code for sensors and BLE-MQTT Gateways that should be easy to extend. This project also has a BLE-LoRa bridge to extend the range of BLE sensors or make LoRa sensors.
Some of the example sensors I’ve made in this project:
-
Window Sensor – tells you how wide opened the windows are. Not just open/closed. Also, it’s not ugly.
-
Dog food level
-
Geolocation with $10 BLE-Wifi Gateways + $5 beacons. I have examples of tracking which area of the house my dog is hanging out in. This beacon can be purchased off-the-shelf and comes with a key-chain / dog-collar friendly case. Also not ugly and doesn’t look DIY.
https://www.instructables.com/id/LoRa-Tooth-Small-Wireless-Sensors/
Eric
8 Likes
Thank you for such an insightful writeup. It motivates me to try your approach. I don’t want to use any commercial solutions and want to go the DIY way.
I just found this thread. I actually found your project at the instructables site and decided to give it a go.
I have made my first door/window sensor, and when SSH in to Raspi and subscribing to topic everything works well.
If I add the sensor as “sensor” in Home Assistant it will show “1” or “0” like expected. (but updates are a bit slow)
If I add the sensor as “binary_sensor” and “device_class: door” it shows as expected but never updates. It just sits at “closed”
Any suggestions?
sensor:
- platform: mqtt
device_class: door
name: "Entrance"
state_topic: "/yyy/esp2/f8a34f9d94hf8/mag"
binary_sensor:
- platform: mqtt
device_class: door
name: "Entrance"
state_topic: "/yyy/esp2/f8a34f9d94hf8/mag"
1 Like
I am also working on the same thing. I believe we need to change the value 0 and 1 to On and Off.
This we can do via nodered or automation. I see you are almost 40 days ahead of me on this project. Did you make it work?
Yes, the following configuration has worked for me. Door/window sensors work flawless now.
- platform: mqtt
name: “Backdoor"
state_topic: "/+/+/a8df52sdfaff/mag"
device_class: door
payload_on: "1"
payload_off: "0"
Regarding payload, just subscribe to topic and double check what it reports when open/closed.
So far the problems I have had is ;
-
A couple boards have reported payload of “2” (odd state) instead of “1”, but otherwise functions well.
-
Dog tracking beacon works fine for a while, several days, but then looses signal. A re-press of the button often helps it reconnect, but the button also floods the MQTT server with thousands of transmissions per minute.
-
Couldn’t get the temperature sensor working. Tried with several different sensors, all confirmed to work on my Wemos board. Maybe some libraries are outdated? It reports 32 degrees and 0% humidity, with no change.
1 Like
This is much easier and simpler than what I did last night.
I first created two sensors in sensors.yaml
it was so simple and I over engineered it
- platform: mqtt
state_topic: '/yyy/ble_gateway/c91bc21021f1/mag'
name: bedroom_balcony_realtime
- platform: mqtt
state_topic: '/yyy/ble_gateway/c91bc21021f1/mag/p'
name: bedroom_balcony_perodic
Then I created input booleans
bedroom_balcony_door:
name: bedroom balcony door
Then I created binary sensor
- platform: template
sensors:
bedroom_balcony_door:
friendly_name: Bedroom Balcony Door
device_class: door
value_template: >-
{% if is_state("input_boolean.bedroom_balcony_door", "on") %}
true
{% else %}
false
{% endif %}
And an automation to report state to the binary sensor
- alias: bedroom balcony door sensor periodic (closed)
initial_state: true
trigger:
platform: numeric_state
entity_id: sensor.bedroom_balcony_perodic
above: 0
condition:
- condition: state
entity_id: input_boolean.bedroom_balcony_door
state: 'on'
action:
service: input_boolean.turn_off
data:
entity_id: input_boolean.bedroom_balcony_door
- alias: bedroom balcony door sensor realtime (closed)
initial_state: true
trigger:
platform: numeric_state
entity_id: sensor.bedroom_balcony_realtime
above: 0
condition: []
action:
service: input_boolean.turn_off
data:
entity_id: input_boolean.bedroom_balcony_door
- alias: bedroom balcony door sensor periodic (open)
initial_state: true
trigger:
platform: numeric_state
entity_id: sensor.bedroom_balcony_perodic
below: 1
condition:
- condition: state
entity_id: input_boolean.bedroom_balcony_door
state: 'off'
action:
service: input_boolean.turn_on
data:
entity_id: input_boolean.bedroom_balcony_door
- alias: bedroom balcony door sensor realtime (open)
initial_state: true
trigger:
platform: numeric_state
entity_id: sensor.bedroom_balcony_realtime
below: 1
condition: []
action:
service: input_boolean.turn_on
data:
entity_id: input_boolean.bedroom_balcony_door