I spent very little time with the stock firmware on the device. I don’t like the fact that an Internet connection is needed, and I am not in control. As of the time of this writing I found the Ewelink was not configurable enough to meet my needs. There is one feature that is really nice that I could easily see keeping stock firmware. It is the Alexa Skill. It worked. I am also currently reviewing Vobot Smart Alarm Clock with Alexa integration and had no trouble controlling the Sonoff devices with Alexa. But unfortunately I am lazy and want everything automatic so I can’t keep it. With the RF bridge I was unable to trigger a light from a motion sensor. In comes Arendst ‘s Sonoff-Tasmota firmware to the rescue. It gets better all the time. It is dead simple, and so configurable now. He continues to add features and devices.

RF Bridge

You may have seen my previous article building a 433toMQTTto433 bridge to use cheap 433mhz devices. I never did build a case for it, and it’s a little bit of an eyesore. When I found out about a nicely packaged one, I was excited to check it out. Like I stated previously, it didn’t work as I anticipated and was glad when I found out Arendst got one as well. He has a good wiki with on the github page and all the needed information to flash and configure so I won’t go into it. It flashed uneventfully. I was a little scared by the design that it was only going to be able to receive 16 individual codes and pass onto MQTT but that is not the case. It passes everything it receives. You can only send 16 different codes right now which need to be saved ahead of time. So after monitoring the MQTT server I ran into first hurdle. I was getting this example json value.

And actually I found after much frustration that “Data” is a nested json value. This took a while for me to figure out. After that it was relatively easy to parse in Home Assistant and move my automations over from the previous bridge.

YAML

1

2

3

4

5

6

7

8

9

10

11

- alias: Living Room Tamper

hide_entity: true

trigger:

platform: mqtt

topic: tele/sonoffrfbridge/RESULT

condition:

condition: template

value_template: '{{trigger.payload_json.RfReceived.Data=="982817"}}'

action:

service: homeassistant.toggle

entity_id: light.living_room

and

YAML

1

2

3

4

5

6

7

- platform: mqtt

name: "Living Room Motion"

payload_on: "98281B"

payload_off: "9971736"

sensor_class: motion

state_topic: "tele/sonoffrfbridge/RESULT"

value_template: '{{value_json.RfReceived.Data}}'

From the previous article payload off is a made up value and is only used internally to turn the sensor off after a minute.

Just a couple gripes about the rf bridge which are superficial. There is a noticeable increased delay over the homemade bridge from the time it senses a trigger until the light comes on. It is only about half a second but a noticeable difference. And my wife pointed quickly that the led indicating it is on is very bright. I might remove it or install a varistor to tone it down. The receiver does not appear to be as good or might just be that it is in a case or my positioning. I am still able to cover my house but the trigger on my mailbox across the street doesn’t trigger. It was hit or miss on the old one but never triggers now.

FYI I am still running off the same batteries I initially installed in the 433mhz motion sensors over 6 months ago.

Sonoff 4ch Pro

I tested it with stock Ewelink software and all tests done before worked. I quickly installed the alternative firmware from above, and again no loss in functionality. I was still able to pair and clear the 433 MHz remotes. It is weird that it does not indicate with a light that it is in pairing mode as of right now but when you press the button the light blinks when it is learned. The inching, self locking and interlock continued to work as well via switches. I can definitely see this being used for lighting, or if you needed to control multiple items in close proximity. Maybe simple access control. Possibilities are endless. On the product page, it shows wiring with motors as well which looks cool. If I find a unique or interesting project I will share.

The 4 button transmitter is very powerful. It transmits further than any of my other 433mhz devices.

Sonoff POW

Click to Enlarge

A buddy of mine gave me a Sonoff POW to play with. The Sonoff POW is very similar to the Sonoff Basic, but has the ability to measure power usage. I didn’t bother testing the stock software. I went straight to Arendst software. I didn’t have anything to measure power before and this is a welcome addition to my tools arsenal. I don’t need super accurate readings just a good idea what the draw is. I installed a light rated at 75w to test and got the results below. If a more accurate load is available you can calibrate the POW and instructions are in the Wiki.

OTA Firmware

Who wants to drag all their devices back to the PC and flash new firmware? I finally checked it out. It is really simple to do.

First uncomment BE_MINIMAL then export compiled Binary. After a while you will have a bin file in your sketch folder.

Click to Enlarge

After uploading comment BE_MINIMAL, upload again. The 2 steps procedure is because he is running out of space with all the features. He is trying to reduce the code down, and hopefully make this a single step in the future. If you have a web server there are instructions to automate this.

Conclusion

