This script will connect to Nordic's Thingy:52 IoT Sensor Kit using Bluetooth, and send the environment sensor data to Home-Assistant set up with the MQTT Sensor component.
- A Raspberry Pi with built in Bluetooth or a Raspberry Pi and a Bluetooth USB dongle.
- The Raspbian Jessie operating system image.
- A Nordic Thingy:52 IoT Sensor Kit
- Home-Assistant with MQTT Sensor component
- Git, Node.js, npm and thingy52 lib.
- Update the package manager:
sudo apt-get update
. - Add the latest version of Node.js to package manager:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
- Install Node.js and thingy52 lib dependencies:
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev git nodejs
- Clone the repository:
git clone https://github.com/joakimtoe/thingy52_hass_mqtt_sensor.git
- Go into the thingy52_hass_mqtt_sensor folder.
cd thingy52_hass_mqtt_sensor
- Install the thingy52 lib:
npm install thingy52
- Find your Thingy:52's bluetooth device address using.
hcitool
pi@raspberrypi:~ $ sudo hcitool lescan
LE Scan ...
E2:16:3A:FD:67:46 Thingy
- Open
config.json
withnano config.json
- Remove ':' from the device address and add it (with this format
e2163afd6746
) to the parameterthingy_white_list
in theconfig.json
file. Or removethingy_white_list
completly to connect to all discovered Thingy:52's. - Change
mqtt_url
,mqtt_username
andmqtt_password
according to your MQTT Broker. See Home-Assitant configuration chapter if in doubt. If you are using Home-Assitant's embedded MQTT broker see this page.
To run the script: sudo node thingy_hass_mqtt.js
- Create a new systemd service
sudo nano /etc/systemd/system/thingy-hass-mqtt.service
- Then copy/paste the following into the service file:
[Unit]
Description=Thingy Environment MQTT service
After=network.target ntpdate.service
[Service]
Environment=PATH=/usr/bin:/usr/local/sbin:/usr/local
ExecStart=/usr/bin/node /[path to thingy52_hass_mqtt_sensor]/thingy_hass_mqtt.js
StandardOutput=inherit
StandardError=inherit
Restart=always
User=root
[Install]
WantedBy=multi-user.target
Alias=thingy-hass-mqtt.service
- Change the path to your thingy52_hass_mqtt_sensor folder and save.
- Reload systemd:
sudo systemctl --system daemon-reload
- To start automatically at boot, enable the service:
sudo systemctl enable thingy-hass-mqtt
. Usedisable
to turn off. - To start it now use:
sudo systemctl start thingy-hass-mqtt
. Also supportsstop
,restart
andstatus
. - To get the log use:
sudo journalctl -f -u thingy-hass-mqtt
- Setup MQTT and select MQTT Broker according to this page.
- Availible data are:
{
"temp": "25", // Temperature in Celsius
"press": "1000", // Air Pressure in hPa
"humid": "30", // Relative Humidity in %
"eco2": "500", // Estimated CO2 in ppm
"tvoc": "20", // Total Volatile Organic Compound in ppb
"batt": "85" // Battery level in %
}
- Add sensors like in the following example.
# Example configuration.yaml entry
sensor:
- platform: mqtt
state_topic: "thingy/[lower case bluetooth device address without :]/environment"
name: "Temperature"
unit_of_measurement: "C"
value_template: '{{ value_json.temp }}'
To find your Thingy:52's bluetooth device address use. sudo hcitool lescan
- Restart Home-Assitant and the added sensors will appear in the States view.