RuuviBridge - Utility to bridge RuuviTag data between various sources and consumers

RuuviBridge

RuuviBridge is designed to act as a "data bridge" between various sources and consumers of data. Original design goal is to work as a drop-in replacement for RuuviCollector for users who have a Ruuvi Gateway or use ruuvi-go-gateway.

Features

Supports following sources (sources of RuuviTag data):

  • MQTT (in Ruuvi Gateway format)
  • Ruuvi Gateway by polling the /history http-api endpoint
  • HTTP POST (in Ruuvi Gateway format, the custom http server setting)

Supports following sinks (things that use the data):

  • InfluxDB 1.8 and 2.x
  • Prometheus
  • MQTT (including Home Assistant MQTT discovery for automatic configuration)

Supports following RuuviTag Data Formats:

  • Data Format 3: "RAW v1" BLE Manufacturer specific data, all current sensor readings
  • Data Format 5: "RAW v2" BLE Manufacturer specific data, all current sensor readings + extra

Supports following data from the tag (depending on tag firmware):

  • Temperature (Celsius)
  • Relative humidity (0-100%)
  • Air pressure (Pascal)
  • Acceleration for X, Y and Z axes (g)
  • Battery voltage (Volts)
  • TX power (dBm)
  • RSSI (Signal strength at the receiver, dBm)
  • Movement counter (Running counter incremented each time a motion detection interrupt is received)
  • Measurement sequence number (Running counter incremented each time a new measurement is taken on the tag)

Ability to calculate following values in addition to the raw data (the accuracy of these values are approximations):

  • Total acceleration (g)
  • Absolute humidity (g/m³)
  • Dew point (Celsius)
  • Equilibrium vapor pressure (Pascal)
  • Air density (Accounts for humidity in the air, kg/m³)
  • Acceleration angle from X, Y and Z axes (Degrees)

Configuration

Check config.sample.yml for a sample config. By default the bridge assumes to find a file called config.yml in the current working directory, but that can be overridden with -config /path/to/config.yml command line flag.

By default RuuviBridge parses the config in a flexible way, ignoring all unknown fields. This can be changed with -strict-config command line flag, which will make RuuviBridge throw errors if there are unknown entries in the config. Do note that this only validates whether the config has a valid structure with right keys (ie. no typos in the keys), it does not validate whether the config makes sense as such.

Installation

Recommended method is using Docker with the prebuilt dockerimage: ghcr.io/scrin/ruuvibridge for which you can use the provided composefile

Without docker you can download prebuilt binaries from the releases page. For production use it's recommended to set up as a service.

Home Assistant MQTT discovery

Home Assistant allows automatic configuration of MQTT entities using MQTT Discovery. To enable RuuviBridge to automatically configure all of your RuuviTags to Home Assistant for you, all you need to do (assuming default configuration) is to set homeassistant_discovery_prefix in the config under mqtt_publisher. In default Home Assistant configuration this should be simply homeassistant.

After setting this configuration, it should be a matter of seconds before your RuuviTags should appear as devices in Home Assistant for reporting all available measurements, with properly set names, units, icons and other attributes.