I would like to thank Itead Studio for sending the Sonoff RF Bridge, 4ch Pro and 4 button 433 MHz transmitter. They keep expanding their Sonoff line and make them hacker friendly. I would also like to thank Arendst for his tireless work on Sonoff-Tasmota firmware. If you are just looking to control your lights via Alexa, and don’t mind requiring the Internet to be available the stock firmware might work for you.

Motion Sensor

Click to Enlarge

The motion sensor I linked in part 2 is run by a common chip called a BISS0001. We are interested in pin 9. If voltage is below .2v it will not trigger a motion. This solves the problem discussed in part 2, when we have a gloomy day or if blinds are closed etc.

By adding an GL5537 LDR (Light Dependent Resistor) shown as R3 in the diagram above, you will achieve the desired effect. Extend the LDR with some wires and solder between ground and pin 9.

The GL5537 is extremely sensitive. You can adjust your sensitivity by placement. I put mine right next to the PIR sensor so it sees outside the window. It works perfectly. If you wanted it to get a little darker you can use the mounting hole on the back or make a new on the top or sides. Direct access to the outside light would mean it would need to be darker in the room for it to trigger. You have to be careful with the motion sensor placement or your light being triggered might cause the motion sensor not to trigger because there is too much light. I get this if the motion sensor is too close to the lamps I am triggering.

Home Assistant

Before modifying we had 2 automations one for before sunrise and one for after sunset:

YAML

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

automation:

- alias: Turn on generic after Sunset

hide_entity: true

trigger:

platform: state

entity_id: binary_sensor.generic_motion

to: 'on'

condition:

condition: and

conditions:

- condition: sun

after: sunset

after_offset: "-1:00:00"

- condition: time

before: '20:00:00'

action:

service: homeassistant.turn_on

entity_id: script.generic_timed_lamp

- alias: Turn on generic before Sunrise

hide_entity: true

trigger:

platform: state

entity_id: binary_sensor.generic_motion

to: 'on'

condition:

condition: and

conditions:

- condition: sun

before: sunrise

before_offset: "1:00:00"

- condition: time

after: '07:00:00'

action:

service: homeassistant.turn_on

entity_id: script.generic_timed_lamp

Now that we’ve added the logic for light and dark at the motion sensor itself, we can simplify these 2 down to one automation, and only specify the time. The rest of the home assistant configuration can be found in 2nd article here.

YAML

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

automation:

- alias: Turn on generic on Motion

hide_entity: true

trigger:

platform: state

entity_id: binary_sensor.generic_motion

to: 'on'

condition:

condition: and

conditions:

- condition: time

after: '07:00:00'

- condition: time

before: '22:00:00'

action:

service: homeassistant.turn_on

entity_id: script.generic_timed_lamp

That is all I have for now. If you have an idea or a product that you feel that meets the cheap and DIY criteria leave a comment below. I will test it out. I know you can do a ton of things with Home Assistant and a lot seem over the top. I want to focus on mundane things like turning off lights. I am also going to get some 433 MHz moisture sensors for my house to place in crawl spaces, and under the sink but that is pretty basic.

Karl here again for part 2 of my home automation project. We will be looking at how to automate your lights based on time of day and motion. In the first part we setup Home Assistant and uploaded firmware to basic Sonoff Wifi switches. Today we will setup a 433 MHz to MQTT bridge and some sensors.

433 MHz

Depending on your country 433 MHz is an open frequency to use to communicate with. There are hundreds of different types of devices that use 433 MHz to communicate information. We will be focusing on 2 today from Gearbest: WMS07 motion sensor (left) and WDS07 door/window sensor (2 parts, right).

I am not taking the door/window sensor apart, since it is super basic, but I’ve included some photos of the PIR motion detector.

Click to Enlarge

Click to Enlarge

433 MHz Bridge

While contemplating how to get presence on a per room basis I ran across this project. It monitors 433 MHz signals and publishes it to the MQTT server. It is a really an easy project. It also has an IR to MQTT feature. I did have an IR receiver and tested it but have not implemented it. He has some good instructions on his page so I won’t go over too much. You can do the bare bones version and just leave off the unused sensors. I also went an extra step and added a light intensity sensor and DHT sensor to the project. It can be found here. I am not going to add those to this write up because trying to keep costs down.

That is all that is needed. For about $10 you have an inexpensive 433 MHz bridge. You can put in a box if you want and hide it in a central location away from interference. I would suggest soldering headers to your board just in case something goes bad. I didn’t at first and made my life a pain. There are a ton of 433 MHz receivers. I purchased all the ones on Gearbest and this is by far the best. I did upgrade to a superheterodyne but I am not sure it is any better. I upgraded because I wanted to put the door sensor on my mailbox and get a notification when the mail was delivered. It is about 200’ away and is a little spotty even with a new 433 MHz receiver. I used this antenna design (see picture on right), as it seemed to work the best

