MQTT, MySensors, OpenHab1 - Is this a rules issue?

I didn’t read the whole topic but 1 thing i learned is that mysensor is a beginners guide wich i go look to learn. I did the same but i programmed it in the arduino/esp8266 itself and not used the rules off openhab. Example of my code i use for a room with DHT11 temp sensor. I know there are still thing to adjust but lack of time with a newborn baby.

#include <ESP8266WiFi.h>
#include <MQTTClient.h>
#include <SimpleDHT.h>

long interval = 60000; //Tijd tussen interval T en rH doorsturen
unsigned long timer;

const char *ssid = " ";
const char *pass = " ";

const char *mqtt_server = "192.168.1.100";
const char *mqtt_sub = "openhab/Veranda/#";
const char *mqtt_pub_temp = "openhab/Veranda/Temp";
const char *mqtt_pub_hum = "openhab/Veranda/Hum";
const char *mqtt_pub_Schak1 = "openhab/Veranda/Schak1";
char *Schak1 = "OFF";
char *INIT = "NO";
int StandSchak1 = digitalRead(4);

const char *tPayload = "";
const char *hPayload = "";

unsigned long resetPeriod = 86400000; // ESP dagelijks herstarten, korter maken indien nodig

int pinDHT11 = 2;
SimpleDHT11 dht11;
byte temperature = 0;
byte humidity = 0;

WiFiClient net;

MQTTClient client;


// IO settings
void initialize() {
  pinMode (12, OUTPUT); // UITGANG 1
  digitalWrite (12, HIGH);
  pinMode (4 , INPUT_PULLUP);  // INGANG 1
  INIT = "YES";
  client.subscribe(mqtt_sub);
}

void connect() {
  Serial.print("checking wifi...");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1000);
  }

  Serial.print("\nconnecting...");
  while (!client.connect("arduino", "try", "try")) {
    Serial.print(".");
    delay(1000);
  }

  Serial.println("\nconnected!");

  client.subscribe(mqtt_sub);
}

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, pass);
  client.begin(mqtt_server, net);

  connect();
  timer = millis();
}


void loop() {
  client.loop();
  delay(10); // <- fixes some issues with WiFi stability

  // STARTUP, determine IO
  if (INIT == "NO") {
    initialize();
  }

  if (!client.connected()) {
    connect();
  }
  if (digitalRead(4) != StandSchak1)  // Controle verandering van schakelaar
  {
    if (Schak1 == "OFF")
    {
      client.publish(mqtt_pub_Schak1 , "ON");
    }
    else
    {
      client.publish(mqtt_pub_Schak1 , "OFF");
    }
    StandSchak1 = digitalRead(4);
  }
  if ((millis() - timer) > interval)  // Doorsturen T en rH
  {
    timer += interval;
    dht11.read(pinDHT11, &temperature, &humidity, NULL);
    int temperature1 = int(temperature);
    int humidity1 = int(humidity);
    client.publish(mqtt_pub_temp, String(temperature1));
    client.publish(mqtt_pub_hum, String(humidity1));
  }
  if (millis() > resetPeriod) // Herstarten ESP
  {
    ESP.restart();
  } 
}

// Handeling MQTT bericht ontvangen
void messageReceived(String topic, String payload, char * bytes, unsigned int length) {
  Serial.print("incoming: ");
  Serial.print(topic);
  Serial.print(" - ");
  Serial.print(payload);
  Serial.println();
  if (topic == mqtt_pub_Schak1)
  {
    if (payload == "ON")
    {
      digitalWrite (12, LOW);
      Schak1 = "ON";
    }
    else
    {
      digitalWrite (12, HIGH);
      Schak1 = "OFF";
    }
  }
}


I think i have cracked the issue with the designer firstly. It for some reason is attempting to use a 32 bit version of java, and because it isn’t on my system it can’t open. Is there a way to specify, maybe in the ini files or some sort of config file, what java fule to use?

No, it is compiled either for 64-bit or 32-bit. This isn’t configurable. But you can download the 64-bit version of Designer at least for Linux. It looks, based on the filename, that for OSX it only comes in 64-bit flavor.

http://www.openhab.org/getting-started/downloads.html

You either need to get a 64-bit version of Designer or install a 32-bit JRE.

I have gotten myself an install of Eclipse Smarthome Incubation designed, looks exactly the same, i think its just the shell that is different for OpenHab. I haven’t connected it to my OpenHab server yet but it seems alright.

I have no idea why its attempting to use a version of Java that i do not have then if you can’t manualy config where the java is located… Its clearly looking for a 32-bit version for some reason.

I will attempt to get this connected to my OpenHab server in short while.

I don’t know how well that will work. ESH and OH2 put things in different locations with some different formatting.

Because what you downloaded was the 32-bit version of Designer. It will only work with the 32-bit Java Runtime Environment. A Java program can only be one or the other, not both. There is nothing to manually config or any alternative place to point it to because there is only one Java that will work, the 32-bit version. The 32-bit version of Designer can only run on the 32-bit Java. With the 32-bit Java the 32-bit Designer can’t run.

