Add a humidity sensor Sonoff to Homebridge using Tasmota and MQTT

4 minutes of reading
Guide purposes
CONCEPTS FACED:
  • Software installation and configuration
SOFTWARE COMPONENTS USED:
Prerequisites
PHYSICAL DEVICES USED:
PROJET MOST INDICATED FOR ::

Apple-200x200

Notes and disclaimer
  • qualsiasi modifica all'impianto elettrico dev'essere progettata ed effettuata da personale qualificato;
  • any changes implemented in probefore is a propersonal responsibility as well as a profirst risk and danger (the contents of the present page are purely educational);
  • any changes implemented in proprior to a device it voids the guarantee, quality approvals and certifications.
Driving review: 1.1

Sonoff TH-16 TH-10 and sensors

Abstract

"homebridge-mqtt-humidity-tasmota”Is a plugin developed by the excellent MacWyznawca in order to quickly and easily survey them the relative humidity of a certain environment using sensors ITEAD Sonoff TH-16 or TH-10 that they have been preventively and timelynameupdated to firmware Sonoff-Tasmota.

The latter assumption relative to the higher onenameof the firmware it is a must because, as we know, the original firmware does not allow to interrogate the sensor in a way direct, but only through theappeWeLink communication, conceived appSpecially from productor to interface with the whole family of products ITEAD Sonoff Smart Home. Firmware adoption Sonoff-TasmotaInstead, enables the user to use the topics MQTT in order to directly survey the readings taken.

This plugin is designed expressly to extract from the topic MQTT prolearned from a Sonoff TH-16 / TH-10 with firmware Sonoff-Tasmota. Actually they could be used also other plugins - always able to read these telemetries - but the advantage of adopting this specific plugin is its predisposition in extracting the numeric data from the telemetric topic without the need for the user to configure manually a parsing string ad hoc.

Side configuration Sonoff

Before going into the plugin configuration it is necessary to set up the actuator / sensor Sonoff so that measure the humidity cyclically and send it to the broker MQTT, so anyone who is registered (in listen) to that topic (in our case, our plugin and therefore our home automation).

Nb. If you are not familiar with MQTT, we recommend reading this our page, it is much easier to understand than you think.

So let's connect to the Sonof in question using its web interface. What we will use in this guide will be a Sonoff TH-16 equipped with sensor AM2301.
Once connected, click on "Configuration" and then "Configure Module"

The screen that appears will allow us to select the "Module Type" (to select "Sonoff TH ”) and indicate, on the connector GPIO14, which type of sensor is in use, in this case the AM2301.

Sonoff-Tasmota Module Configuration - Sensor-AM2301

Once this configuration is set, click on Save and, after restarting the device, return to the main menu.
As you will notice, at the head of the home will be appburned temperature and humidity readings:

Sonoff-Tasmota TH-16 TH-10 Temperature and Humidity - RES1

As noted, the resolution of the data temperature and humidity is a tenth of a degree and a percentage.
This is an important aspect that we will take care of in proI follow the guide.

Plugin installation

Pronow we are going to install the plugin. As with all plugins it is very simple.

Run the following command - on unix-based systems (linux, Raspberry etc.) from the terminal, from systems windows su procommand mpt:

npm install -g homebridge-mqtt-humidity-tasmota

and wait for the end of proprocedure.
Nb. In case Homebridge is already running as a service (as described in our installation guides), prosee to interrupt it before installing using the command:

sudo systemctl stop homebridge

Configuration at Homebridge

The plugin configuration includes the addition to the Home configuration filebridge of one or more accessories configured as follows:

"accessories": [
  {
    "accessory": "mqtt-humidity-tasmota",
    "name": "Umidità",
    "url": "mqtt://127.0.0.1",
    "username": "xxx",
    "password": "xxx",
    "topic": "tele/Sonoff/SENSOR",
    "startCmd": "cmnd/Sonoff/TelePeriod",
    "startParameter": "120",
    "sensorPropertyName": "AM2301",
    "manufacturer": "ITEAD",
    "model": "Sonoff TH-16",
  }
]

Explanation of the fields.

FieldDescription
accessoryRequired - Must necessarily be “mqtt-humidity-tasmota"(All tiny).
nameRequired - Name of the accessory
urlRequired - MQTT broker address. In this case the local address is indicatedhost as this role resides on the same computer that hosts Homebridge
usernameOptional - The username to log into the MQTT broker, if configured.
passwordOptional - The user password to access the MQTT broker, if configured.
topicRequired - The telemetric topic from which to draw information on humidity
startCmdOptional - Command to be sent when Home is startedbridge (the one shown in the example indicates al Sonoff to send a reading every few seconds, defined in the parameter “StartParameter")
StartParameter
Optional - Parameter sent with the command set in the field "startCmd"
sensorPropertyNameOptional - A descriptive string of the sensor
manufactorer
Optional - A descriptive string of the proconductor
modelOptional - A descriptive string of the model Sonoff in use

utilization

Starting Homebridge, the accessory that apparirà will appear as follows:

This slideshow requires JavaScript.

Rounding of the humidity value

Unfortunately, at the date of preparation of this guide, the plugin presents a stupid but significant defect: the relative humidity data - which starting from iOS 12 would be available in decimal format - is passed from the plugin toapp "Home" in decimal format. Not bad, not that the data is not, from the plugin, not even rounded, but simply passed in decimal part. In the presence of a value, for example, equal to "30,9%", on iOS "Home" is displayed "30%", when it would be more correct at this point "31%".

At this point we can use a command Tasmota to make it the firmware of the Sonoff (and not the plugin - that anyway it does not do it) to round off correctly, at the source, the data.

In the console input hole Tasmota to insert:

cmnd/Sonoff/HumRes 1

and press enter (obviously "Sonoff"Is the friendy name of the example device. If you have modified it, modify the command accordingly.

At this point returning to the home page you will notice how the resolution of the data has been changed:

Sonoff-Tasmota-TH-16 TH-10 Temperature and Humidity - Um RES0

From here on, even "Casa" will display a correct figure.

Update Searchnamento

To update the package is sufficient execute the following command:

sudo npm update -g -dev homebridge-mqtt-humidityt-tasmota

having previously taken care of having stopped any Home executionsbridge in progress.


ITEAD Sonoff BasicATTENZIONE: remember that there is on our FORUM community an ad hoc section dedicated to Sonoff (and more generally to devices ESP8266), for any doubt, question, information on the specific merit of these components.

Please comment below