Coverage is the biggest concern. I have a brick single story ranch style home about 2000 square feet and it covers the inside with ease and a lot of the area around the house. If you have a multi-story house or would need multiple receivers you would need to change the MQTT topics to avoid getting duplicates. Below is the final project. To be honest temperature is really the only thing that is useful to me, but wanted to see what could be done. I purchase the DHT11 and the readings are not good. If you want to do this go with the DHT22. Below is a mostly loaded bridge. I don’t have an infrared transmitter yet. I have a different one coming that does the encoding/decoding on a chip and will follow up when I receive it. I am hoping it will be easier/better than using the Arduino library.

Motion Sensor

The motion sensor itself is really easy to setup with jumpers. I suggest turning the LED off, and the time to 5 min after finished setting up with the jumpers. If you notice there is a micro switch in the top left of this picture. It is meant to be a tamper switch but I use it as a toggle switch to quickly turn off the lights. The motion sensor is meant to be used for a security system but I just have them sitting on night stands and corner tables. It works really well to override or turn a light on when Home Assistant ignores the motion. A little squeeze of the box and the light will toggle states on or off.

After your bridge is set up and connected take the motion sensor out and put some batteries in it. Run your batch file to see what code is being sent. For this one we need 2: motion and tamper. Write these codes down.

Home Assistant

Below is the YAML code that I am using with Home Assistant. I made it find and replace friendly. If you copy and find the 4 items below it should work. I think it is relatively easy to follow. It is the typical timed lamp on motion that is on Home Assistant website with some slight modifications. I had to add the turn off motion script because the motion sensors only sends when it senses motion. I also had to add the tamper toggle switch. When you are adding multiple sensors you can only have one “binary_sensor:” group and one “automation:” group etc.

Find/Replace

Explanation

generic

use livingroom or masterbedroom etc no spaces

5555555

use the motion number you found earlier

8888888

make up a number around your tamper/motion number

9999999

use the tamper number you found earlier.

YAML

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

binary_sensor:

- platform: mqtt

name: "Generic Motion"

payload_on: "5555555"

payload_off: "8888888"

sensor_class: motion

state_topic: "home/433toMQTT"

automation:

- alias: Turn on generic after Sunset

hide_entity: true

trigger:

platform: state

entity_id: binary_sensor.generic_motion

to: 'on'

condition:

condition: and

conditions:

- condition: sun

after: sunset

after_offset: "-1:00:00"

- condition: time

before: '20:00:00'

action:

service: homeassistant.turn_on

entity_id: script.generic_timed_lamp

- alias: Turn on generic before Sunrise

hide_entity: true

trigger:

platform: state

entity_id: binary_sensor.generic_motion

to: 'on'

condition:

condition: and

conditions:

- condition: sun

before: sunrise

before_offset: "1:00:00"

- condition: time

after: '07:00:00'

action:

service: homeassistant.turn_on

entity_id: script.generic_timed_lamp

- alias: Turn off generic motion

hide_entity: true

trigger:

platform: state

entity_id: binary_sensor.generic_motion

to: 'on'

action:

service: homeassistant.turn_on

entity_id: script.generic_pir_timer_off

- alias: generic Tamper

hide_entity: true

trigger:

platform: mqtt

topic: home/433toMQTT

payload: '9999999'

action:

service: homeassistant.toggle

entity_id: light.generic

Light:

- alias: generic

platform: mqtt

name: "generic"

state_topic: "stat/testbench/POWER"

command_topic: "cmnd/testbench/power"

payload_on: "ON"

payload_off: "OFF"

script:

generic_timed_lamp:

alias: "Turn on generic and set timer"

sequence:

# Cancel ev. old timers

- service: script.turn_on

data:

entity_id: script.generic_pir_timer_off

- service: script.turn_off

data:

entity_id: script.generic_timer_off

- service: light.turn_on

data:

entity_id: light.generic

# Set new timer

- service: script.turn_on

data:

entity_id: script.generic_timer_off

generic_timer_off:

alias: "Turn off generic after 30 minutes"

sequence:

- delay:

minutes: 30

- service: light.turn_off

data:

entity_id: light.generic

generic_pir_timer_off:

alias: "Turn off generic motion"

sequence:

- delay:

minutes: 1

- service: mqtt.publish

data:

topic: 'home/433toMQTT'

payload: '8888888'

Door Sensor

For the mailbox sensor here is an example. Same thing on this one run the batch file and find the open and closed codes. I have it send me a notification via pushbullet.

