Welcome!
This sensor deserves a proper integration to Home Assistant, which I have yet to do. When I got the device, I hacked up a short program using the library and example code from the github project listed below. It’s been running fine, so of course it’s gotten pushed back in the ‘make it better’ queue of ToDos. Perhaps this python code and the Home Assistant sensor configs below will give you some ideas.
This sensor has been running non-stop for months with no issues, the bluetooth range seems a but low, but it could be the BLE adapter on the computer I am using to collect with.
Good breathing!
Aranet4 Python client
testing on hp-600-g1-dm-01
added usb bluetooth dongle and got below running
sudo apt-get install python-pip
sudo apt-get install libglib2.0-dev
sudo pip install bluepy
sudo pip install requests
sudo pip install paho-mqtt
git clone https://github.com/Anrijs/Aranet4-Python.git
sudo pip install aranet4
Make sure that bluetoothd is running with --experimental. On systemd (sigh), try this:
sudo sed -i ‘s#/bluetoothd$#/bluetoothd --experimental#’ /lib/systemd/system/bluetooth.service
sudo systemctl daemon-reload
sudo systemctl restart bluetooth
Pair device:
Open bluetoothctl: sudo bluetoothctl
Enable passcode support: agent KeyboardOnly
Enable adapter: power on
Scan devices: scan on
When found your device, stop scan: scan off
Pair device: pair <DEVICE_ADDRESS>
Disconnect if automatically connected: disconnect <DEVICE_ADDRESS>
Exit from bluetooth ctl: exit
Device FA:70:36:DD:AB:F1 Aranet4 05A24
put this in github in useful_code
ble data access need to run as root
sudo ./aranet_mqtt_publish.py FA:70:36:DD:AB:F1 192.168.2.242 aranet
#!/usr/bin/env python3
# aranet_mqtt_publish.py
# 202111151305
#
# https://github.com/Anrijs/Aranet4-Python.git
#
# read CO2 data from ARANET4 sensor and publish to MQTT
# sudo ./aranet_mqtt_publish.py FA:70:36:DD:AB:F1 192.168.1.13 aranet
PROGRAM_NAME = "aranet_mqtt_publish"
VERSION_MAJOR = "1"
VERSION_MINOR = "2"
WORKING_DIRECTORY = ""
import sys
# check version of python
if not (sys.version_info.major == 3 and sys.version_info.minor >= 8):
print("This script requires Python 3.8 or higher!")
print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))
sys.exit(1)
#print("{} {} is using Python {}.{}.".format(PROGRAM_NAME, VERSION_MAJOR + "." + VERSION_MINOR, sys.version_info.major, sys.version_info.minor))
import paho.mqtt.publish as publish
import aranet4
import sys
import time
from datetime import datetime
import json
# reading interval
PUBLISH_INTERVAL = 30
ERROR_INTERVAL = 2
def buildMsgs(readings, topic):
return [
(topic + "time", readings["time"]),
(topic + "temperature", readings["temperature"]),
(topic + "pressure", readings["pressure"]),
(topic + "humidity", readings["humidity"]),
(topic + "co2", readings["co2"]),
(topic + "battery", readings["battery"])
]
def readArg(argv, key, default, error="Invalid value"):
if key in argv:
idx = argv.index(key) + 1
if idx >= len(argv):
print(error)
raise Exception(error)
return argv[idx]
return default
def main(argv):
if len(argv) < 3:
print("Missing device address, topic base and/or hostname.")
argv[0] = "?"
if "help" in argv or "?" in argv:
print("Usage: python publish.py DEVICE_ADDRESS HOSTNAME TOPIC_BASE [OPTIONS]")
print(" -P <port> Broker port")
print(" -u <user> Auth user name")
print(" -p <password> Auth user password")
print("")
return
device_mac = argv[0]
host = argv[1]
topic = argv[2]
port = readArg(argv, "-P", "1883")
user = readArg(argv, "-u", "")
pwd = readArg(argv, "-p", "")
auth = None
if len(user) > 0:
auth = {"username":user}
if len(pwd) > 0: auth["password"] = pwd
if (topic[-1] != "/"): topic += "/"
while True :
now = datetime.now()
nowts = int(time.time())
try :
ar4 = aranet4.Aranet4(device_mac)
current = ar4.currentReadings()
current["time"] = nowts
current["mac-address"] = device_mac
print("Publishing results : " + now.strftime("%H:%M:%S"))
print(current)
dev_topic = topic + device_mac
publish.single(dev_topic, payload=json.dumps(current), hostname=host, port=int(port), auth=auth)
# publish.multiple(buildMsgs(current, topic + device_mac + "/"), hostname=host, port=int(port), auth=auth)
print("Sleeping ....")
time.sleep( PUBLISH_INTERVAL )
except KeyboardInterrupt:
print("Program end : Keyboard Interrupt : " + PROGRAM_NAME + " Version : " + VERSION_MAJOR + "." + VERSION_MINOR)
sys.exit(0)
except :
print("Failed to connect to sensor : " + now.strftime("%H:%M:%S"))
print("Sleeping ....")
time.sleep( ERROR_INTERVAL )
if __name__== "__main__":
main(sys.argv[1:])
# aranet bluetooth low energy co2 sensors
- platform: mqtt
name: "ARANET4_01 CO2"
unique_id: "FA:70:36:DD:AB:F1-CO2"
expire_after: 3600
state_topic: "aranet/FA:70:36:DD:AB:F1"
value_template: "{{ value_json.co2 }}"
unit_of_measurement: "ppm"
json_attributes_topic: "aranet/FA:70:36:DD:AB:F1"
- platform: mqtt
name: "ARANET4_01 Temperature"
unique_id: "FA:70:36:DD:AB:F1-temperature"
expire_after: 3600
state_topic: "aranet/FA:70:36:DD:AB:F1"
value_template: "{{ value_json.temperature }}"
# unit_of_measurement: "°C"
json_attributes_topic: "aranet/FA:70:36:DD:AB:F1"
- platform: mqtt
name: "ARANET4_01 Humidity"
unique_id: "FA:70:36:DD:AB:F1-humidity"
expire_after: 3600
state_topic: "aranet/FA:70:36:DD:AB:F1"
value_template: "{{ value_json.humidity }}"
unit_of_measurement: "%"
json_attributes_topic: "aranet/FA:70:36:DD:AB:F1"
- platform: mqtt
name: "ARANET4_01 Pressure"
unique_id: "FA:70:36:DD:AB:F1-pressure"
expire_after: 3600
state_topic: "aranet/FA:70:36:DD:AB:F1"
value_template: "{{ value_json.pressure }}"
unit_of_measurement: "hPa"
json_attributes_topic: "aranet/FA:70:36:DD:AB:F1"
- platform: mqtt
name: "ARANET4_01 Battery"
unique_id: "FA:70:36:DD:AB:F1-battery"
expire_after: 3600
state_topic: "aranet/FA:70:36:DD:AB:F1"
value_template: "{{ value_json.battery }}"
unit_of_measurement: "%"
json_attributes_topic: "aranet/FA:70:36:DD:AB:F1"
# midea dehumidifiers