MQTT possible issues JSON transformation

I cannot seem to find an answer to my MQQT issue. I upgraded to Openhabian 2.5.0-1 Release Build with the built in MQQT broker from 2.4 and Mosquitto, now I am getting the following in my log:

==> /var/log/openhab2/openhab.log <==

2020-01-14 11:19:57.322 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command 'closed' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.closed

This did work before upgrading to 2.5. The item is:

Contact     MQQT_Basement_Door          "Basement Door [MAP(door.map):%s]"                      <door>              (gDoors, gPres_Basement, gBasement)     [ "OpenState", "Door" ] { channel="mqtt:topic:1d0d7733:28f72894", alexa="ContactSensor", synonyms="Basement Door" }

This is the ino file for the ESP-01 door contact I made:

#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
ADC_MODE(ADC_VCC);

//USER CONFIGURED SECTION START//
const char* ssid = "XXXXXX";
const char* password = "XXXXXX";
const char* mqtt_server = "10.0.1.25";
const int mqtt_port = 1883;
const char *mqtt_user = "openhabian";
const char *mqtt_pass = "XXXXX";
const char *mqtt_client_name = "Basement_Door"; // Client connections can't have the same connection name
const char *mqtt_topic = "House/Basement/Basement_Door";
IPAddress ip(10, 0, 1, 75); 
IPAddress gateway(10, 0, 1, 1); 
IPAddress subnet(255, 255, 255, 0);
//USER CONFIGURED SECTION END//

WiFiClient espClient;
PubSubClient client(espClient);

// Variables
bool boot = true;
char batteryVoltageMQTT[50];

//Functions

void setup_wifi() 
{
  WiFi.config(ip, gateway, subnet);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) 
    {
      delay(50);
    }
}

void reconnect() 
{
  while (!client.connected()) 
  {
      int battery_Voltage = ESP.getVcc() + 600;
      String temp_str = String(battery_Voltage);
      String mqttString = temp_str + "mV Replace Battery for basement door.";
      mqttString.toCharArray(batteryVoltageMQTT, mqttString.length() + 1);
      if (battery_Voltage <= 2900)
      {
        if (client.connect(mqtt_client_name, mqtt_user, mqtt_pass, mqtt_topic, 0, 1, batteryVoltageMQTT)) 
        {
        
          if(boot == true)
          {
            client.publish(mqtt_topic,"open");
            boot = false;
          }
        } 
        else 
        {
          ESP.restart();
        }
      }
      if (battery_Voltage > 2900)
      {
        if (client.connect(mqtt_client_name, mqtt_user, mqtt_pass, mqtt_topic, 0, 1, "closed")) 
        {
          if(boot == true)
          {
            client.publish(mqtt_topic,"open");
            boot = false;
          }
        } 
        else 
        {
          ESP.restart();
        }
      }
  }
}

void setup() 
{
  setup_wifi();
  client.setServer(mqtt_server, mqtt_port);
}

void loop() 
{
  
  if (boot == true) 
  {
    reconnect();
  }
  else
  {
  ESP.deepSleep(0);
  }
}

I use “open” and “closed” in the file, and by reading this error, do I have to re-flash the ESP-01 changing the ino file to “open” and “close”? Or is it possible to do a JSON transformation? If someone could point me in the right direction, I would appreciate it, MQQT is something that I can’t seem to wrap my head around.

~John

Typically one uses only one broker or the other. Which one are you using? I recommend that you use Mosquitto only as Moquette (the embedded broker) is apparently not maintained any more.

I’m surprised this ever worked. openHAB only understands “OPEN” and “CLOSED”, not “open” and “closed” for a Contact’s state.

You need to either change your ESP code to send all caps or you need to add a transformation or custom ON/OFF value to your MQTT Channel config.

Put open for the Custom On/Open Value and closed for the Custom Off/Closed Value.

Or set up an incoming transformation using the MAP transformation with a .map file that converts the lower case to upper case.

You are on your own if you are using .things files. I can’t/won’t help with those.

@rlkoshak,

Sorry it was confusing on how I typed that… I was using Openhabian 2.4 with the embedded broker and my setup was working properly. I recently upgraded to 2.5 release build with Mosquitto and I was getting those errors. Thanks for the help, changing the custom On/Open values to lowercase worked perfectly!

~John