YAML

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

binary_sensor:

- platform: mqtt

name: "Mailbox"

payload_on: "11784714"

payload_off: "11784718"

sensor_class: opening

state_topic: "home/433toMQTT"

automation:

- alias: You've Got Mail

hide_entity: true

trigger:

platform: mqtt

topic: home/433toMQTT

payload: '11784714'

action:

service: notify.pushbullet

data:

message: 'Youve Got Mail'

Almost there

We are almost there. Lights are turning on and off magically. Life is good. But there is one situation where it’s not so good. The gloomy day. With the automations above we cannot determine if the blinds are pulled or it is gloomy. We still need the lights to come on under those circumstances to make it really cool. In the next installment we are going to take the motion sensors above and add a light intensity sensor to them. We will be able to do this cheap. We still have a pretty good budget. With the bridge above you open yourself to a bunch of battery operated sensors. You can also control devices, as well, with a transmitter. Any of the transmitters should work on GearBest. You can get the one linked and throw away the receiver. It’s only $1.25. If you have any questions or concerns feel free to leave a comment.

Karl here. I am here to write about my home automation project. First thing I want to say is that I am very cost conscious and I don’t mind putting in extra effort into the setup of things to keep costs down. I did invest a lot of time and had to do a lot of reading to get my project going. It took while and I received a lot of groans from my wife while testing. I am still in the process of tweaking things.

I started watching a series of videos on YouTube from Bruh Automation. He introduced me to Home Assistant. It got me really excited. He uses a Raspberry Pi as a server but I already had a Wintel Pro CX-W8 Smart TV Box which I use as a server. I run 3 Minecraft Servers, Emby Server, iSpyConnect DVR (2 IP Cameras), Unifi wifi controller, and now MQTT Server, and Home Assistant. Below is screenshot of mostly idle.

If it weren’t for iSpy it would be around 5-10% most of the time. Emby transcoding is the only thing that is stressful and it is not used much. The reason I mention this is because after purchasing a Raspberry Pi with power supply and case, you are not far off from getting a z8300 box. Only downfall is dreaded Windows update auto reboot. I finally looked into it and disabled it. If you decide to use a Windows box, I would make sure you are running 64bit windows. One advantage to using a Raspberry Pi is there is an image on Home assistant with the basics pre-configured and just need to write it to an SD card.

Server side Setup

I won’t go into too much detail on server side, as I installed Python, Mosquitto, and Home Assitant (I followed the guide on their site for Windows)

Python was a breeze to install and just ran the executable and went with defaults. I already had it installed for something else and I am running 3.5.2 64-bit. There are newer versions now. Mosquitto was the most difficult. I followed this guide but substituted Win32OpenSSL_Light-1_0_2j.exe approx 2MB. A k version is available now. Home assistant was easy and used pip.

Christmas Lights

It was a little before Christmas when I started researching home automation. I had been reading about these inexpensive Sonoff devices here on CNX and I found a project on Github for some custom firmware by arendst that enabled them to be controlled by MQTT. (While getting the link it looks like a new project has started with some additional features here). My wife really likes decorating for Xmas and we have 3 trees and lots of lights. She mentioned getting some timers and boom I had my opportunity and ordered them the same night. After receiving It took me a couple nights and I had a simple automation turning Xmas lights on and off at specific times and life was good. I got an extra one to play with until Xmas was over. I redeployed the rest around the house after Xmas.

MQTT

I really had no idea what this was and it took me a while to grasp. You can use a cloud based MQTT if you would like, but I prefer to run my own. MQTT is a service that relays messages between devices. There are 2 main items topics and payloads. To be able to tell a switch to turn on you send payload “on” to a topic, for example, “cmnd/testbench/power”. The light turns on and it replys back to a topic “stat/testbench/POWER” confirming that the light is on and the message is received. Because we are sending “on” to the topic each device using MQTT will need its own topic. Topics are case sensitive. I made a batch file to subscribe to all topics for troubleshooting so I could monitor the messages. The # indicates all sub topics.

Sonoff

I picked the Sonoff basic but there are also different varieties that add additional features which are supported by arendst software.

