Believe it or not, there are other useful devices in the world beside the Sonoff.  I know, I was shocked too. As far as Arduino compatible, wifi devices go, the two most common are probably the D1 mini and the NodeMCU board.  In this video I’ll show you some of the useful things you can do with these boards like adding a temperature and humidity sensor, a motion detector and controlling RGB LEDs, using Tasmota and Home Assistant.  Cuz that’s what I do.

The brains inside these boards is the same as the Sonoff devices.  It’s this ESP8266 chip. The big difference between the D1 mini and the Sonoff is the number of available pins.  The Sonoff Basic has 3 pins that are easily accessible. The D1 mini on the other hand has 11. So that means you can connect a bunch of input devices (like sensors) and output devices (like relays and lights).  I’ve used the D1 mini for my Holiday LEDs, and for my first smart garage door opener. It runs Arduino sketches, no problem. But I’m not a trained Arduino code writer. That’s a big reason why I like Tasmota. So I want to see what all we can do with Tasmota on the D1 mini.  

Step one is to download the latest version of Tasmota and the Arduino IDE (if you don’t already have it).  Open Arduino Preferences, paste the URL for the esp8266 board manager. Peak at where you’re Sketchbook is located.  Then go to Tools – Board – Boards manger, search for and install the ESP8266 boards manager. Then go to the Tasmota lib folder, copy everything in there and paste it into your Sketchbook folder.  

Now open the sonoff.ino file, go to user_config.h, add your WiFi info, MQTT info and give it a unique project name.  One really nice difference is because this board is made for hacking, there’s no funky procedure for getting it into programming mode.  It’s a development board, so it’s always in programming mode. Just use a micro USB cable and plug it into your computer. Select the COM port that just appeared. Now under tools, select the board type, and match these other settings.  

If you’re using the NodeMCU board you may need to do another step before it will show up in the COM ports list.  I had to install this other driver.

CP210x

I think that’s because the NodeMCU has another chip.  Another difference with the NodeMCU is you can power it with 12v.  So if you’re running 12v lights, using the NodeMCU instead of the D1 mini (which runs on 5v), means you don’t need to have an extra voltage regulator.  Bonus! When you’ve got all that hit upload.

Once you’ve hit 100% go to your router and find the new device, then put the IP address in your browser.  You’ll get the Tasmota main page. Tasmota will set the device type as Sonoff Basic by default. To change it go to Configuration – Configure Module – then set the device type to Generic. Save and it’ll restart.  When it comes back up go to the Configure Module page again and look at all those options! Every one of those boxes can be set to some different function. Wuhoo! So let’s have some fun!

A lot of folks are interested in Temp & Humidity, so let’s connect that sensor first. The one I have is the DHT11.  There are others. The Tasmota website has a list of supported sensors and tells you which option to select from the menu for each sensor. If you don’t see the sensor you’re using in that list, it doesn’t mean you can’t use it.  It just means you’ll have to work harder to get it working.

https://github.com/arendst/Sonoff-Tasmota/wiki/Sensor-Configuration

Getting the T&H to show up in Tasmota is really easy.  Just connect the sensor (VCC, Gnd, and Output to a GPIO pin), and select the DHT11 for the pin you connect the sensor to save and restart the board.  Now getting Home Assistant to see that data is a bit more involved. Go to your Config.yaml, to the sensors section and add this:

sensor:

 – platform: mqtt

   state_topic: ‘tele/D1mini01/SENSOR’

   name: ‘Temperature’

   unit_of_measurement: ‘°F’

   value_template: ‘{{ value_json.DHT11.Temperature }}’

 – platform: mqtt

   state_topic: ‘tele/D1mini01/SENSOR’

   name: ‘Humidity’

   unit_of_measurement: ‘%’

   value_template: ‘{{ value_json.DHT11.Humidity }}’

 – platform: yr

 

D1mini01 is what I called my project when I loaded tasmota on this board.  You’ll need to put your own project name in place of mine. The tricky part here was getting the value_template right. If you look at the “payload” that gets sent by the D1 mini on that “topic” it looks like this:

It’s json formatting, so it’s in pairs. Time has a value, and tempunit has a value, but DHT11 has two values. Getting the template to pull the right value had me stumped for a bit.  Thanks to ‘me hardy’ IROTRAS for pointing me in the right direction. The key was adding “DHT11” to the Template. You may never have to use that again, but it caused me enough of a struggle that I figured I’d better include it.  With the Template working you should now see the Temp & Humidity in HA, and new sensors in your entity list that you can use for automations. Like automatically buying a one-way ticket out of town when the humidity is over 85%. Yay!

If you wanted to connect this same sensor to a Sonoff, you just attach the output to one of the GPIO pins. Then the rest of the settings are the same.

 

For the next bit of fun, let’s connect some programmable LEDs.  Tasmota is all set up to run ws2812 LEDs. Those are very common and easy to get. They’re essentially the same as the Adafruit NeoPixels, if you’ve ever heard of or used those. If you’re going to run more than a few LEDs you’ll want to have a separate power supply. Each GPIO pin is only able to withstand a load of about 12mA. These LED’s draw between 20 and 60 mA, so plan your ps accordingly.  I’ve got 5v LEDs so I just use a 3 amp 5v ps, to power the D1 mini so I have plenty of capacity for a 150 LEDs. Connect the data pin from the LEDs to one of your GPIO pins, then in Tasmota select “WS2812” for that pin. Of course, connect vcc and gnd to the LEDs too. Duh.

 

