Problems set switch mqtt on mp3 in nodemcu with tasmota

First I apologize for not knowing English and having to use the Google translator.
I have added an mp3 player to a nodemcu with tasmota to send sound messages in my hassio, but since I am new to everything: hassio, programming, mqtt. I got stuck and I do not know how to configure it, to reproduce the sound in the nodmcu I have to send the topic: cmnd / music / MP3Play and to stop it cmnd / music / MP3Stop, then I have configured the following mqtt switch in my configuration.yaml

  • platform: mqtt
    name: “MP3”
    command_topic: “cmnd/musica”
    payload_on: “MP3Play”
    payload_off: “MP3Stop”

I get an error and I do not know how to continue.
What do I do wrong?

One step at a time. What error are you getting?

You said:

but in your config you say:

Have you installed an MQTT tool like MQTTBox or something similar that lets you send and monitor MQTT messages?

I would first get the player to respond to the MQTT messages through MQTTBox, then add the working commands to Home Assistant.

Now, I am interested in the MP3 player you have on the NodeMCU. Tell me more about it.

I followed this link:

and it works, if through the browser I connect and in the console I send the MP3Play command the nodemcu plays the sound, but I do not know how to send it through the home assistant

I am confused. What is the full publish line you are entering into the console? It should be something like,

publish cmnd/musica MP3Play

Steve

in the tasmota console you just have to put MP3Play

I made a scrip and I act it with:

  • service: mqtt.publish
    data:
    “topic”: "cmnd/musica/MP3Play

and works, the problem is that I want to use it as an alarm clock and I need a switch to turn it off or postpone it and for that it’s switch mqtt

Try this for an idea:

I am confused. What is the full publish line you are entering into the console? It should be something like,

publish cmnd/musica MP3Play

#MQTT Switches
  - platform: mqtt
    name: "MP3 Player On"  
    command_topic: "cmnd/musica"
    state_topic: "stat/musica"
    qos: 1
    payload_on: "MP3Play"
    momentary: 300

  - platform: mqtt
    name: "MP3 Player Off"  
    command_topic: "cmnd/musica"
    state_topic: "stat/musica"
    qos: 1
    payload_on: "MP3Stop"
    momentary: 300

I haven’t tried the momentary parameter yet, I just recently discovered it in another thread.
This should give you one momentary switch to turn on the player and another to turn it off. The parameter for momentary is in ms.

if I apply your configuration does not work it appears in the tasmota:
image

I just tried this with a NodeMCU running Tasmota. The state_topic is required to make a switch on the front-end. It works. I have two buttons, NodeMCU Light ON and OFF. If I click on the ON switch, the light on the NodeMCU turns on, and 0.3 seconds later, the switch turns itself off, but the light stays on.

  - platform: mqtt
    name: "NodeMCU Light ON"  
    command_topic: "cmnd/sonoff/POWER"
    state_topic: "/stat/sonoff/POWER"
    payload_on: "on"
    momentary: 300

  - platform: mqtt
    name: "NodeMCU Light OFF"  
    command_topic: "cmnd/sonoff/POWER"
    state_topic: "/stat/sonoff/POWER"
    payload_on: "off"
    momentary: 300

I can not explain either because it does not work

Did you change the default topics in Tasmota?

image

not the only thing I’ve put is the name of the topic as musica

I use the tasmota wiki commands

In that case, try changing the topics like this:

command_topic: "cmnd/musica/POWER"
state_topic: "stat/musica/POWER"

and show more of the console lines after the publish cmnd

pressing the two switches out this:

I am not seeing the cmnd/ lines

I have reset the nodmcu to see this:

You should see the cmnd lines with every press of the switch.

You really need an MQTT tool, like the MQTTbox I mentioned before. It will show you what messages are being published. You can also find an MQTT app for your phone. I use MyMqtt for my android.

I am going offline for a few hours, but I would isolate where the problem is. Use MQTTBox to publish the MP3Play and MP3Stop messages. Once you have that working, you will then know exactly what the switch command_topic should be.

Also, some versions of Tasmota (at least here) are case sensitive whether the command topic is ‘power’ or ‘POWER’.

You said that you were able to send play and stop from the console? Monitor # on MQTTBox and see what the topic and message are. (# is the MQTT wild card. # will show you every message going through your broker).

Hope this helps.

I have installed the mqttbox but it will take me a while to learn how to use it