Ok, I understand. But how can I send something to tasmota? Tasmota can also listen for topics, not only publish? If yes, how can I use a template for publishing to tasmota?
A sensor likely won’t subscribe (“listen too”) any topics except for the standard birth/will topics from other clients in the mqtt network.
A switch will both publish status topics to the MQTT broker but also subscribe to command topics from the broker to control it’s functions.
you will need to figure out what the command topics are for your particular tasmotized device in order to know what topic to publish the command to that the device uses and what the payload that will be to execute the command.
Tasmota has changed the standard status and command topic structure over time and it also has the ability to customize those topics so I can’t for sure say what the topic & payload will be.
But my couple of Tasomtized devices use the following example for configuration:
switch:
- platform: mqtt
name: "Garage Door South Op MQTT"
state_topic: "stat/s_gd_op/POWER"
command_topic: "cmnd/s_gd_op/POWER"
availability_topic: "tele/s_gd_op/LWT"
qos: 1
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
in there you can see the topics and payloads expected for my tasmotized switch.
in that example if I click on the switch in the front end to turn it on or call the switch.turn_on service for that switch then the system will publish “ON” to the command topic “cmnd/s_gd_op/POWER” to the broker (which the switch also subscribes to) and the switch is turned on. It will then send it’s updated status to the broker via the status topic “stat/s_gd_op/POWER” which HA subscribes to and HA knows what the new status of the switch is.
there is no “template” required.
In the case of the sensor you could do the same thing but sensors typically will send more information out in the status topic that you then need to extract the desired value from by using a template as you have in your example above.
But the template above is doing nothing but listening for info on the status topic then you are using the trigger state object to extract the desired value out of the delivered json string.
Just publish this payload “ZbSend {“Device”:“Computer_Heater”,“Write”:{“TuyaTempTarget”:1}}” to the topic and my device (which is a thermostat with switch), will set the temperature to the exact value. As far for the sensors, it is easy to read. I didn’t know how to send command. Thanks for your advices man, cya!