So, as I said, you either need to download the 64-bit version of Designer or you need to install a 32-bit version of the JRE.

I have just downloaded a 32bit Oracle Java SE Runtime Environment Version 7 update 80, still not working.

I have just had a look at some information regarding using this Eclipse designer with OpenHab, and found a thread on this forum regarding it where Kai informs it should be okay to use.

I have just ran the ‘eclipsec.exe’ file and that opens the OpenHab designer, with a command prompt behind it. Interesting, this may point to a workspace being corrupted…

Perfect, working now. I deleted the workspace folder and ran the designer.exe file and now its working. There must have been a corrupted workspace. I will leave the messages above just so people can relate to this thread if they need it in case of theirs not working.

Back to the case of the config not working for my rules now though. The real work starts >.<

I’m sorry to push you through the pain of getting it to work, but it really is worth it. The errors that OH reports when there is a problem (and sometimes fail to report) makes finding simple syntax errors a time consuming and challenging prospect. Its much better to have Designer tell you its wrong even as you type it.

No, don’t be. I know how easy it is to make syntax errors, and i know how important it is to have designer in reality. However, when it broke last time i just gave up at that point, i had a lot of things going on and as real life slows down a little i’m now able to resume, thank you :slight_smile:

Is there any guides/documents out here that aids us through the use of designer? Its little things like a purple shaded box at the start of a line, what does that mean? Something to do with a match i remember reading, not sure.

Sadly it is one of the areas that is lacking documentation the most.

A quick and dirty bit of info (note: this is all relevant to openHAB Designer, not ESH’s version):

  • Press the little file folder in the upper left and browse to your openhab configurations folder. This will load your complete config
  • To save the currently opened file press <ctrl>s
  • To create a new file press <ctrl>n
  • To auto-complete the line you are currently typing press <ctrl><space>, it could take a few minutes for the dialog with valid completions to come up the first time
  • Yellow underlined lines are warnings (e.g. you have a val declared but never used)
  • Red underlined lines are errors
  • Light red underlined words are spelling errors (usually seen in Strings or comments)
  • In all of the underlined cases, hovering your mouse over the line or word will pop-up a dialog with what the error or warning is

I’ve never seen a purple line so don’t know if that is something new or something I’ve just never noticed.

Cool, thank you!

This is the purple shaded box at the start of the line in the Items folder that i was talking about:

I had a feeling that it was something had been edited since the last save took place, but i’m only guessing here. It seems to work like that in the other files but if i add something in, the box appears, if i remove it the box disappears, so i’m not too sure if it intelligent enough to recognize that the edit has been removed or not.

Ah, yes. That highlights which lines have been changed since the last save.

It is.

Would this item work for both sending ON/OFF commands and representing the state of the ceiling lights it controls?

Switch CinemaRoom_CeilingLights "Ceiling Lights" <light> (SF_CinemaRoom, gSwitch,gLight) {mqtt="<[mymosquitto:Gateway1-out/3/3/1/0/2:MAP(1on2off.map)], >[mymosquitto:Gateway1-in/4/1/1/0/2:command:ON:1], >[mymosquitto:Gateway1-in/4/1/1/0/2:command:OFF:0]"}

transform/1on2off.map (or whichever messages you publish to Gateway1-out/3/3/1/0/2):

1=ON
2=OFF

Are you asking this as a way for me to try this or are you asking RIch if it would work theoretically?

@rlkoshak - The lighting item in my items file is

Switch	CinemaRoom_Light01	"Ceiling Lights"			<light>		(SF_CinemaRoom, gLight)		{mqtt=">[mymosquitto:Gateway1-in/4/1/1/0/2:command:ON:1],>[mymosquitto:Gateway1-in/4/1/1/0/2:command:OFF:0]"}

Please correct me here if i’m wrong, for you to send a .postUpdate to an item, should it not be state rather than command in the items config?

I’m asking you if it meets your requirement to have a single item that takes ON/OFF commands, and also shows the current state of the ceiling lights, without needing any rules or other complex setup. But I forgot yesterday to add the important ingredient of autoupdate="false" to the binding config:

Switch CinemaRoom_CeilingLights "Ceiling Lights" <light> (SF_CinemaRoom, gSwitch,gLight) {mqtt="<[mymosquitto:Gateway1-out/3/3/1/0/2:MAP(1on2off.map)], >[mymosquitto:Gateway1-in/4/1/1/0/2:command:ON:1], >[mymosquitto:Gateway1-in/4/1/1/0/2:command:OFF:0]", autoupdate="false"}

I’ll be honest, i don’t care how the light is turned on. If it means having two items and a rule stating when item1 changes (when the light switch is pressed) then toggle item2 or if it means having them both on the one item, i really don’t mind. I have no use for the item i’ve assigned to the light switch other than to toggle the other item.

So it would make sense to have a single item represent the ceiling lights, taking both commands to turn it on and off, and showing the state of the lights. I suggest studying and trying my item definition, and eliminating unnecessary rules for coordinating one item with another item.

Would your method require any rules to work at all or is it just waiting for a command/state on both MQTT topics and then to perform accordingly?