ESP32 + ruuvi

Home Assistant automation projects, questions, etc. go here.
Post Reply
dirkdiggler147
LED-Curious
LED-Curious
Reactions:
Posts: 20
Joined: Fri Jun 12, 2020 9:52 pm

I have managed to get a ESP32 connected to my HA and I have also been able to connect a binary sensor:

Code: Select all

esp32_ble_tracker:

binary_sensor:
  - platform: ble_presence
    mac_address: ******
    name: "ESP32 BLE ruuvi"
I can see this in the entity list.

Anyone got any info on how I can read data from the ruuvi? Temp, RH etc

@gvbz I know that you have posted about using nodered to do this but do you have any idea? I dont want to use nodered as homeassistant is hosted outside of bluetooth range (but on the lan)

Thanks
User avatar
gvbz
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 37
Joined: Thu Apr 02, 2020 3:30 pm

dirkdiggler147 wrote:
Wed Jul 08, 2020 2:53 pm
I have managed to get a ESP32 connected to my HA and I have also been able to connect a binary sensor:

Code: Select all

esp32_ble_tracker:

binary_sensor:
  - platform: ble_presence
    mac_address: ******
    name: "ESP32 BLE ruuvi"
I can see this in the entity list.

Anyone got any info on how I can read data from the ruuvi? Temp, RH etc

@gvbz I know that you have posted about using nodered to do this but do you have any idea? I dont want to use nodered as homeassistant is hosted outside of bluetooth range (but on the lan)

Thanks
So I have no idea about ESP32 to HA communications, but on the ESP side of things I've used this reference to get data out of a RuuviTag: https://www.hackster.io/amir-pournasser ... uvi-e8a68d. Can you read the values in HA after decoding the ruuvi data into JSON format, or maybe right from the array? Check out the code snippet in that link, in that example they are sending data from the ESP32 to a cloud server.

I also know that Hass.IO has a RuuviTag addon but it sounds like you are out of range and that's why the ESP32. https://github.com/akx/hass-ruuvitag
480W Bridgelux EB Gen3 Parallel Build: https://bit.ly/2NfoVyE
Grow Room Automation w/ Node Red: https://bit.ly/3hOm5yK
Github: https://github.com/gvbz/gardenbro
Instagram: @loudfarms_ca
dirkdiggler147
LED-Curious
LED-Curious
Reactions:
Posts: 20
Joined: Fri Jun 12, 2020 9:52 pm

Thanks for the info @gvbz

I am sure there is some way to make it work with ESP but I couldn't find it.

In the end I moved the pi closer to the tent and went with a HA addon as you suggested.

I used https://github.com/ruuvi-friends/ruuvi-hass.io

Then edited the yaml config to add sensors. Seems to be working well.

Thanks again
User avatar
gvbz
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 37
Joined: Thu Apr 02, 2020 3:30 pm

dirkdiggler147 wrote:
Thu Jul 09, 2020 12:43 pm
Thanks for the info @gvbz

I am sure there is some way to make it work with ESP but I couldn't find it.

In the end I moved the pi closer to the tent and went with a HA addon as you suggested.

I used https://github.com/ruuvi-friends/ruuvi-hass.io

Then edited the yaml config to add sensors. Seems to be working well.

Thanks again
I just got HA up and running on my Pi 3, mind explaining how you got the Ruuvis working using this method? I'm running into the following issue when compiling my configuration file in HA:

Platform error sensor.ruuvi - No module named 'simple_ruuvitag'
480W Bridgelux EB Gen3 Parallel Build: https://bit.ly/2NfoVyE
Grow Room Automation w/ Node Red: https://bit.ly/3hOm5yK
Github: https://github.com/gvbz/gardenbro
Instagram: @loudfarms_ca
dirkdiggler147
LED-Curious
LED-Curious
Reactions:
Posts: 20
Joined: Fri Jun 12, 2020 9:52 pm

@gvbz

I downloaded the repository from the git link above then added the folder hass-ruuvitag-master to the addons folder. I think you also need to restart HA

Here is my entry for it in the yaml config file:

Code: Select all

sensor:
  - platform: ruuvi
    sensors:
        - mac: '*****'
          name: 'Tent'
User avatar
gvbz
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 37
Joined: Thu Apr 02, 2020 3:30 pm

dirkdiggler147 wrote:
Thu Jul 23, 2020 3:04 pm
@gvbz

I downloaded the repository from the git link above then added the folder hass-ruuvitag-master to the addons folder. I think you also need to restart HA

Here is my entry for it in the yaml config file:

Code: Select all

sensor:
  - platform: ruuvi
    sensors:
        - mac: '*****'
          name: 'Tent'

That's where I went wrong, added to a custom_components folder as per the original instructions... Working good with the files in the addons folder, much appreciated!
480W Bridgelux EB Gen3 Parallel Build: https://bit.ly/2NfoVyE
Grow Room Automation w/ Node Red: https://bit.ly/3hOm5yK
Github: https://github.com/gvbz/gardenbro
Instagram: @loudfarms_ca
User avatar
LEDG
Site Admin
Reactions:
Posts: 1599
Joined: Sun Jun 04, 2017 8:15 pm

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 }}"
Want to Support the Site?

Use this Amazon referral link and any purchase you make within 24 hrs will earn LEDgardener a commission at no cost to you!
dirkdiggler147
LED-Curious
LED-Curious
Reactions:
Posts: 20
Joined: Fri Jun 12, 2020 9:52 pm

@LEDG

Thanks I am going to look into this, MQTT on ESP seems to open up loads of options!

Any chance this could be in part 4 on your youtube series?
User avatar
LEDG
Site Admin
Reactions:
Posts: 1599
Joined: Sun Jun 04, 2017 8:15 pm

From this point I plan on doing a whole bunch of short videos that cover specific things, and I do plan on covering this in particular.
Want to Support the Site?

Use this Amazon referral link and any purchase you make within 24 hrs will earn LEDgardener a commission at no cost to you!
Post Reply