tony-fav / tasmota-blerry

GNU General Public License v3.0
95 stars 29 forks source link

BLErry v0.2.5-dev - A BLE Gateway inside Tasmota32 using Berry

Here's an intro video by @digiblur to get an idea of the how and why! HOWEVER, setup has changed, gotten simpler, since this video, see below. Make sure to check out the discussions below.

Contribute in Dev Branch

Feature Requests

Device Suggestions

ESP32 Lock-Up/Reboot Issues

video thumbnail

Setup

Compatible ESP32

First, you must flash your ESP32 (or ESP32-C3 or ESP32-Solo1) with a Tasmota build with BLE and Berry. These are available from the Tasmota Web Installer. The binaries are available here: ESP32 Release, ESP32 Dev, ESP32-C3 Dev Only, and ESP32-Solo1 Dev Only. Additionally, this repo may from time to time host compiled Tasmota binaries that are confirmed to be stable for this project, provided there is any instability in the dev releases.

Automated Setup

Provided your Tasmota32 device has internet access, BLErry can be installed automatically by running the following (blerry_setup_script.be) in the Berry Scripting Console (http://your.tas.device.ip/bc?)

import path
def start_blerry_setup()
  var cl = webclient()
  var url = 'https://raw.githubusercontent.com/tony-fav/tasmota-blerry/dev/blerry/blerry_setup.be'
  cl.begin(url)
  var r = cl.GET()
  if r != 200
    print('error getting blerry_setup.be')
    return false
  end
  var s = cl.get_string()
  cl.close()
  var f = open('blerry_setup.be', 'w')
  f.write(s)
  f.close()
  load('blerry_setup.be')
end
start_blerry_setup()

This script will download a larger setup script and run it which downloads blerry.be, sets up a blank blerry_config.json if one does not already exist, sets up and enables a Rule to launch BLErry on Tasmota boot if one does not already exist, and restarts the ESP.

If the script did not seem to work the first time. Run it again! There is some instability in downloading files to the ESP.

Alternately, this setup script can be executed as a Tasmota command:

br import path; def start_blerry_setup(); var cl = webclient(); var url = 'https://raw.githubusercontent.com/tony-fav/tasmota-blerry/dev/blerry/blerry_setup.be'; cl.begin(url); var r = cl.GET(); if r != 200; print('error getting blerry_setup.be'); return false; end; var s = cl.get_string(); cl.close(); var f = open('blerry_setup.be', 'w'); f.write(s); f.close(); load('blerry_setup.be'); end; start_blerry_setup()

IF AFTER INSTALLATION, BLERRY DOES NOT APPEAR TO BE WORKING, AND TASMOTA COMMANDS ARE UNKNOWN, PLEASE FOLLOW THE MANUAL SETUP GUIDE BELOW. The automatic installation can fail leaving a blerry.be of size 0 on the filesystem.

Tasmota Commands

There are several available Tasmota commands which can be used to setup devices or get information about the current setup.

The list of commands is below

BlerrySetDevice <JSON of a single device>
BlerryGetDevice <mac of a single device>
BlerryDelDevice <mac of a single device>
BlerrySetConfig <Complete JSON>
BlerryGetConfig
BlerryDelConfig
BlerryConfigURL <URL of blerry_config.json>

For example,

BlerrySetDevice {"E33281034C99":{"alias":"dev_GVH5074","model":"GVH5074"}}

would add this device (if it did not exist) to the configuration or edit the device to have this configuration if it did not previously. The rest of the configuration would remain intact. After this command, for changes to take effect, the Tasmota device should be restarted.

BlerryDelDevice E33281034C99

would delete the device configuration with mac address E33281034C99 leaving the remaining configuration intact.

BlerryConfigURL https://raw.githubusercontent.com/username/blerry/main/blerry_config.json

would rewrite the entire configuration file to be the file from the provided URL. This will auto update at every boot.

BlerrySetConfig {"devices":{"E33281034C99":{"alias":"dev_GVH5074","model":"GVH5074"}}}

would rewrite the entire configuration file to be the provided JSON.

These commands work like regular Tasmota commands, available through the console, serial, MQTT, HTTP request, etc.

Alternate to System#Boot Rule

If you would like a fully berry solution to loading BLErry. Add the following line to autoexec.be

tasmota.add_rule('System#Boot', / -> tasmota.set_timer(10000, / -> load('blerry.be')))

This works similar to the rule but with a 10s. This delay seems to be required for BLErry to load properly. This is likely due to slight timing differences between Berry's rule processing and Tasmota's rule processing. This delay is also useful if you are running something like Tasmota Device Manager which also asks the ESP32 to do quite a lot at system boot.

Manual Setup

Next, to use:

Final Setup (required for both automated and manual)

If you use HA discovery, devices should appear under MQTT Devices NOT the Tasmota integration.

Configuration JSON

As most folks in the home automation world are incredibly familiar with yaml, I suggest writing your configuration in yaml then converting it to JSON with https://www.json2yaml.com/

An example minimum configuration for 1 sensor is shown below in yaml

devices:
  A4C138FFFFFF:
    alias: example_ATCpvvx
    model: ATCpvvx

This becomes blerry_config.json when converted

{
  "devices": {
    "A4C138FFFFFF": {
      "alias": "example_ATCpvvx",
      "model": "ATCpvvx"
    }
  }
}

Adding a second device is just as simple

devices:
  A4C138AAAAAA:
    alias: example_ATCpvvx
    model: ATCpvvx
  E33281BBBBBB:
    alias: another_sensor
    model: GVH5074

Again, you would convert this to json and save as blerry_config.json

If you would like to use the same configuration across multiple ESP32 devices, you can use the same config file but ignore specific sensors.

devices:
  A4C138AAAAAA:
    alias: example_ATCpvvx
    model: ATCpvvx
  E33281BBBBBB:
    alias: another_sensor
    model: GVH5074
    ignore: true

Other settings can be added which override the default behavior and configured behavior for each device

devices:
  A4C138AAAAAA:
    alias: example_ATCpvvx
    model: ATCpvvx
    sensor_retain: true
    precision:
      Temperature: 1
      Humidity: 0
      DewPoint: 1
  E33281BBBBBB:
    name: Living Room Sensor # friendly name shown in Home Assistant etc, if not set alias is used (ie use the alias as the name)
    alias: blerry_BBBBBB # used for BLE alias and mqtt topic
    model: GVH5074
    via_pubs: true
    publish_attributes: true
    calibration:
      Temperature: [ 1 ]
      Humidity: [ 0, 1.1 ]

Similarly, an override section can be defined which overrides the settings of every sensor (even if you specific individual settings for that sensor).

devices:
  A4C138AAAAAA:
    alias: example_ATCpvvx
    model: ATCpvvx
    sensor_retain: true
    precision:
      Temperature: 1
      Humidity: 0
      DewPoint: 1
  E33281BBBBBB:
    alias: another_sensor
    model: GVH5074
    via_pubs: true
    publish_attributes: true
    calibration:
      Temperature: [ 1 ]
      Humidity: [ 0, 1.1 ]
override:
  base_topic: tele/tasmota_blerry2
  discovery: true
  precision:
    Battery: -1

For devices like scales that timeout and turn off when not in use or thermometers that have low digit precision and might not update often, the discovery of those specific sensors should be overriden to have a longer exp_aft time (default is 10 minutes = 600 seconds). The example below uses the discovery_override option to change the expire after time to 36 hours and change the state class to a measurement.

devices:
  5CCAD3XXXXXX:
    model: MyScale
    alias: MiScale2
    discovery_override:
      Weight:
        stat_cla: measurement
        exp_aft: 129600
      Impedance:
        stat_cla: measurement
        exp_aft: 129600

Final reminder, you must convert this yaml to json and save a blerry_config.json to use it.

Troubleshooting

Supported Devices in BLErry v0.2.5-dev

Please discuss any devices you would like supported here as well as if you are working on supporting any device!

Sensors

Driver Name Mac Example Description
"ATCpvvx" "A4C138XXXXXX" Xiaomi sensors on ATC or pvvx firmware with "ATC1441" or "Custom" advertisement.
"GVH5074" "E33281XXXXXX" Govee H5074. Need H5051 packets to add support to this driver.
"GVH5075" "A4C138XXXXXX" Govee H5072, H5075, H5101, and H5102.
"GVH5182" "C33130XXXXXX/1" Govee H5182 two probe meat thermometer with display. Thanks carlthehaitian!
"GVH5183" "A4C138XXXXXX" Govee H5183 single probe meat thermometer.
"GVH5184" "D03232XXXXXX/1" Govee H5184 four probe meat thermometer with display. Thanks ElksInNC!
"iBBQ6" "F83002XXXXXX" Inkbird IBT-6XS and potentially other 6 probe iBBQ devices
"IBSTH2" "494208XXXXXX" Inkbird IBSTH1 & IBSTH2 with and without humidity.
"ThermoPro_TP59" "487E48XXXXXX" ThermoPro TP59/TP357.
"WoContact" "D4BD28XXXXXX/1" Switchbot contact sensor (also has motion, binary lux, and a button).
"WoPresence" "FC7CADXXXXXX/1" Switchbot motion sensor (also has binary lux).
"WoSensorTH" "D4E4A3XXXXXX/1" Switchbot temperature and humidity sensor (regular and plus).
"BTHome" "AABBCCDDEEFF" BTHome format. Currently supports thermometer like readings Can be expanded to more sensors
"Xiaomi" "AABBCCDDEEFF" ATC/PVVX sensor on Mi-Like Advertising, Xiaomi LYWSDCGQ, Mi-Flora. Can be expanded to more sensors
"MiScale2" "AABBCCDDEEFF" Xiaomi Mi Scale 2 See configuration section for configuration recommendation
"EufyC1" "AABBCCDDEEFF" Anker eufy C1 Scale See configuration section for configuration recommendation
"dev" "AABBCCDDEEFF" A driver for easy development that prints out received raw data.
-- POLLED DEVICES -- Devices which require a BLEOp command to receive a Notification with data.
WP6003 "600303AABBCC" WP6003 Air Box.

Development Status

I have the following devices that I am seeking to support which all require some control:

Contributing

Feel free to fork and PR any new drivers, better code, etc.!

I have added a document with some of the process for supporting the Govee H5183 in v0.1.x. The implementation has changed drastically (to be easier) in v0.2.x.

Drivers to Reference

If you like my project

Buy Me A Coffee