go-mijia
Xiaomi Mijia CLI + web app
How to read is based on this post and go-ble and it's explorer example which includes subscribing a notification.
Usage
Find your Mijia MAC address with hcitool
$ hcitool lescann
LE Scan ...
B0:52:16:BB:6F:A0 (unknown)
(...)
A4:C1:38:99:99:99 LYWSD03MMC
Then launch go-mijia
$ ./go-mijia -addr A4:C1:38:99:99:99
Scanning for 15s...
Discovering profile...
-- Subscribed notification --
Temperature: 24.57
Humidity: 67
...
If using the docker image, make sure to create the container with --net=host and --cap-add=NET_ADMIN:
$ docker run --rm --net=host --cap-add=NET_ADMIN fopina/go-mijia -addr A4:C1:38:99:99:99
Use -web to enable the http server (and -web-bind to choose the local interface and port to use). Also throw in -quiet option if you only want to use the HTTP endpoint and don't care for data in the output
$ docker run -d --rm --net=host --cap-add=NET_ADMIN fopina/go-mijia -addr A4:C1:38:99:99:99 -web -web-bind 0.0.0.0:8989 -quiet
$ curl localhost:8989
{
"temperature": 24.55,
"humidity": 67
}
Sample home-assistant sensor configuration for this endpoint (as it is my own use case):
- platform: rest
name: livingroom_mijia
resource: http://my.pi.next.to.mijia:8989/
json_attributes:
- temperature
- humidity
value_template: "OK"
- platform: template
sensors:
livingroom_temperature:
value_template: "{{ state_attr('sensor.livingroom_mijia', 'temperature') }}"
device_class: temperature
unit_of_measurement: "°C"
livingroom_humidity:
value_template: "{{ state_attr('sensor.livingroom_mijia', 'humidity') }}"
device_class: humidity
unit_of_measurement: "%"