Create a DIY motion activated smart switch with temperature and humidity sensors. Learn how to create custom automations with Tasmota rules. My previous video of the unboxing and flashing Tasmota Firmware with the Sonoff Basic Template:

Smart Switch Models:

VegaHome (Larger LED window on the button)
2 pack –

KULED SmartSwitch:
(2 Pack) –
(4 Pack) –

Gosund Switch with a power logo
(1 pack) –

Parts List:
DHT22 Temp/Humidity Module – or

PIR Motion AM312 Sensor – or

Male Header Pins –

Female Jumper Wires –

USB FTDI Adapter(for Flashing, set jumper to 3v3 – NOT 5 volts) –

Products I use and recommend –

Come chat with us!
Discord –
Patreon –

Sample HomeAssistant Config:

– platform: mqtt
name: “KLD Motion”
state_topic: “KLDSwitch/PIR/state”
availability_topic: “tele/KLD-Secondary/LWT”
qos: 1
payload_on: “1”
payload_off: “0”
payload_available: “Online”
payload_not_available: “Offline”
retain: false
device_class: motion

– platform: mqtt
name: “KLD Temp”
state_topic: “tele/KLD-Secondary/SENSOR”
value_template: “value_json[‘AM2301’].Temperature ”
qos: 1
unit_of_measurement: “°F”
availability_topic: “tele/KLD-Secondary/LWT”
payload_available: “Online”
payload_not_available: “Offline”

– platform: mqtt
name: “KLD Humidity”
state_topic: “tele/KLD-Secondary/SENSOR”
value_template: “value_json[‘AM2301’].Humidity ”
qos: 1
unit_of_measurement: “%”
device_class: humidity
availability_topic: “tele/KLD-Secondary/LWT”
payload_available: “Online”
payload_not_available: “Offline”

Fix boot windows 10

Previous articleHow To Use Samsung Smart Switch (2020)
Next articleHow to Use Samsung Smart Switch — The PC Mac Backup Method


  1. Hey! I’m a bit confused on to what you added the pir and temp sensor to.
    What device is providing the Wi-Fi?
    To what did you solder the pir sensor and temp / humidity sensor?

  2. Could this be done with a sonoff or something else if you have a situation where you either don’t want to modify the switch or won’t be next to it?

  3. A little late to this video, still new to the whole home automation “thing”. Using the smart switch to expand capabilities totally changes the game for me.

  4. Travis, something has been driving me crazy with the video, did you change the DHT22? during most of the video you have a regular DHT22 that has the connectors (power, signal and ground) on the front (like an L shape), but when you proceed to glue it, the connectors are on the back and they are straight. I have a hard time fitting the sensor due to the L shape of the connectors.

  5. Hi, i used you guide with a sonoff basic in the hallway, and it work great. but i have a question if it possible to add a rule for sunset and sunrise for the pir sensor to trigger the light. Here in the north the sun goes down very late at summer.

  6. How to change the state of the relay1 on when the temperature (ds18b20 sensor) is above 35 degrees? what command

  7. Excellent video, this will be a great solution for the two gang boxes in my bedrooms where one switch controls the overhead light/fan, and the other controls an outlet(which I dont need to control). Bye bye second switch, hello sensors. 😀

  8. Travis, I love all your videos. I have added a DHT22 and an AM312 to a KuLED switch and applied all the Tasmota rules from this video. Everything works, but the LED flashes and I don’t know what to do to stop it.

    I did have an issue with the commands to turn the light off after the PIR turned it on. I finally figured it out. It would be nice if you would publish your Tasmota commands, like your HA, at the bottom of each video.

    Thanks Again for all your hard work,

  9. Travis, is there a way to get PIR state without triggering the relay (while having the wiring as per the video)? Thank you.

  10. Is there a rule that would just publish the temperature/humidity values only when their values have changed? That way I would not get duplicate MQTT messages from them.

  11. I tried to add the DHT22 temp/humidity sensor to a sonoff basic
    3.3v to pos, neg to GND and the single sensor wire to GPIO14
    The I set GPIO14 to AM2301
    The web page does not display the temp or humidity
    I’m using Tasmota 6.4.1
    I’ve double the wiring and it look correct.
    Any ideas want I could be doing wrong not to get the Temp and Humidity ?

    I edit the source and compile Tasmota myself is there any define I should be making sure I don’t comment out?


  12. Thanks for a realy great video , but can you tell me ,a rule mabye to my esp8266 12e board so the relay 2 follows the switch 2i becurse on the sonoff basic the switch 1 and relay 1 follows but not on the esp8266 12e as default ,i cant chouse relay 1 any were on the gpio`s

    please help ,i`m no coder at all so the rules are a bit hard to figer out i think thanks i have tasmota 6.4 on my board and every thing but the relay will not pull on motion i have switched from your rule to switch 2 and relay 2 but nothing happens

    edit : sorry find it out i flashed the esp8266 12e whit the “tasmota_6307_1m_i2c_sensors” and i then got the relay 1 too chose from so now all works as it should

  13. Just a heads up on installation. Yes the sensors are low voltage between the GND and Vcc pins. Although, on all of these devices, GND or DC common is referenced to the AC Hot leg. So, I would still treat it as Mains voltage. This is the exact reason you can’t flash these devices with AC mains connected.

  14. Hoping for some help – I installed AM2302 (bought on Amazon from link posted in description). Configured the module for AM2301 per the video and get no sensor readout on the web server. The switch is flashed with Tasmota 6.4.1. I know that the GPIO pins are working, as I tried a PIR sensor as configured in the video and that worked flawlessly.

    I’ve tried 2 different kuled switches, same result. I even tried adding a pullup resistor (4.7k and 10k tested) between 3.3V and GPIO sensor pin, as it seems to be best practice for this type of sensor. No luck. I’ve confirmed I get 3.3V on the pins when hooked to house AC. Could it be a tasmota firmware issue? Can someone confirm that the AM2302 is working on 6.4.1?

    I am certain the AM2302 sensor is functional, as I tested on an Arduino nano and got temp/hum readings no problem. So the Kuled switches seems functional, the sensor is functional, but I cant get a sensor working in the tasmota web server. I don’t know what to troubleshoot next

    Digiblur, thanks so much for the great videos!

  15. Great Video.
    Do you think you could add the PIR sensor directly to the switch, i.e. make the hole for the PIR sensor in the switch plate?
    Like to keep it one gang instead of 2.

  16. Thanks for the help w/ flashing the S20 last night. it mysteriously decided to work this morning and I think (using this vid as a guide) I have it programmed to run a 30sec shot of fog when the PIR is triggered. Will test later today when I have time to put jumpers on the header.

  17. Great video. I have the perfect use case: our bathroom has the traditional motion switch. Light stays on for about 5 mins. But, if you’re in the shower, it can’t see the motion. So, using humidity could tell the light to stay on. Thanks for the video!

  18. I can see using the perfboard for a splitter. I have started making my own dupont cables & just solder/shrink power&gnd wires together.

  19. Another great video, I cannot wait for an application to do this. The PIR looks extremely handy to be able to turn on the switch automatically. Thanks again!

  20. you can use empty dupont shells to have your pins correctly connected every time, just assuming that their “open” side is always on the external, for example…

  21. There is a console code, ill have to go back and look that will let you update temp and Humidity as quickly as every 10 seconds.

Comments are closed.