Arendst has been very active with this project and adding/tweaking daily. When I first flashed the device, I did find a defect and notified him and he had it fixed and uploaded within the hour. He has very detailed instructions on the Wiki. First step before flashing is soldering headers. (I link to bent headers…which I initially thought I made a mistake but turned out it was good. They are easy to straighten) A USB to TTL adapter is also needed to upload from Arduino IDE. I recommend one like this because it provides both 3.3 and 5V. After downloading and setting Arduino up, I only set my WiFi password and SSID in the sketch. After it boots the first time, it connects to your wireless network. Find the IP address in your router, and pop the IP address in your browser to finish the configuration. Set the MQTT server credentials and topic and your done. I never setup credentials on the MQTT server so it accepts any login. Finally after everything is programmed you need to connect it to mains. Beware do not connect mains while TTL is connected.I bought some extension cords locally. Cut them in half and stripped back a ¼ inch of the insulation. Extension cords use stranded wire so I tinned them with solder to avoid any stray strands from shorting out. Then I screwed them down on the terminals making sure polarity was correct.

Click to Enlarge

YAML

YAML is unforgiving. It is the formatting that you configure Home Assistant in. A single space will stop Home Assistant from starting. Luckily on this last update if you restart Home Assistant through the browser it will test the configuration file before actually restarting. I purposefully put an extra space on line 54 to show it is easy to find any mistakes.

Click to Enlarge

I also recommend Notepad++ for editing in windows. You can break your configuration down into different files but I like one. Notepad ++ allows you to collapse the parts you aren’t currently working on.

I recommend adding one thing at a time and restarting to make it easier to find errors. And making a copy of the last working config before adding more. In the config below there are 5 sonoff’s and an automation to turn the lights on and off at specific times. This is extremely basic. I also recommend setting up one new device and be conscious of naming. When you get your config working properly on your first new device I copy the config to a new blank text window and do a find/replace.

Below is the screen capture of collapsed parts, and and full config (minus personal info).

# Allows you to issue voice commands from the frontend in enabled browsers

conversation:

# Enables support for tracking state changes over time.

history:

# View all events in a logbook

logbook:

# Track the sun

sun:

# Weather Prediction

light:

- alias: Living Room

platform: mqtt

name: "Living Room"

state_topic: "stat/livingroom/1/POWER"

command_topic: "cmnd/livingroom/1/power"

payload_on: "ON"

payload_off: "OFF"

- alias: Karson

platform: mqtt

name: "Karson"

state_topic: "stat/karson/1/POWER"

command_topic: "cmnd/karson/1/power"

payload_on: "ON"

payload_off: "OFF"

- alias: Master Bedroom

platform: mqtt

name: "Master Bedroom"

state_topic: "stat/masterbedroom/1/POWER"

command_topic: "cmnd/masterbedroom/1/power"

payload_on: "ON"

payload_off: "OFF"

- alias: McKayla

platform: mqtt

name: "McKayla"

state_topic: "stat/mckayla/1/POWER"

command_topic: "cmnd/mckayla/1/power"

payload_on: "ON"

payload_off: "OFF"

- alias: Test Bench

platform: mqtt

name: "Test Bench"

state_topic: "stat/testbench/POWER"

command_topic: "cmnd/testbench/power"

payload_on: "ON"

payload_off: "OFF"

group:

All_Lights:

-light.living_room

-light.karson

-light.master_bedroom

-light.test_bench

-light.mckayla

automation:

- alias: Lights On

hide_entity: true

trigger:

platform: time

after: '16:30:00'

action:

service: light.turn_on

entity_id: group.all_lights

- alias: Lights Off

hide_entity: true

trigger:

platform: time

after: '20:30:00'

action:

service: light.turn_off

entity_id: group.all_lights

Notice the test bench is on later firmware and the MQTT topic is slightly different

Next Steps

So now I have a smart home, right? Not in my opinion. I can turn lights on and off with a schedule or with my smart phone or at the light by pressing the button on the Sonoff. To me this is not smart. Setting a schedule is OK, but then you have the lights on unnecessarily and wasting electricity. Only real option is to press a button on the Sonoff but what difference is that than flipping a switch. Taking your phone out takes way too long, and I feel like it is going backwards. Below are estimated costs so far. By far the Windows Box will be the most expensive part if you choose to go that way. You can re-purpose just about anything that runs Linux to be a server. One other option is to run Linux on an S905x.

Money Spent

Cost of server not included nor shipping.

Item

Qty

Price

Total

Sonoff Basic

5

$4.85

$24.25

Headers

1

$1.50

$1.50

USB to TTL

1

$2.54

$2.54

Total

$28.29

If you find this entertaining or want me to go more in depth on a specific aspect let me know in the comments. I have been finding my time setting it up very satisfying. I am able to do some hardware and software work. I hope this might get your interest in home automation going, and find out it is not hard nor expensive. I would like to state none of the products linked were provided by the sites. I purchased with my own money.

The plan right now is to do a 3 part post. In the next post, we will integrate some inexpensive motion sensors and door sensors using 433mhz, then finally modifying the sensors to include a light intensity sensor.