Cannot get my head around MQTT Publish and IRSend Command of complex string

Hello All,

Posting this as a last straw before I go to bed and dream about the hair I wish I still had after I’ve just pulled out of my head trying to figure this issue out. I have mqtt publish commands set up pretty well for simple strings but I am trying to send a more complex one as a POC for an IR Blaster I have.

I captured the IR code to turn off the TV easy enough. I run the following command just perfectly from the console of the Tasmota-IR flashed device:

IRSend {"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E040BF","DataLSB":"0x070702FD","Repeat":0}

My console output is this:

15:29:38 CMD: IRSend {"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E040BF","DataLSB":"0x070702FD","Repeat":0}
15:29:38 MQT: stat/mirgen_ir_livingroom/RESULT = {"IRSend":"Done"}

TV turns off - perfect.

However, I cannot for the life of me find how to turn that into a script that I can call in HA. My latest effort (which does not work) is this:

data:
  payload: >-
    {"Protocol":"SAMSUNG", "Bits":32, "Data":"0xE0E040BF",
    "DataLSB":"0x070702FD", "Repeat":0}
  topic: tele/mirgen_ir_livingroom/IRSend
service: mqtt.publish

Would someone please mind casting an eye over this to see what I might be doing wrong?

I appreciate the time in advance.

  action:
  - data:
      payload: '{"Protocol":"SAMSUNG", "Bits":32, "Data":"0xE0E040BF", "DataLSB":"0x070702FD", "Repeat":0}'
      topic: cmnd/mirgen_ir_livingroom/IRsend
    service: mqtt.publish

Hello,

I know this was from a few months ago. I’m having the exact same issue. Did the code provided by francisp solve this issue?

Just confirming I should place this code was placed under scripts.yaml?

Thanks,

Brad

From the docs,

payload must be a string. If you want to send JSON then you need to format/escape it properly. Like:

topic: home-assistant/light/1/state
payload: "{\"Status\":\"off\", \"Data\":\"something\"}"

I don’t think Tasmota needs a json, for me it works fine the way I posted some messages above.

Hello,

Just follwoing up on what I ended up putting into the scripts.yaml file.

Here are some samples below.

lounge_tv_off:
  alias: Lounge TV Off
  mode: single
  sequence:
  - data_template:
      payload: '{"Protocol":"PANASONIC","Bits":48,"Data":"0x40040100FCFD","DataLSB":"0x022080003FBF","Repeat":3}'
      topic: cmnd/IR-Lounge/IRsend
    service: mqtt.publish
lounge_tv_on:
  alias: Lounge TV On
  mode: single
  sequence:
  - data_template:
      payload: '{"Protocol":"PANASONIC","Bits":48,"Data":"0x400401007C7D","DataLSB":"0x022080003EBE","Repeat":3}'
      topic: cmnd/IR-Lounge/IRsend
    service: mqtt.publish
lounge_tv_mute:
  alias: Lounge TV Mute
  mode: single
  sequence:
  - data_template:
      payload: '{"Protocol":"PANASONIC","Bits":48,"Data":"0x400401004C4D","DataLSB":"0x0220800032B2","Repeat":0}'
      topic: cmnd/IR-Lounge/IRsend
    service: mqtt.publish
1 Like

Nice write up. Thanks for following up. Mine ended up similar.