Sonoff-HomeAssistant (Alternative firmware for Sonoff Switches for use with mqtt/HA)

Hey @RAWB Can you please share your config_sc.h file as I have got a TH16 and the temperature and humidity doesnt work from the 2.5mm jack on my TH16.

Thanks…

I grappled with exactly this problem for months. It turned out to be my FTDI. I bought different ones from China. One of them worked. I can’t describe how excited I was seeing it upload to the Sonoff after 4 months of frustration. So, buy different FTDI’s and try them out. And don’t forget to kill the power and reboot the Sonoff into program mode.

1 Like

Good point @deej99

I use multiple on my job to program Arduino Pro Mini.
For the ESP8266 / Sonoff I use the CP2102 with micro USB, as I like that it is small and I always have a micro USB cable in my bag.

PS. I see that the one I ordered now has no free shipment to NL at the moment. So you might want to find a different one that has the same 3v3 and 5v output option.

Well I am powering from USB for now I haven’t connected it to the mains yet. Could it be that I need to connect it to the mains and then hope the temperature and humidity data to be logged?

Hi Mudman, are you able to get the water reading daily/hourly and monthly in HA with this meter?
I’ve been scratching my head for days trying to figure this out. I have tasmota FW. I can get the reading into HA with either pulse Counter or pulse Timer. I also noticed that if the sonoff restarts it looses the data on pulse counter or the sonoff gives a incorrect number. Any help will be much appreciated.

Did you ever manage to figure this out?

As long as you have a regulated 3.3V it shouldn’t make a difference if you’re connected to the mains or not (other than increasing your chance of getting fried!). I’d strongly recommend only connecting to mains once everything works perfectly, and boxing/insulating at the same time. You’ll live a lot longer that way.

1 Like

Thanks for the tip! Interestingly my only FDTI that works with Arduino IDE on a Mac, won’t work with Atom PlatformIO. It fails to upload to the Sonoff yet the Atom serial monitor works. I’ve been thinking of using a Rasberry Pi 3 to do the uploads as I’ve read Macs can be problematic. What app are you using and on what OS?

@KmanOz is your code working for DS18B20 temperature sensor? Its driving me crazy I can only get AM2301 working. Please confirm?

Thanks.

Hi @turu

Your code for the DS18B20 does it work well and is stable? Have you got any instructions for flashing or?

I really need a code for DS18B20.

Thanks.

I tried Tasmota with the DS18B20 and it worked.

1 Like

I am using the Arduino IDE on Windows 10 and have also used Ubuntu in the past.
I am not an expert but I think that the FDTI is dependent on the driver for it, which is OS related.
So I understand your solution for going to (for example) Rasbian on a Rasberry Pi 3.
However if the software Atom PlatformIO recognizes the FDTI and the serial monitors works, then it should be able to upload. Did you set the right settings in PlatformIO? Dout mode etc?
(disclaimer, I have never worked with PlatformIO)

I suspect the FDTI is more than driver-dependent. I bought multiple FDTI’s and some work, whereas some don’t. The issue seems to extend to the software/hardware. One of the issues with working on this technology is that people are talking across-purposes. Some use Windows, some Ubuntu, some Mac etc. There is a litany of issues being discussed but there is no clean, common platform. Any issue could be related to literally any software installed on their computer, or caused by the OS. If as a community we don’t have a common base, how can we exchange meaningful information?

FTDI chips are subject to cloning, chinese chips really similar to the legitimate but low quality. Try to google “FTDI fake chips”, plenty of people scammed. Maybe some of your chips are the good one, other are the clones. Better to go with CP2102 as @bvansambeek suggested.

@namadori Can you please share your mqtt sensor config for DS18B20? I have just flashed my sonoff TH16 to tasmota and can control the switch but struggling with the DS18B20 recording.

Thanks.

Sorry but I exchanged the DS18B20 with a SI7021 to have a humidity reading, I can’t tell you the exact configuration but will try to help:

My steps:

  1. the DS18B20 needs a pull-up resistor between Data and +5V
  2. set the correct sensor in Tasmota config and reboot, you should see the temperature on the web page
  3. check the Tasmota console for the MQTT message sent. For example my sensor reports this way: 19:33:10 MQT: tele/sonoff/SENSOR = {"Time":"2018-02-13T19:33:10","SI7021":{"Temperature":20.8,"Humidity":45.7},"TempUnit":"C"}
  4. the HA configuration is quite simple. This is for SI7021, you should adapt it for the DS18B20 message format:
  - platform: mqtt
    name: "Sonoff_temperature"
    state_topic: "tele/sonoff/SENSOR"
    value_template: '{{ value_json["SI7021"]["Temperature"] }}'
    unit_of_measurement: "°C"

If you are still having problems, tell us what works and what doesn’t from the 4 steps.

1 Like

@namadori

1). how do I add this pull up resistor?

2). how do I set the correct sensor in Tasmota?

thanks

UPDATE:

IT WORKS!! I had to change the GPIO settings and it worked !!!

For the pull up resistor: it is recommended 4.7K, similar values should work too (I tried with 10K)

For instructions google “esp8266 ds18b20”, there’s plenty of tutorials.

Screenshot%20from%202018-02-13%2019-48-18

EDIT: saw your message: I’m glad it worked. If it behaves strange or if it stops working with a longer cable, yu need the resistor. Maybe for short cable lengths it works without.

2 Likes

thanks @namadori

@namadori so I extended the cable of the DS18B20 by almost 3metres and everything still works fine on 3.3V without the 4.7kohm pull up resistor.

UPDATE: installed the resistor and things are still normal.

Another one for you. . I noticed HA doesn’t report the state of the switch if it was restarted. Do you have any solution to that buddy?