First let's install the library IRremoteESP8266. For that go to Sketch | Include Library | Manage Libraries... and search for IRremoteESP8266 library like in the following screenshot:
After the library is installed and the connections to the ESP are done, let's use the following code to send over an MQTT topic a command to open or close a Panasonic TV. Since the same Infrared command is used to power on or power off, you just need to receive something on the MQTT topic to send an infrared command to the TV:
#include <ArduinoJson.h> #include <ESP8266WiFi.h> #include <ESP8266mDNS.h> #include <WiFiUdp.h> ...