Successfully Integrating Wemos D1 Mini with Tasmota and OpenHAB

I recently embarked on a project to integrate a Wemos D1 Mini with Tasmota firmware into my OpenHAB setup, and I wanted to share my experience in case it can inspire or assist others. My goal was to monitor wind direction using a Sparkfun Weather Meter, and while I initially tried using Arduino, it proved cumbersome due to the need for two cables (power and LAN). After some research, I realized that the Wemos D1 Mini with Tasmota would be a more streamlined solution.

The physical setup was straightforward: connecting the A0 pin to the sensor with a 10K resistor to 3.3V and grounding the other pin. With Tasmota, I utilized the sensors.bin firmware, which was essential for accessing the A0 pin. My OpenHAB setup already had an MQTT broker running, so I configured an item to capture the raw wind direction value from Tasmota:

Number sensorwind_WindDirRAW “Wind Dir RAW [%s]” { mqtt=“<[mqtt:sonoff/tele/sensorwind/SENSOR:state:JSONPATH($.ANALOG.A0)]” }

However, translating this raw value into meaningful wind direction letters was a bit of a puzzle. After some experimentation, I discovered that using a scale transformation in OpenHAB was the key. Here’s how I set it up:

Number WindDirection “Wind as letter [SCALE(analogtowinddir.scale):%s]” { mqtt=“<[mqtt:sonoff/tele/sensorwind/SENSOR:state:JSONPATH($.ANALOG.A0)]” }

I then created a scale file to map the analog values to wind directions:

[0…135]=E
[135…227]=SE
[227…360]=S
[360…521]=NE
[521…672]=SW
[672…792]=N
[792…865]=NW
[865…1020]=W

This setup has been working perfectly for me, though I acknowledge that the analog voltage readings aren’t always precise. Nonetheless, it fulfills my needs effectively. If anyone is looking to refine the scale further, they could adjust the ranges or add a fallback like “DirectionUnknown” for values outside the defined ranges.

I hope this分享 can help others looking to integrate similar sensors into their OpenHAB setups. It was a rewarding project, and I’m excited to see how others might build upon this idea!