After you’ve selected WS2812 and saved, Tasmota will restart. When it comes back up you’ll have a dimmer slider and a toggle button. To play around with the available effects you can go to the Console and use Color and Scheme commands. Here’s the list of what’s available:

WS2812 Commands

When you want to trigger the lights from Home Assistant you can call the service “mqtt.publish” with the topic like this:

cmnd/D1mini01/Scheme (payload + or -)

cmnd/D1mini01/Color (payload + or -)

cmnd/D1mini01/Color (payload hexadecimal color)

cmnd/D1mini01/Dimmer (payload + or -)

cmnd/D1mini01/Speed (payload + or -)

cmnd/D1mini01/Fade (payload 1 or 0)

 

If you set up an mqtt Light in your config.yaml, you’ll be able to set the color with a nice selector and you’ll have a dimmer slider and an on/off tab. I loves me some purdy LEDs!

 

light:

 – platform: mqtt

   name: “D1mini ws2812”

   command_topic: “cmnd/D1mini01/power2”

   state_topic: “stat/D1mini01/POWER2”

   rgb_state_topic: “stat/D1mini01/color”

   rgb_command_topic: “cmnd/D1mini01/color”

   brightness_state_topic: “stat/D1mini01/dimmer”

   brightness_command_topic: “cmnd/D1mini01/dimmer”

   retain: true

 

Now let’s set up the PIR. PIR = passive infrared sensor. We usually use these as motion detectors, but they’re not really motion detectors, they are heat detectors. And as someone pointed out in the last live stream, it should only detect large balls of heat (like humans) and ignore smaller things like pets.  Well, most pets…

 

The PIR has 3 pins, vcc gnd and output. We connect the output to one of the free pins on the D1 mini (or sonoff). A PIR sensor is really just a switch. It’s either on or off. It turns on when there’s motion, then quickly back off again, then back on briefly if there’s still motion. It doesn’t stay in the on position when it detects motion.  Since it acts like a switch we select “switch” as the device type in Tasmota. If you already have a switch (like a touch module) as Switch1 then make the PIR Switch2. You can have up to 4 switches, or 4 sensors that act like switches. You can set the mqtt topic for that switch (or sensor) in the Console with command SwitchTopic(#) ‘customtopic’.  So for my PIR, I’m going to set it up as Switch2 and set the topic as D1mini01PIR. If you were doing this for your house you could set the topic based on the location; “FrontDoorPIR” for example. Then in Home Assistant you set things up to subscribe to that topic to give you the response you want. Like turning on the porch light. You can set the topic to control the local relay on the sonoff too by making SwitchTopic2 match SwitchTopic1, which by default triggers the onboard relay. Or just make your PIR Switch1, then it will control Relay1 by default.

 

To set up the PIR as a sensor in Home Assistant, you put something like this in your config.yaml:

binary_sensor:
 – platform: mqtt
   state_topic: “cmnd/D1mini01PIR/POWER2”
   name: “D1 PIR”

 

customize:

 binary_sensor.d1_pir:

   device_class: motion

 

automation old:

 – alias: ‘D1 motion ON’

   trigger:

     – platform: state

       entity_id: binary_sensor.d1_pir

       from: ‘off’

       to: ‘on’

   action:

     – service: light.turn_on

       data:

         entity_id: light.d1mini_ws2812

#—————————————————-

 – alias: ‘D1 motion OFF’

   trigger:

     – platform: state

       entity_id: binary_sensor.d1_pir

       from: ‘on’

       to: ‘off’

       for: ’00:05:00′

   action:

     – service: light.turn_off

       data:

         entity_id: light.d1mini_ws2812

#—————————————————

 

All these other sensors are setup in the same manner as the PIR sensor.  Connect the sensor, set it as a Switch(#), set the switchTopic(#), then setup something to respond to that topic.  

All these other sensors can be used in the same way:

 

That’s probably enough for part 1.  In part 2 I’ll show you how to use these other sensors:

  • Tilt Switch
  • Ultra Sonic
  • Light Intensity
  • Sound Detection
  • Flame Detection
  • Water Level

 

Tasmota Sensors Page:

https://github.com/arendst/Sonoff-Tasmota/wiki/Sensor-Configuration

 

ESP8266 Board Manager URL:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

 

Theo Arends Github Contact: https://github.com/arendst

 

Tasmota Console Commands:

https://github.com/arendst/Sonoff-Tasmota/wiki/Commands

 

NodeMCU required Driver:

https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

 

Product Links:

D1 mini

Amazon:

AliExpress:
AliExpress.com Product – 1pcs D1 mini – Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266

NodeMCU

Amazon:

AliExpress:
AliExpress.com Product – New Wireless module NodeMcu Lua WIFI Internet of Things development board based ESP8266 with pcb Antenna and usb port ESP-12E

Sensor Pack

Amazon:

AliExpress:
AliExpress.com Product – 37 IN 1 sensor kit for Arduino starter kit high-quality (Works with Arduino Boards) landzo

PIR – Motion Detector

Amazon:

AliExpress:
AliExpress.com Product – NEW PIR Sensor Human Body detecting module Pyroelectric HC-SR501 For Arduino MCU Freeshipping
Temp/Humidity

Amazon:

AliExpress:
AliExpress.com Product – Free Shipping 1x DHT11 DHT-11 Digital Temperature and Humidity Temperature sensor for Arduino Hot
WS2812 LEDs

Amazon:

AliExpress:
AliExpress.com Product – 1m/4m/5m ws2812b ws2812 led strip,30/60/74/96/144pixels/leds/m individually addressable smart led light dc12v