MQTT Request ends in "Command Unknown"

This is my first “hack” project with a ceiling fan that has an RF frequency of 303.9. SO I used a D1 Mini and wired it to a spare remote. I’ve been able to manually send successful MQTT requests to the fan but all of my requests through the lovelace setup “below” end with MQT: stat/Office_Fan/RESULT = {“Command”:“Unknown”} in the Tasmota console. Could someone tell me what I’ve done wrong? Special thanks to Controller DC fans / Fan light combo - RF controlled for providing an example of how this could work.

#DC Fan Control
input_select:
  fan_office:
    name: Office fan
    icon: mdi:fan
    options:
      - 'Off'
      - 'One'
      - 'Two'
      - 'Three'
      - 'Four'
      - 'Five'
      - 'Six'
      
#Automations for Home Assitant
automation:
 - alias: 'Office Fan'
   trigger:
     - platform: state
       entity_id: input_select.fan_office
   action:
     - service: mqtt.publish
       data_template:
        topic: >-
         {% set topics = {'Off':'0,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510', 'One':'0,328,326,656,328,656,326,656,328,656,326,656,328,656,654,328,654,328,656,328,654,328,656,326,656,328,11472,328,326,656,328,656,326,656,328,656,326,656,328,656,654,328,654,328,656,328,654,328,656,326,656,328,11472,328,326,656,328,656,326,656,328,656,326,656,328,656,654,328,654,328,656,328,654,328,656,326,656,328,11472,328,326,656,328,656,326,656,328,656,326,656,328,656,654,328,654,328,656,328,654,328,656,326,656,328,11472', 'Two':'0,328,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,328,654,658,328,328,656,656,328,11476,328,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,328,654,658,328,328,656,656,328,11476,328,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,328,654,658,328,328,656,656,328,11476,328,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,328,654,658,328,328,656,656,328,11476', 'Three':'0,326,328,654,328,656,328,656,328,656,328,656,328,654,658,328,328,656,656,328,656,328,658,328,656,328,11502,326,328,654,328,656,328,656,328,656,328,656,328,654,658,328,328,656,656,328,656,328,658,328,656,328,11502,326,328,654,328,656,328,656,328,656,328,656,328,654,658,328,328,656,656,328,656,328,658,328,656,328,11502,326,328,654,328,656,328,656,328,656,328,656,328,654,658,328,328,656,656,328,656,328,658,328,656,328,11502','Four':'0,328,328,656,328,656,328,656,328,656,328,656,328,656,658,328,328,656,328,656,658,328,658,328,658,328,11522,328,328,656,328,656,328,656,328,656,328,656,328,656,658,328,328,656,328,656,658,328,658,328,658,328,11522,328,328,656,328,656,328,656,328,656,328,656,328,656,658,328,328,656,328,656,658,328,658,328,658,328,11522,328,328,656,328,656,328,656,328,656,328,656,328,656,658,328,328,656,328,656,658,328,658,328,658,328,11522', 'Five':'0,326,328,656,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,656,328,328,656,656,328,11506,326,328,656,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,656,328,328,656,656,328,11506,326,328,656,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,656,328,328,656,656,328,11506,326,328,656,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,656,328,328,656,656,328,11506', 'Six':'0,328,328,654,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,656,328,658,328,11510,328,328,654,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,656,328,658,328,11510,328,328,654,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,656,328,658,328,11510,328,328,654,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,656,328,658,328,11510'} %}
         cmnd/Office_Fan/irsend{{ topics[trigger.to_state.state] if trigger.to_state.state in topics.keys() else 'unknown' }}
         payload: ""

I’ve used irrecv to sniff the codes from the remote and now I’m using irsend to hijack the remote’s 303.9 crystal. It works really well, I just can’t get it to interface with HA.

The topics look like this??

cmnd/Office_Fan/irsend0,328,328,654,328,656,328,656,328,656,328,656,328,656,328,656,etc

Because that’s what the template generates. I would think the sequence of numbers would go in the payload.

When I type irsend 0,328,328,654,328, etc into the console in Tasmota it works as intended. When I type the below in the mqtt.publish on the HA developer tools services it works as intended. Something is off with my syntax or I’m just not getting my head around it.

topic: "cmnd/Office_Fan/irsend"
payload: '0,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510'

So do I just do this?

automation:
 - alias: 'Office Fan'
   trigger:
     - platform: state
       entity_id: input_select.fan_office
   action:
     - service: mqtt.publish
       data_template:
        topic: >-
         {% set topics = {'Off':'0,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510,326,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,658,328,328,656,658,328,11510', 'One':'0,328,326,656,328,656,326,656,328,656,326,656,328,656,654,328,654,328,656,328,654,328,656,326,656,328,11472,328,326,656,328,656,326,656,328,656,326,656,328,656,654,328,654,328,656,328,654,328,656,326,656,328,11472,328,326,656,328,656,326,656,328,656,326,656,328,656,654,328,654,328,656,328,654,328,656,326,656,328,11472,328,326,656,328,656,326,656,328,656,326,656,328,656,654,328,654,328,656,328,654,328,656,326,656,328,11472', 'Two':'0,328,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,328,654,658,328,328,656,656,328,11476,328,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,328,654,658,328,328,656,656,328,11476,328,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,328,654,658,328,328,656,656,328,11476,328,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,328,654,658,328,328,656,656,328,11476', 'Three':'0,326,328,654,328,656,328,656,328,656,328,656,328,654,658,328,328,656,656,328,656,328,658,328,656,328,11502,326,328,654,328,656,328,656,328,656,328,656,328,654,658,328,328,656,656,328,656,328,658,328,656,328,11502,326,328,654,328,656,328,656,328,656,328,656,328,654,658,328,328,656,656,328,656,328,658,328,656,328,11502,326,328,654,328,656,328,656,328,656,328,656,328,654,658,328,328,656,656,328,656,328,658,328,656,328,11502','Four':'0,328,328,656,328,656,328,656,328,656,328,656,328,656,658,328,328,656,328,656,658,328,658,328,658,328,11522,328,328,656,328,656,328,656,328,656,328,656,328,656,658,328,328,656,328,656,658,328,658,328,658,328,11522,328,328,656,328,656,328,656,328,656,328,656,328,656,658,328,328,656,328,656,658,328,658,328,658,328,11522,328,328,656,328,656,328,656,328,656,328,656,328,656,658,328,328,656,328,656,658,328,658,328,658,328,11522', 'Five':'0,326,328,656,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,656,328,328,656,656,328,11506,326,328,656,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,656,328,328,656,656,328,11506,326,328,656,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,656,328,328,656,656,328,11506,326,328,656,328,656,328,656,328,656,328,656,328,656,328,656,656,328,656,328,656,328,328,656,656,328,11506', 'Six':'0,328,328,654,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,656,328,658,328,11510,328,328,654,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,656,328,658,328,11510,328,328,654,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,656,328,658,328,11510,328,328,654,328,656,328,656,328,656,328,656,328,656,328,656,658,328,656,328,658,328,656,328,658,328,11510'} %}
         cmnd/Office_Fan/irsend
         payload: '{{ topics[trigger.to_state.state] if trigger.to_state.state in topics.keys() else 'unknown' }}'

The entire template you created belongs in payload.

The only thing you need in topic is:

cmnd/Office_Fan/irsend

The topic represents the destination and the payload is what’s being sent there.