In the example the payloads are “ON” and “OFF”.
I think it’s case sensitive.
You’re 100% correct, thank you so much, the other firmware was lower case
Some advanced configuration for the Sonoff-Tasmota firmware. This configuration be used for the Sonoff POW:
sensor:
- platform: mqtt
name: "sonoff-workbench energy"
state_topic: "tele/sonoff-workbench/ENERGY"
value_template: "{{ value_json.Today }}"
unit_of_measurement: "kWh"
- platform: mqtt
name: "sonoff-workbench power"
state_topic: "tele/sonoff-workbench/ENERGY"
value_template: "{{ value_json.Power }}"
unit_of_measurement: "W"
- platform: mqtt
name: "sonoff-workbench voltage"
state_topic: "tele/sonoff-workbench/ENERGY"
value_template: "{{ value_json.Voltage }}"
unit_of_measurement: "V"
binary_sensor:
- platform: mqtt
name: "sonoff-workbench lwt"
state_topic: "tele/sonoff-workbench/LWT"
value_template: "{{ value }}"
payload_on: "Online"
payload_off: "Offline"
device_class: connectivity
switch:
- platform: mqtt
name: "sonoff-workbench"
state_topic: "stat/sonoff-workbench/POWER"
command_topic: "cmnd/sonoff-workbench/POWER"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
This configuration can be used for the Sonoff TH10/TH16 or another Sonoff with sensors (bh1750, bmp280) attached:
sensor:
- platform: mqtt
name: "sonoff-th10 temperature"
state_topic: "tele/sonoff-th10-3/SENSOR"
value_template: "{{ value_json.BME280.Temperature }}"
unit_of_measurement: "°C"
- platform: mqtt
name: "sonoff-th10 humidity"
state_topic: "tele/sonoff-th10-3/SENSOR"
value_template: "{{ value_json.BME280.Humidity }}"
unit_of_measurement: "%"
- platform: mqtt
name: "sonoff-th10 pressure"
state_topic: "tele/sonoff-th10-3/SENSOR"
value_template: "{{ value_json.BME280.Pressure }}"
unit_of_measurement: "hPa"
- platform: mqtt
name: "sonoff-th10 illuminance"
state_topic: "tele/sonoff-th10-3/SENSOR"
value_template: "{{ value_json.BH1750.Illuminance }}"
unit_of_measurement: "lx"
binary_sensor:
- platform: mqtt
name: "sonoff-th10 lwt"
state_topic: "tele/sonoff-th10-3/LWT"
value_template: "{{ value }}"
payload_on: "Online"
payload_off: "Offline"
device_class: connectivity
switch:
- platform: mqtt
name: "sonoff-th10"
state_topic: "stat/sonoff-th10-3/POWER"
command_topic: "cmnd/sonoff-th10-3/POWER"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
Have fun!
Hello all.
Just starting with Home Assistant. Now testing Mqtt and Sonoff devices (with tasmota firmware).
I tested mqtt works ok with hello world messages, with to putty terminals or putty and home assistant interface.
Now i do this kind settings one my sonoff switch.
When i toggle switch ON my browser. Sonoff switch goes ON just like i want, BUT after couple seconds HA browser shows switch goes back OFF state. Sonoff leave that ON state. If i try manually off sonoff that goes back to ON state after couple seconds. Only way i get that “permanent ON” state off, i need to stop mosquitto service, delete percident file and start mosquitto service again.
I am very thankfull if someone can help me with this problem.
edit: I try this too, but not helped:
- platform: mqtt
name: “Sonoff”
state_topic: “stat/s20-001/POWER”
command_topic: “cmnd/s20-001/POWER”
optimistic: false
payload_on: “ON”
payload_off: “OFF”
qos: 1
retain: true
This occurs because HA did not receive the state_topic:
message indicating that the light had turned on. In your example, it should receive a message with topic stat/s20-001/POWER
and payload ON
(or OFF
when you turn the light off).
Hi try that link instructions but not helped. Now i try mosquitto -v command. That gives me this, still that sonoff goes ON state ok, but after that not work.
pi@hassbian:~ $ mosquitto -v
1504805954: mosquitto version 1.4.14 (build date Mon, 10 Jul 2017 23:48:43 +0100) starting
1504805954: Using default config.
1504805954: Opening ipv4 listen socket on port 1883.
1504805954: Error: Address already in use
Or if that normal? Little scared how this mqtt start workings and quite much problems to get this working, if compare how easy everything seems many tutorials
I think you need different Client ID’s for HA and the Sonoff.
Open up a terminal on the system you have mosquitto installed and at the prompt type:
mosquitto_sub -u $USER -P $PASSWORD -t "#" -v
Where $USER = your mosquitto user and $PASSWORD = your mosquitto password.
the output should look similar to this:
tele/sonoff/STATE {"Time":"2017-09-07T20:16:46", "Uptime":38, "Vcc":3.161, "POWER":"OFF", "Wifi":{"AP":1, "SSID":"The Promised Lan", "RSSI":100, "APMac":"B8:A3:86:BD:0C:FB"}}
tele/sonoff4/STATE {"Time":"2017-09-07T20:18:00", "Uptime":50, "Vcc":3.204, "POWER":"OFF", "Wifi":{"AP":1, "SSID":"The Promised Lan", "RSSI":38, "APMac":"B8:A3:86:BD:0C:FB"}}
tele/sonoff4/SENSOR {"Time":"2017-09-07T20:18:01", "AM2301":{"Temperature":23.4, "Humidity":43.5}, "TempUnit":"C"}
Note sonoff4 is a TH10 which also includes an AM2301 temp and humidity sensor.
You have the client id the same for both the sonoff and the config of the broker in HA, i fell for the same thing. Change it in the sonoff to something unique
So, just got my Sonoff POW loaded with Tasmota 5.11 and have it online. I am trying to get some of the power numbers out of the unit and am not having much luck…
Here is the output from MQTTfx:
tele/sonoff-basement/SENSOR
Results:
{"Time":"2018-02-04T19:21:11","ENERGY":{"Total":0.000,"Yesterday":0.000,"Today":0.000,"Period":0,"Power":0,"Factor":0.00,"Voltage":118,"Current":0.000}}
My MQTT sensor to read the voltage value:
- platform: mqtt
name: "sonoff-basement voltage"
state_topic: "tele/sonoff-basement/SENSOR"
value_template: "{{ value_json.Voltage }}"
unit_of_measurement: "V"
This is resulting in the sensor
sensor.sonoffbasement_voltage
With no value contained.
What am I doing wrong?
This setup works for me.
- platform: mqtt
state_topic: "tele/sonoff/SENSOR"
name: "Voltage"
unit_of_measurement: "kWh"
value_template: "{{ value_json['ENERGY'].Voltage }}"
I hope it works for you.
Thanks… Worked! I knew it was something wrong in reading the json fields.
Is it normal for the POW not to have a wifi led on if the switch is turned off? The unit is still connected but does not display the blue led when it is logically off. I am running Tasmota 5.11.1
No it should show the blue light, maybe you changed it in the code of Tasmota before you wrote the firmware to the device?
I ota’d with sonota.exe and it loaded the latest version which I had pulled down.
This Tastmota/Home Assistant guide sorted it for me:
Awesome stuff! I want to use your binary_sensor for LWT inside my packages but whenever I add a binary_sensor
to a package, config fails. Sensors work fine. Anyone got any tricks?
Hi, if you are still having issues, I have a guide here on how to set up Sonoff Tasmota either through auto detection or MQTT.
Hey.
I have been struggling to manually(without using Auto-discovery) configure my Sonoff Basic, but after carefully studying GitHub wiki(wiki), i finally made it. I’m using Sonoff-Tasmota 6.4.1 and Home Assistant 0.85.1, so my configuration looks like:
/config/configuration.yaml:
switch: !include switch.yaml
/config/switch.yaml:
- platform: mqtt
name: “MY SONOFF”
command_topic: “tasmota/sonoff_basic/cmnd/POWER1”
state_topic: “tasmota/sonoff_basic/cmnd/POWER1”
qos: 1
payload_on: “ON”
payload_off: “OFF”
payload_available: “Online”
payload_not_available: “Offline”
retain: false
The code alignment is very important in yaml, so make sure you do the exact way as on my screenshoot
Note, that during Sonoff Basic MQTT configuration you should use the following:
Topic: sonoff_basic
Full Topic: tasmota/%topic%/%prefix%/
Hope it will help someone as me