I managed to get my 3 Ruuvis transmitting to an ESP32 via Bluetooth and then broadcasting over wifi using MQTT into HA. Here’s how:
- Download Visual Studio Code and add the Platformio extension
- Pull down the files from this repo and open it up in VS Code/platformio:
https://github.com/hpirila/ESP32-Ruuvitag-Collector
- Go into “src” folder and then config.cpp and edit the wifiSSID, password, MQTT server IP, username, and password.
- Comment out line 42 so it looks like this:
Code: Select all
//“influxConfiguration.push_back(iC);”
- Delete the word homeassistant in line 67 and leave it like this:
Code: Select all
std::string mqttHomeAssistantDiscoveryTopic="";
- Set line 77 for the interval you want to collect info, in seconds (no less than 30)
Code: Select all
const int deepSleepWakeUpAtSecond=60;
- Set line 88 to “0” so wifi is always on or else it won’t broadcast each time it polls the sensors. If you had your ESP on a battery you might want to change this to something other than 0 to save battery, but I’d imagine most people will plug theirs in to power.
- Flash your ESP with this code using platformio and then watch it in a serial monitor. It’ll show the MAC addresses of the devices it finds and show the temperature readouts for each (only temp here, no other data).
- Grab these MACs and paste them into your list on line 18 of config.cpp. This way the ESP will only scan these addresses and quit when it finds them so we can save some time.
You will now be able to see the values in MQTT by subscribing to this topic format:
mqttTopicPrefix/+Ruuvitag mac address/+state
By default, the topic prefix is ruuviesp32, but this can be changed in config.cpp to whatever you want. So by default it looks like this:
Example: ruuviesp32/C2CA7F7D07F5/state
When you subscribe to that you should see all the sensor’s data come through at each interval you set.
Now it’s just a matter of creating an MQTT sensor in Home Assistant for each Ruuvi you have and then templating out the values you want. I will paste my config in in a bit.
Edit: As promised
Code: Select all
sensor:
- platform: mqtt
name: "Ruuvi 1 Temperature"
state_topic: "ruuviesp32/D6FBC72850EB/state"
unit_of_measurement: '°C'
value_template: "{{ value_json.temperature }}"
- platform: mqtt
name: "Ruuvi 1 Humidity"
state_topic: "ruuviesp32/D6FBC72850EB/state"
unit_of_measurement: '%'
value_template: "{{ value_json.humidity }}"
- platform: mqtt
name: "Ruuvi 2 Temperature"
state_topic: "ruuviesp32/DA6BAFDD30F0/state"
unit_of_measurement: '°C'
value_template: "{{ value_json.temperature }}"
- platform: mqtt
name: "Ruuvi 2 Humidity"
state_topic: "ruuviesp32/DA6BAFDD30F0/state"
unit_of_measurement: '%'
value_template: "{{ value_json.humidity }}"
- platform: mqtt
name: "Ruuvi 3 Temperature"
state_topic: "ruuviesp32/E51DD692D3BC/state"
unit_of_measurement: '°C'
value_template: "{{ value_json.temperature }}"
- platform: mqtt
name: "Ruuvi 3 Humidity"
state_topic: "ruuviesp32/E51DD692D3BC/state"
unit_of_measurement: '%'
value_template: "{{ value_json.humidity }}"