Problem with Tasmota & MQTT Switches & Sensors

Hi all,

I’ve bought a Gosund SP1 smart plug which has a Tasmota firmware.

I’ve set up MQTT on Home Assistant and did the proper configuration to both the tasmota software on the plug as well as to the Mosquito MQTT.

Devices can also communicate with each other. I’ve tested this within the MQTT Integration configuration by listening to the topics:

e.g.
tele/steckdose/waschmaschine/SENSOR returns

{
    "Time": "2020-09-26T07:47:08",
    "ENERGY": {
        "TotalStartTime": "2020-09-26T06:38:12",
        "Total": 0.1,
        "Yesterday": 0,
        "Today": 0.1,
        "Period": 0,
        "Power": 0,
        "ApparentPower": 0,
        "ReactivePower": 0,
        "Factor": 0,
        "Voltage": 0,
        "Current": 0
    }
}

or stat/steckdose/waschmaschine/RESULT returns

{
    "POWER": "ON"
}

I’ve now try to put the power plug as switch and sensor to my configuration.yaml like following:

switch:
  - platform: mqtt
    name: "Steckdose Waschmaschine"
    state_topic: "stat/steckdose/waschmaschine/RESULT"  
    value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/steckdose/waschmaschine/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/steckdose/waschmaschine/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    retain: false

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'
  - platform: mqtt
    name: "Energy Today"
    state_topic: "tele/steckdose/waschmaschine/SENSOR"
    value_template: '{{ value_json["ENERGY"]["Today"] }}'
    unit_of_measurement: "kWh"
  - platform: mqtt
    name: "Power"
    state_topic: "tele/steckdose/waschmaschine/SENSOR"
    value_template: '{{ value_json["ENERGY"]["Power"] }}'
    unit_of_measurement: "W"
  - platform: mqtt
    name: "Voltage"
    state_topic: "tele/steckdose/waschmaschine/SENSOR"
    value_template: '{{ value_json["ENERGY"]["Voltage"] }}'
    unit_of_measurement: "V"
  - platform: mqtt
    name: "Current"
    state_topic: "tele/steckdose/waschmaschine/SENSOR"
    value_template: '{{ value_json["ENERGY"]["Current"] }}'
    unit_of_measurement: "A"

My problems are:

  1. The switch works fine to switch the power plug on, but it cannot be switched off. The switch in the home assistant UI immediately gets back to off state after switching it on. I guess something is wrong with the state topic, but I cannot figure out what.
  2. The sensors are not appearing within home assistant

Does anybody has any advice?

I haven’t had to diagnose too many issues with Tasmota to HA, so forgive me if this is wrong.

My topics are tele/device_name/HASS_STATE where your path is much, much longer.
I don’t know if you have changed your HA autodiscovery or something?

What Options did you use too?

Mmh. Thanks, but I would exclude this as a reason as the devices are in able to communicate with each other.

It’s just the configuration in the Tasmota software, %prefix%/%topic%/waschmaschine as full topic, steckdose as topic.

As you can see in the above log, house assistant receives result messages from the power plug when subscribing to the topic.

I just resolved the problem with the switch by changing to the STATE topic after looking on the Tasmota console:

07:46:05 MQT: stat/steckdose/waschmaschine/POWER = OFF
07:47:08 MQT: tele/steckdose/waschmaschine/STATE = {"Time":"2020-09-26T07:47:08","Uptime":"0T00:50:12","UptimeSec":3012,"Heap":29,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":24,"MqttCount":1,"POWER":"OFF","Wifi":{"AP":1,"SSId":"JackNetHighSpeed","BSSId":"3C:A6:2F:6E:AA:E1","Channel":6,"RSSI":54,"Signal":-73,"LinkCount":1,"Downtime":"0T00:00:06"}}

But I still don’t understand, why it does not work with the RESULT topic.

It remains the problem with the sensors, they don’t appear as entities. Nothing to see in the home assistant logs

The easiest way to get your sensor in HA is to use autodiscovery. Simple enter ‘setoption19 1’ in the Tasmota console.

I will give the auto-detection a try, but however, it also must work this way. I mean, what prevents the trigger from appearing in the home assistant. After adding the switch, it immediately was visible…

I used autodiscovery to pick up a number of Sonoff Minis on my HA set up.
Obviously I typed “SelectOption19 1” on the console and the devices turned up shown as “switch.sonoff_mini_1” along with a “sensor.sonoff_mini_1_status” which basically shows the RSSI. I was expecting to get a binary sensor too so that I could get other information.

On the Tasmota Git hub (https://tasmota.github.io/docs/Home-Assistant/) there is a bunch of information about SwitchMode and SwitchTopic. So I tried setting both of those to 1 on the console but it isn’t making any difference. I’m probably missing something really obvious but any help would be appreciated.

FWIW my automations are all running fine but I want something to put into my UI without writing YAML into the binarysensor file.

Looks like they were autodiscovered if I set the SwitchTopic to a text value AND deleted the device in HA configuration AND deleted then discovered the device in TasmoAdmin. Happy days :slight_smile:

1 Like