Sonoff issues

Hi,
I’ve flashed my sonoff basic with Tasmota FW and it’s working well with tasmo admin. I can turn it on/off with publishing a topic in the developer tools, but I can’t get it to work as a switch. Its either unavailable or not working correctly. If sonoff is turned off, it will turn it on, but switch will jump back to off position and thats it. I have the 6.1.0 version of the tasmota. My config:

mqtt:
broker: core-mosquitto
port: 1883
username: sirotkaslo
password: xxxxxx
discovery: true

switch:
  - platform: mqtt
    name: "Sonoff power"
    state_topic: "stat/sonoff/POWER"
    value_template: '{{ value_json["POWER"] }}'
    command_topic: "cmnd/sonoff/POWER"
    availability_topic: "tele/sonoff/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

Currently only using one sonoff basic, but will add more If I can get this one to work.
any help appreciated, thanks!

Can you format your code using the blue bar on top of the page?
I personally don’t use the value template and it works just fine…

also comparing your code and mine, it looks like you’re not using the name of your sonoff device in the MQTT topics?

I’ve edited my post.

sonoff is the name of my device, or do i need to change it even with just one sonoff present at the time?

state_topic: "stat/sonoff/basic/1/POWER"
what is the /1/ used for?
thanks

sonoff settings:

then you may need to change stat/sonoff/POWER to stat/sonoff/sonoff/POWER
Best is to check with an MQTT tool like mqtt.fx to see what gets published…

I got it to work, just had to add 1 to POWER, like this:

switch:
  - platform: mqtt
    name: "Sonoff power"
    state_topic: "stat/sonoff/POWER1"
    value_template: '{{ value_json["POWER1"] }}'
    command_topic: "cmnd/sonoff/POWER1"
    availability_topic: "tele/sonoff/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

I’ll add the second one today and hope it will also work. Thanks @lolouk44

1 Like

@lolouk44, do you see a blue box on top?

oh I see the bar has gone!
I’ll have to revise my “template answer”. would be nice to have it back and it does help code troubleshooting, especially with indentations

I saw the blue box earlier today and it had added a picture to show exactly how to use the </> (is that picture new? I hope so since I don’t remember seeing it before). But now I don’t see it on a different machine.

Yes the picture is new, check the link in @VDRainer 's last post
For your machine missing it, try and refresh / clear your cache and or cookies

Yeah, it’s back now.

I like it. I definitely think it will help trying to explain how to post code correctly.