Monitoring your home temperature – Part 1: Setting up RuuviTags and Raspberry Pi

Tech Community • 3 min read

We moved to a new house three years ago and since then, we have had issues with floor temperatures. It’s hard to maintain steady temperature for all rooms and I wanted to build a solution to keep track of it and see temperature trend for a whole week. That way, I know exactly what’s happening.

I will guide how to setup your own environment using same method.

First, you need temperature sensors and those I recommend RuuviTags. You can find detailed information at their website, but they are very handy bluetooth beacons with battery that lasts multiple years. You can measure temperature, movement, humidity and air pressure. There is a mobile app for them also, but it only shows current status, so it didn’t fit to my purpose.

So, I needed to push data to somewhere and an obvious choice was Azure. I will write more about Azure side of things in the next part of the blog. But in this part, we will setup a single RuuviTag and Raspberry Pi for sending data. You can add more RuuviTags later, like I did when everything is working as expected.

First, I recommend updating RuuviTag to the latest firmware. This page has instructions for it:

Updating firmware to latest with nRF Connect

I used an iOS app called nRF Connect for it and it went quite smoothly. You can check that your RuuviTag still works after updating with Ruuvi Station app:

iOS or Android

You will also need Raspberry Pi for sending data to the cloud. I recommend using Raspberry Zero W, because we need only WiFi and Bluetooth for this. I have mine plugged in my kitchen at the moment, but you will just need it to be range of the RuuviTags bluetooth signal (and of course WiFi).

Raspberry Pi Zero W with clear plastic case

Mine has a clear acrylic case for protection, a power supply and a memory card. Data is not saved to Raspberry memory card, so no need for bigger memory card than usual. I installed Raspbian Buster, because at time, there were issues with Azure IoT Hub Python modules with the latest Raspbian image.

Here is a page with instructions how to install a Raspbian image to an SD card:

After you have installed image, boot up your Raspberry and do basic stuff like update it, change passwords etc...

You can find how to configure your Raspberry here:

After you have done everything, you need to setup Python scripts and modules. Two modules are needed: RuuviTag (ruuvitag_sensor) and Azure IoT Hub Client (azure-iot-device). And you need MAC of your RuuviTag, you can find it with Ruuvi Station App under Settings of your RuuviTag.

Then you need to create a Python script to get that temperature data, here is my script:

import asyncio
import os
from azure.iot.device.aio import IoTHubDeviceClient
from ruuvitag_sensor.ruuvitag import RuuviTag

#Replace 'xx:xx:xx:xx:xx:xx' with your RuuviTags MAC
sensor = RuuviTag('xx:xx:xx:xx:xx:xx')
state = sensor.update()
state = str(sensor.state)

async def main():
    # Fetch the connection string from an enviornment variable
    conn_str = os.getenv("IOTHUB_DEVICE_CONNECTION_STRING")
    # Create instance of the device client using the connection string
    device_client = IoTHubDeviceClient.create_from_connection_string(conn_str)

    # Send a single message
      print("Sending message...")
      await device_client.send_message(state)
      print("Message successfully sent!")
      print("Message sent failed!")

    # finally, disconnect
    await device_client.disconnect()

if __name__ == "__main__":

Code gets current temperature from RuuviTag and sends it to Azure IoT Hub. You can see that this code needs IOTHUB_DEVICE_CONNECTION_STRING environment variable and you don’t have that yet, so we need to update it later.

You can put this code to crontab and run it like every 15min or whatever suits your needs.

Next time, we will setup Azure side…

Links: (RuuviTag firmware) (RuuviTag module) (Azure IoT module) (Raspberry Pi)

Get to know the whole project by reading the parts 2 and 3 of the series here and here.

This blog text is originally published in Senior Cloud Architect Sami Lahti's personal Tech Life blog. Follow the blog to stay up to date about Sami's writings!

Sami Lahti
Sami LahtiSenior Cloud Security Architect
Related topics

Get in Touch.

Let’s discuss how we can help with your cloud journey. Our experts are standing by to talk about your migration, modernisation, development and skills challenges.

Ilja Summala
Ilja Summala LinkedIn
Ilja’s passion and tech knowledge help customers transform how they manage infrastructure and develop apps in cloud.