Send specific message to MQTT - MAP problem

Hi everyone!

I have a problem, I’m trying to control my air conditioner by sending an infrared signal from my ESP8266 and controlling it via MQTT.

The problem I have is that, as you can see below, my arduino code receives “ON”-“OFF” command to turn on or off the air but the switch I have in my OpenHAB sends 0 or 1, I have tried to use the MAP transformation in several conbinations but without success, I can’t get OpenHAB to send ON or OFF to my ESP8266

My initial setup is:

Arduino

#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char* ssid = "xxx";
const char* password = "xxxx";
const char* mqtt_server = "xxxx";
const uint16_t kIrLed = 4;

IRsend irsend(kIrLed);
WiFiClient espClient;
PubSubClient client(espClient);

uint16_t TEMP17[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP18[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP19[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP20[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP21[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP22[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP23[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP24[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 4497, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP25[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP26[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP27[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP28[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP29[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 4497, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t TEMP30[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t Off[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433};
uint16_t On[199] = {4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 5298, 4269, 4497, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 654, 433, 654, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 654, 433, 1732, 433, 1732, 433, 1732, 433};
 
void setup() {
  pinMode(BUILTIN_LED, OUTPUT);
 // digitalWrite(BUILTIN_LED, HIGH);
  irsend.begin();
//#if ESP8266
 // Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
//#else  // ESP8266
  //Serial.begin(115200, SERIAL_8N1);
//#endif  // ESP8266
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  }

void setup_wifi() {
  delay(10);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("WiFi connected - ESP IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(String topic, byte* message, unsigned int length) {
  Serial.print("Message arrived on topic: ");
  Serial.print(topic);
  Serial.print(". Message: ");
  String messageTemp;
  int i=0;
  for (i = 0; i < length; i++) {
    Serial.print((char)message[i]);
    messageTemp += (char)message[i];
  }
  Serial.println();
  
  if(topic=="esp1/habitacion/aire"){
      Serial.print("Estado del aire: ");
      if(messageTemp == "ON"){
        irsend.sendRaw(On, 199, 38);
        Serial.print("Encendido");
        client.publish("esp1/habitacion/aire/state","ON");
      }
      else if(messageTemp == "OFF"){
        irsend.sendRaw(Off, 199, 38);
        Serial.print("Apagado");
        client.publish("esp1/habitacion/aire/state","OFF");
      }
  }

  if(topic=="esp1/habitacion/aire/temperatura"){
      Serial.print("Temperatura del aire: ");
      if(messageTemp == "17"){
        irsend.sendRaw(TEMP17, 199, 38);
        Serial.print("17º C");
        client.publish("esp1/habitacion/aire/temperatura/state","17");
      }
      else if(messageTemp == "18"){
        irsend.sendRaw(TEMP18, 199, 38);
        Serial.print("18º C");
        client.publish("esp1/habitacion/aire/temperatura/state","18");
      }
      else if(messageTemp == "19"){
        irsend.sendRaw(TEMP19, 199, 38);
        Serial.print("19º C");
        client.publish("esp1/habitacion/aire/temperatura/state","19");
      }
      else if(messageTemp == "20"){
        irsend.sendRaw(TEMP20, 199, 38);
        Serial.print("20º C");
        client.publish("esp1/habitacion/aire/temperatura/state","20");
      }
      else if(messageTemp == "21"){
        irsend.sendRaw(TEMP21, 199, 38);
        Serial.print("21º C");
        client.publish("esp1/habitacion/aire/temperatura/state","21");
      }
      else if(messageTemp == "22"){
        irsend.sendRaw(TEMP22, 199, 38);
        Serial.print("22º C");
        client.publish("esp1/habitacion/aire/temperatura/state","22");
      }
      else if(messageTemp == "23"){
        irsend.sendRaw(TEMP23, 199, 38);
        Serial.print("23º C");
        client.publish("esp1/habitacion/aire/temperatura/state","23");
      }
      else if(messageTemp == "24"){
        irsend.sendRaw(TEMP24, 199, 38);
        Serial.print("24º C");
        client.publish("esp1/habitacion/aire/temperatura/state","24");
      }
      else if(messageTemp == "25"){
        irsend.sendRaw(TEMP25, 199, 38);
        Serial.print("25º C");
        client.publish("esp1/habitacion/aire/temperatura/state","25");
      }
      else if(messageTemp == "26"){
        irsend.sendRaw(TEMP26, 199, 38);
        Serial.print("26º C");
        client.publish("esp1/habitacion/aire/temperatura/state","26");
      }
      else if(messageTemp == "27"){
        irsend.sendRaw(TEMP27, 199, 38);
        Serial.print("27º C");
        client.publish("esp1/habitacion/aire/temperatura/state","27");
      }
      else if(messageTemp == "28"){
        irsend.sendRaw(TEMP28, 199, 38);
        Serial.print("28º C");
        client.publish("esp1/habitacion/aire/temperatura/state","28");
      }
      else if(messageTemp == "29"){
        irsend.sendRaw(TEMP29, 199, 38);
        Serial.print("29º C");
        client.publish("esp1/habitacion/aire/temperatura/state","29");
      }
      else if(messageTemp == "30"){
        irsend.sendRaw(TEMP30, 199, 38);
        Serial.print("30º C");
        client.publish("esp1/habitacion/aire/temperatura/state","30");
      }
  } 
  
  Serial.println();
}

void reconnect() {
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    if (client.connect("ESP8266Client")) {
      Serial.println("connected");  
      client.subscribe("esp1/habitacion/aire");
      client.subscribe("esp1/habitacion/aire/temperatura");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      delay(5000);
    }
  }
}


void loop() {
    if (!client.connected()) {
    reconnect();
  }
  if(!client.loop())
    client.connect("ESP8266Client");
}

.things

Bridge mqtt:broker:mosquitto "Mosquitto" @ "System" [ host="192.168.0.15", secure=false ]
{	
    Thing topic aireacondicionado "Aire" {
        Channels:
            Type switch : aireonoff [  commandTopic="esp1/habitacion/aire"
                                   // transformationPattern="MAP:ONOFF.map"
                                    //retained=true,
                                    stateTopic="esp1/habitacion/aire/state"
                                    //
                                    ]
            Type string : aireonoffstate [  stateTopic="esp1/habitacion/aire/state"]
}}

.items

Switch  Aireprueba  {channel="mqtt:topic:mosquitto:aireacondicionado:aireonoff"}
String  Airepruebastate {channel="mqtt:topic:mosquitto:aireacondicionado:aireonoffstate"}

Note: I’ve deleted the transformation and other alternatives I tried to simplify a bit.

Are you using MQTT explorer to check what commands are passed to and from the broker?

It is a c++ question I might be able to help you out.

1 Like

just have a look this is out one of my mqtt.things

  Type switch : light                              "Spare_Bedroom"                          [ stateTopic="SpaarKamer/relay/0", commandTopic="SpaarKamer/relay/0/set", transformationPattern="MAP:OFF0ON1.map" , on="ON", off="OFF" , 1="ON" , 0="OFF" , ON="1" , OFF="0" ]

OR

Thing topic master_bed "MasterBedroom"{
    Channels:
    Type switch : lamp                              "Main_Light"                [ stateTopic="HoofSlaapKamer/relay/0", commandTopic="HoofSlaapKamer/relay/0/set" , transformationPattern="MAP:OFF0ON1.map" , on="ON", off="OFF" , 1="ON" , 0="OFF" ]
    Type switch : downlight                         "downlight"                 [ stateTopic="HoofSlaapKamer/relay/1", commandTopic="HoofSlaapKamer/relay/1/set" , transformationPattern="MAP:OFF0ON1.map" , on="ON", off="OFF" , 1="ON" , 0="OFF" ]
    Type number : temp                              "MasterBedroom Temp"        [ stateTopic="HoofSlaapKamer/Temperature"] 
    Type number : humi                              "MasterBedroom Humidity"    [ stateTopic="HoofSlaapKamer/Humidity"]
    Type switch : Fan_Light                         "Fan on/off"                [stateTopic="stat/Masterbedroom-Fan/POWER1", commandTopic="cmnd/Masterbedroom-Fan/power"]
    Type number : Fan_SPD                           "Fan Speed"                 [stateTopic="stat/Masterbedroom-Fan/RESULT", commandTopic="cmnd/Masterbedroom-Fan/FanSpeed", transformationPatter="JSONPATH($.FanSpeed):(*)"]
    
 }

Might help you.

Hi,

Maybe you could add on=“ON”,off=“OFF” in your channel configuration?

Like this:

Type switch : aireonoff [ commandTopic="esp1/habitacion/aire",
stateTopic="esp1/habitacion/aire/state",
on="ON",
off="OFF"
  ]

See: https://www.openhab.org/addons/bindings/mqtt.generic/#channel-type-contact-switch
And
https://www.openhab.org/v2.4/addons/bindings/mqtt.generic/#full-example

1 Like