Owner
Comments
  • No data in Influxdb

    No data in Influxdb

    I'm trying to save data from Ruuvi Gateway MQTT to InfluxDB, but I see no data saved.

    $ ./ruuvibridge
    [2022-7-4 22:55:59] [info] RuuviBridge starting up, version: v0.1.14
    [2022-7-4 22:55:59] [info] Starting data sources
    [2022-7-4 22:55:59] [info] Starting MQTT subscriber, mqtt_subscription: ruuvi/+, target: tcp://localhost:1883, topic_prefix: ruuvi
    [2022-7-4 22:55:59] [info] Starting data sinks
    [2022-7-4 22:55:59] [info] Starting InfluxDB sink, target: http://127.0.0.1:8086, bucket: ruuvi, measurement_name: ruuvi_measurements, minimum_interval: 0s
    [2022-7-4 22:55:59] [info] Starting MQTT sink, topic_prefix: ruuvitag, minimum_interval: 5s, target: tcp://localhost:1883
    [2022-7-4 22:55:59] [info] Starting processing
    
    $ cat config.yml
    # Easiest option: let RuuviBridge poll the gateway for measurements
    gateway_polling:
      # Flag to enable or disable gateway polling
      enabled: false
      gateway_url: http://ip.or.hostname.of.the.gateway
      interval: 10s
    
    # Recommended option: Have the gateway send the measurements to a MQTT server and let RuuviBridge subscribe to updates in real time
    mqtt_listener:
      # Flag to enable or disable subscribing to a topic on a MQTT server
      enabled: true
      # MQTT broker url, including scheme (tcp, ssl or ws), hostname or IP address, and port
      broker_url: tcp://localhost:1883
      # Client ID, required for persistent sessions and has to be unique on the MQTT server
      client_id: RuuviBridgeListener
      username: <obfuscated>
      password: <obfuscated>
      # Topic prefix to subscribe to, expecting RuuviTag measurements to be published as <topic_prefix>/<mac>
      # You can use + character as a single-level wildcard, for example if you have the gateway mac address in the topic
      # for example: ruuvi/+ as the topic prefix would match the topic ruuvi/<gateway_mac>/<tag_mac>
      topic_prefix: ruuvi
    
    # Third option: Configure Ruuvi Gateway to send measurements here via the custom http server setting
    http_listener:
      # Flag to enable or disable the http listener
      enabled: false
      # Port to listen on. Cannot be the same as prometheus listen port if enabled
      port: 8080
    
    # Extra processing of the values
    processing:
      # Extended values are enabled by default but can be disabled by changing extended_values to false
      extended_values: true
      # Filter which tags are considered. Valid options:
      # none - no filtering is done, all tags are processed (default)
      # named - only tags which have a name configured will be processed
      # allowlist - only mac addresses listed in filter_list will be processed
      # denylist - mac addresses listed in filter_list will be skipped
      filter_mode: none
      # List of mac addresses to allow or deny if filter_mode is either allowlist or denylist
      filter_list:
        - FFEEDDCCBBAA
        - F0E1D2C3B4A5
    
    # Supports both InfluxDB 1.8 and 2.x
    influxdb_publisher:
      # Flag to enable or disable publishing the processed data to InfluxDB
      enabled: true
      # Minimum interval for measurements to publish per tag. InfluxDB handles frequent updates very efficiently due to delta compression so the default is no limit
      minimum_interval: 0s
      # URL for InfluxDB, including scheme, hostname and port
      url: http://127.0.0.1:8086
      # For InfluxDB 1.8 the auth_token is username and password in format "username:password"
      auth_token: <obfuscated>:<obfuscated>
      # This is ignored for InfluxDB 1.8
      org: ""
      # For InfluxDB 1.8 the bucket is the database name, with optional retention policy in format "database/retentionpolicy"
      bucket: ruuvi
      # Measurement name to use
      measurement: ruuvi_measurements
      # Uncomment to add additional tags to a series
      #additional_tags:
      #  mytag: myvalue
      #  myothertag: myothervalue
    
    # Prometheus exporter for data
    prometheus:
      # Flag to enable or disable exporting the measurements and RuuviBridge diagnostics in prometheus exposition format
      enabled: false
      # Port to listen on. Cannot be the same as http listener port if enabled
      port: 8081
    
    # Publish the parsed and processed data back to MQTT. Can be the same server or a different one.
    mqtt_publisher:
      # Flag to enable or disable publishing the processed data to a MQTT server
      enabled: true
      # Minimum interval for measurements to publish per tag. Accepts values in go duration format ( https://pkg.go.dev/time#ParseDuration ), for example 1m30s
      minimum_interval: 5s
      # MQTT broker url, including scheme (tcp, ssl or ws), hostname or IP address, and port
      broker_url: tcp://localhost:1883
      # Client ID, required for persistent sessions and has to be unique on the MQTT server
      client_id: RuuviBridgePublisher
      username: <obfuscated>
      password: <obfuscated>
      # Topic prefix where to publish, in format <topic_prefix>/<mac>
      # If you use the same server for a source, be sure to use a different topic prefix to avoid conflicts!
      topic_prefix: ruuvitag
      # Uncomment to enable creating Home Assistant MQTT discovery topics
      #homeassistant_discovery_prefix: homeassistant
    
    # Optional names for the tags with the key being the mac address and value being the desired name
    tag_names:
      <obfuscated>: Makuuhuone
      <obfuscated>: Parveke
      <obfuscated>: Sauna
      <obfuscated>: Olohuone
    
    # Logging options for RuuviBridge itself
    logging:
      # Type can be either "structured", "json" or "simple"
      type: simple
      # Valid logging levels from most verbose to least verbose: trace, debug, info, warn, error, fatal, panic
      level: info
      # Include timestamp in the log line. Can be useful to turn off with certain logging systems which add their own timestamps
      timestamps: true
      # Whether to include the log caller in the logs. This will increase the size of logs but it helps in troubleshooting in some cases
      with_caller: false
    
    # Enable or disable debug mode. This will print all received measurements to the console among other debuggy things, useful for development, testing and troubleshooting purposes.
    debug: false
    
    $ influx -username <obfuscated> -password <obfuscated>
    Connected to http://localhost:8086 version 1.8.10
    InfluxDB shell version: 1.8.10
    > use ruuvi
    Using database ruuvi
    > SELECT * FROM ruuvi_measurements
    >
    

    Data is shown when running:

    mosquitto_sub -u <obfuscated> -P <obfuscated> -h 127.0.0.1 -p 1883 -t 'ruuvi/<obfuscated>/<obfuscated>'
    

    Any tips?

  • Update mqtt_homeassistant.go

    Update mqtt_homeassistant.go

    Temperature related UnitOfMeasurement i.e. degree character seems to be coded as (U+00BA). I think correct one is (U+00B0). Using (U+00BA) as s degree character looked weird in Home Assistant:

    image

    ..and it was not possible to move the sensor to Homekit without customizing the entity.

  • feat: Add Home Assistant state_class for long term statistics

    feat: Add Home Assistant state_class for long term statistics

    Hi, this adds state_class of type measurement to Home Assistant MQTT to allow using Long Term Statistics:

    • https://www.home-assistant.io/blog/2021/08/04/release-20218/#long-term-statistics
    • https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics
  • Movement Counter to Home Assistant?

    Movement Counter to Home Assistant?

    Great bridge to transfer data to Home Assistant. Thanks! However, one question. RuuviBridge decodes data from my RuuviTag like this:

    {
        "name": "Postilaatikko",
        "mac": "xx:x...",
        "timestamp": 1650901857,
        "data_format": 5,
        "temperature": 6.875,
        "humidity": 42.0975,
        "pressure": 100399,
        "accelerationX": -0.192,
        "accelerationY": -1.076,
        "accelerationZ": -0.076,
        "batteryVoltage": 3.016,
        "txPower": 4,
        "rssi": -84,
        "movementCounter": 114,
        "measurementSequenceNumber": 6553
    }
    

    But I can not find ruuvitag_MAC_movementCounter MQTT topic under homeassistant/sensor and probably for that reason I can find only these sensors in my Home Assistant:

    image

    I'd like to see the Movement counter data in Home Assistant. Is this a missing feature or something else maybe?

  • Configure additional tags per series in influxdb

    Configure additional tags per series in influxdb

    This allows to add arbitrary tags per series. I use that to add more information about the data, like the location the ruuvi tags are located which this instance of the ruuvibridge processes.

  • Gateway polling gives cryptic error message when no API key is provided

    Gateway polling gives cryptic error message when no API key is provided

    Hi, first of all thanks for the great program. My goal is to have my ruuvi gateway (firmware v1.12.4) collect the data from my 6 ruuvi pro sensors (firmware v.3.31.1) and send it to my local server, where I can display it with Grafana.

    I was following the tutorial from ruuvi to set-up an installation for receiving the data, https://ruuvi.com/connecting-ruuvi-gateway-to-a-private-server/ but it failed at the glue logic.

    Afterwards, I found your program which seems to be just the right fit. Unfortunately, neither of the 3 offered methods (to receive data from the gateway) seem to work at first.

    1. My first try with RuuviBridge was polling the data from the gateway. I can access the gateway in the local network, and had it fully set-up

    Ruuvi Gateway’s IP address: 192.168.1.144 Subnet mask: 255.255.255.0 Gateway: 192.168.1.1 DHCP server: 192.168.1.1

    and can see the history under http://192.168.1.144/history history.json.txt

    root@debianvm:/home/tim/ruuvi_bridge# docker-compose up
    Starting ruuvibridge ... done
    Attaching to ruuvibridge
    ruuvibridge    | [2022-10-29 10:14:56] [info] RuuviBridge starting up, version: git-01695bace9705e53f52735e6e15640f39125ce9c
    ruuvibridge    | [2022-10-29 10:14:56] [info] Starting data sources
    ruuvibridge    | [2022-10-29 10:14:56] [info] Starting gateway polling, target: http://192.168.1.144, interval: 10s
    ruuvibridge    | [2022-10-29 10:14:56] [info] Starting data sinks
    ruuvibridge    | [2022-10-29 10:14:56] [info] Starting InfluxDB sink, minimum_interval: 0s, target: http://192.168.1.69:8086, bucket: ruuvi, measurement_name: ruuvi_measurements
    ruuvibridge    | [2022-10-29 10:14:56] [info] Starting processing
    ruuvibridge    | [2022-10-29 10:14:56] [error] Failed to get history from gateway, target: http://192.168.1.144, interval: 10s, error: Get "http://192.168.1.144/history": net/http: HTTP/1.x transport connection broken: unexpected EOF
    

    Mosquitto also had problems (I guess this is a problem from Docker and how to forward ports, I don't have experience with Docker) and the third HTTP method stayed silent and never received data. So I went back to the first method, where RuuviBridge is polling the data.

    Going back to the first HTTP/1.x error, I though that the data format from ruuvi maybe changed (since I had no problem to download the history data on the browser). It turns outs, that during setup of the Ruuvi gateway it should be not optional to take the API key, but is absolutely necessary to copy it and place it in the config.yml of RuuviBridge. Maybe I missed it in the description, but it would be great if you can add to the comment that it is necessary to add the API key.

  • Distinguish between multiple Gateways

    Distinguish between multiple Gateways

    Currently, there is no way to distinguish between multiple gateways, rather than running multiple instances of RuuviBridge (what I currently do and works). I'd like to suggest teaching RuuviBridge to distinguish between multiple Gateways.

    An example could be:

    influxdb_publisher:
      [...]
      additional_tags:
        location: $gateway_name
    
    gateway_names:
      XXXXXXXXXXX: LocationA
      YYYYYYYYYYY: LocationB
    

    (That's just a partial config to show the idea)

    This approach would make it mandatory to configure the Gateways to publish to a predefined format:

    mytopic/$GW_MAC/$TAG_MAC
    

    We could also find a way to make the topic format configurable, if desired.

    What do you think about this idea? I'm open to refine it if needed.

Related tags
Bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API
Bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)

Jan 4, 2023
A REST API for the DN42 registry, written in Go, to provide a bridge between interactive applications and the registry.

dn42regsrv A REST API for the DN42 registry, written in Go, to provide a bridge between interactive applications and registry data. A public instance

Apr 21, 2022
Grpc bridge to various mediabank related systems

Mediabank bridge This internal tool enables authenticated gRPC based endpoint for securely communicating with systems like: Telestream Vantage Workflo

Jan 7, 2022
Bridge REMOV will allow you to safely transfer NFT from RMRK to MOVR and backwards

remov Inspiration Our aim is to expand the capabilities of blockchain and make a secure way for transferring NFT between RMRK and MOVR blockchain. The

Dec 5, 2021
Sonarcon - Uses the SonarQube API to interact and extract sources from public instances

Sonarcon Uses the SonarQube API to interact and extract sources from public inst

Feb 17, 2022
A Matrix-iMessage puppeting bridge

A Matrix-iMessage puppeting bridge. The bridge runs on a Mac or jailbroken iPhone (soon™). A websocket proxy is required to receive appservice events from the homeserver.

Jan 2, 2023
vks is a Vulkan bridge for Go.

vks vks is a Vulkan bridge for Go. The header generator folder contains the code that is used to generate the vulkan bindings. It woks similar to c-fo

Sep 3, 2022
An inline buildpack for deploying a mattermost-irc bridge

Matterbridge-Heroku An inline buildpack for hosting Matterbridge on Heroku. Heroku is a platform for easily deploying applications. A buildpack provid

Nov 26, 2022
Bridge facebook messenger with any service supported by matterbridge

fbridge fbridge bridges facebook messenger with any service supported by matterbridge trough the API interface. fbridge is using fbchat to connect to

Oct 30, 2022
Facebook bridge used with matterbridge

fbridge-asyncio This repo is a fork of fbridge. If you log in to your facebook account from a browser, after you do, it's a good idea to restart fbrid

Aug 7, 2022
Celestia -> EVM bridge

Peggo Peggo is a Go implementation of the Peggy (Gravity Bridge) Orchestrator originally implemented by Injective Labs. Peggo itself is a fork of the

Dec 12, 2022
The official repository of the Gravity Bridge Blockchain

Gravity bridge is Cosmos <-> Ethereum bridge designed to run on the Cosmos SDK blockchains like the Cosmos Hub focused on maximum design simplicity an

Dec 27, 2022
A bridge from the Stellar network to other blockchains
A bridge from the Stellar network to other blockchains

Creating equitable access to the global financial system Starbridge Starbridge is software that facilitates bridge builders who are connecting the Ste

Dec 9, 2022
🧙 High-performance PHP-to-Golang IPC/RPC bridge

High-performance PHP-to-Golang IPC bridge Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/r

Dec 28, 2022
Capdns is a network capture utility designed specifically for DNS traffic. This utility is based on tcpdump.
Capdns is a network capture utility designed specifically for DNS traffic. This utility is based on tcpdump.

Capdns is a network capture utility designed specifically for DNS traffic. This utility is based on tcpdump. Some of its features include: Unde

Feb 26, 2022
Subfinder is a subdomain discovery tool that discovers valid subdomains for websites by using passive online sources
Subfinder is a subdomain discovery tool that discovers valid subdomains for websites by using passive online sources

Subfinder is a subdomain discovery tool that discovers valid subdomains for websites. Designed as a passive framework to be useful for bug bounties and safe for penetration testing.

Jan 1, 2023
Simple Relay between a Unix socket and a TCP socket, and vice versa.
Simple Relay between a Unix socket and a TCP socket, and vice versa.

Simple TCP <-> Unix Relay simpletcpunixrelay is a program which exposes a TCP endpoint as a Unix socket and vice versa. Usecase Let's say you are runn

Nov 23, 2022
Our aim is to expand the capabilities of blockchain and make a secure way for transferring NFT between RMRK and MOVR blockchain.

remov Inspiration Our aim is to expand the capabilities of blockchain and make a secure way for transferring NFT between RMRK and MOVR blockchain. The

Jul 25, 2022
Web app utility to get server list data from Minecraft servers.

Ping Web app utility to get server list data from Minecraft servers. Avalible at https://ping.turtley12.dev/app, Running yourself Before compiling and

Dec 21, 2021