Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. A very beginner needs help - MySensors and OpenHab !

A very beginner needs help - MySensors and OpenHab !

Scheduled Pinned Locked Moved My Project
43 Posts 7 Posters 28.0k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ewgor
    wrote on last edited by
    #1

    Hi all,
    First off all i want you to know that i am a very beginner in this field as probably some of the people here on this community and not only.
    I'm struggling for more than 1 month to get my Openhab server (installed on my laptop) up and running well, showing me my DHT11 temp and humid. and a few relays with buttons actuators but it was impossible reading a lot of topics and trying a lot of examples. I was following this thread here http://forum.mysensors.org/topic/655/serial-gateway-connection-to-openhab/68 but i cant make it work.
    Can anyone here in this big community please share with us an example of Openhab server (items, rules, sitemap) and a Serial or Ethernet gateway with the Arduino code for the node point for a DHT sensor and a few relays with button actuators? as for example @l153 wrote this nice Openhab server on the same link above.

    To share your work doesn't mean you work for some other lazy geeks who just wait something ready to go.
    Sharing your knowledge means you help a novice understand the principle and maybe to develop his own project.

    Thanks for understanding and hopping to see my "small home automation dream" come true.

    Best regards.

    1 Reply Last reply
    0
    • greglG Offline
      greglG Offline
      gregl
      Hero Member
      wrote on last edited by
      #2

      Hi ewgor,

      Perhaps post about what you cant get working?
      Can you get your sensors/actuators communicating to a mysensors gateway?
      Or is it that you are having trouble getting OpenHab to work/see your mysensors gateway?

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ewgor
        wrote on last edited by ewgor
        #3

        Hi gregl,
        Thanks for reply. As i said above, i was following @TimO example from here http://forum.mysensors.org/topic/655/serial-gateway-connection-to-openhab/68 where i found the serial gateway and the node Arduino sketches and now i can display the temp and humid with this OpenHab configuration from here http://forum.mysensors.org/topic/1194/tutorial-openhab-with-serial-gateway.
        The problem is that I don't know how to make a Arduino sketch or some rules in OpenHab, I'm just trying to combine some different parts written by others and to see if its working or not.

        At this point there are 2 things that i would like to add:

        1. some rules in the OpenHab configuration for 2 switches and the Arduino sketch part for these switches. The switches must be operated from the physical buttons too and i saw here on MySensors that it can be done with this relay with button actuators.
        2. some rules for a SCT sensor and the Arduino sketch. I tried to adapt the temp and humid rules for the SCT sensor but i don't know if its ok like this, please see bellow. The bold rules are adapted by me:
          "if(msgType == 1 ){
          if (subType == V_TEMP){
          postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
          println ("Temp item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " temp: " + msg )
          }
          if (subType == V_HUM){
          postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
          println ("Hum item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " hum: " + msg )
          }
          if (subType == V_ELEC){
          postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
          println ("Elec item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " elec: " + msg )
          }

          } "
          Thanks for any reply.
        1 Reply Last reply
        0
        • E Offline
          E Offline
          ewgor
          wrote on last edited by ewgor
          #4

          Hi All,

          I'm still struggling to develop my project and to add 2 pcs switches and 1 pcs SCT-013-000 sensor but no positive result at the present moment ...
          My modified files are as follows:
          OPENHAB items:

          String Arduino "Arduino" { serial="COM4@115200" }
          Number          livingTemp01                            "Temperatura [%.1f °C]" <temperature> 
          Number          livingHum01                             "Umiditate [%.1f %%]" <water>
          Number          livingKwh01                             "Consum Electric [%.1f kWh]" <energy>
          
          

          OPENHAB rules:

          import org.openhab.core.library.types.*
          import org.openhab.core.persistence.*
          import org.openhab.model.script.actions.*
          import org.joda.time.*
          import java.util.*
          import org.eclipse.xtext.xbase.lib.*
          import org.openhab.core.items.*
          
          
          var String ArduinoUpdate = ""
          var String sketchName = ""
          
          var int V_TEMP = 0
          var int V_HUM = 1
          var int V_LIGHT = 2
          var int V_DIMMER = 3
          var int V_PRESSURE = 4
          var int V_FORECAST = 5
          var int V_RAIN = 6
          var int V_RAINRATE = 7
          var int V_WIND = 8
          var int V_GUST = 9
          var int V_DIRECTION = 10
          var int V_UV = 11
          var int V_WEIGHT = 12
          var int V_DISTANCE = 13
          var int V_IMPEDANCE = 14
          var int V_ARMED = 15
          var int V_TRIPPED = 16
          var int V_WATT = 17
          var int V_KWH = 18
          var int V_SCENE_ON = 19
          var int V_SCENE_OFF = 20
          var int V_HEATER = 21
          var int V_HEATER_SW = 22
          var int V_LIGHT_LEVEL = 23
          var int V_VAR1 = 24
          var int V_VAR2 = 25
          var int V_VAR3 = 26
          var int V_VAR4 = 27
          var int V_VAR5 = 28
          var int V_UP = 29
          var int V_DOWN = 30
          var int V_STOP = 31
          var int V_IR_SEND = 32
          var int V_IR_RECEIVE = 33
          var int V_FLOW = 34
          var int V_VOLUME = 35
          var int V_LOCK_STATUS = 36
          var int V_DUST_LEVEL = 37
          var int V_VOLTAGE = 38
          var int V_CURRENT = 39
          var int msgPresentation = 0
          var int msgSet = 1
          var int msgReq = 2
          var int msgInternal = 3
          var int msgStream = 4
          var int alarmArmor = 1
          
          // Internal Commands
          
          var int I_BATTERY_LEVEL = 0
          var int I_TIME = 1
          var int I_VERSION = 2
          var int I_ID_REQUEST = 3
          var int I_ID_RESPONSE = 4
          var int I_INCLUSION_MODE = 5
          var int I_CONFIG = 6
          var int I_FIND_PARENT = 7
          var int I_FIND_PARENT_RESPONSE = 8
          var int I_LOG_MESSAGE = 9
          var int I_CHILDREN = 10
          var int I_SKETCH_NAME = 11
          var int I_SKETCH_VERSION = 12
          var int I_REBOOT = 13
          var int I_GATEWAY_READY = 14
          
          // Mappings
          var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
              "101;0;"            -> "livingHum01",
              "livingHum01"       -> "101;0;",
          	"101;4;"            -> "livingKwh04",
              "livingKwh04"       -> "101;4;",
              "101;1;"            -> "livingTemp01",
              "livingTemp01"      -> "101;1;"
          	"101;2;" 			-> "lightBar02", 
              "lightBar02" 		-> "101;2;",
          	"101;3;"            -> "lightKitchenCabinet03", 
              "lightKitchenCabinet03" -> "10;3;",
          )
              
          
          //receiving msg from mysensors gateway
          rule "Arduino sends to Openhab"
              when
                  Item Arduino received update
              then
                  var String lineBuffer =  Arduino.state.toString.split("\n")
                  for (String line : lineBuffer) {
                      var String[] message = line.split(";")
                      var Integer nodeId = new Integer(message.get(0))
                      var Integer childId = new Integer(message.get(1))
                      var Integer msgType = new Integer(message.get(2))
                      var Integer ack = new Integer(message.get(3))
                      var Integer subType = new Integer(message.get(4))
                      var String msg = message.get(5)
                      if(msgType == 1 ){
                          if (subType == V_TEMP){
                              postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                              println ("Temp item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " temp: " + msg )
                              }
                          if (subType == V_HUM){
                              postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                              println ("Hum item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " hum: " + msg )
                              }
          				if (subType == V_KWT){
                              postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                              println ("Kwt item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " kwt: " + msg )
                              }
          				if (subType == V_LIGHT){
                              var String state
                              var Integer statusInt = new Integer(message.get(5))
                              if(statusInt == 1) { 
                                  state = "ON"
                                  } 
                              else { 
                                  state = "OFF" 
                                  }
                              postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), state)
                              println ("Light Item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Light: " + state )
                              }
                          }    
                      // Internal Command
                      if(msgType == 3){
                          if(subType == I_SKETCH_NAME){
                                  println("Sketch name: " + msg )
                                  sketchName=msg
                              }
                          if(subType == I_SKETCH_VERSION){
                                  println("Sketch version: " + msg )
                                  postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), sketchName+" " +msg )
                                  sketchName=""
                              }
                          }
                      }   
                  }
          end
          rule "lightBar04 Switch Rule"
              when
                  Item lightBar04 changed
              then
                  switchOperation.apply(lightBar04, Arduino, sensorToItemsMap.get("lightBar04"), V_LIGHT)         
          end 
          
          rule "lightKitchenCabinet00 Switch Rule"
              when
                  Item lightKitchenCabinet00 changed
              then
                  switchOperation.apply(lightKitchenCabinet00, Arduino, sensorToItemsMap.get("lightKitchenCabinet00"), V_LIGHT)           
          end
          

          OPENHAB sitemap:

          sitemap demo label="Acasa"
          {
            Frame label="Dormitor" {
              Text item=livingTemp01
              Text item=livingHum01
          	Text item=livingKwh01
            }
             Frame label="Lights" {
                  Group item=kLights label="Lights" {
                      Switch item=lightBar04 label="Bar Lights"
                      Switch item=kcLights label="Cabinet Lights"
                  }
              }
          

          Arduino node point sketch:

          // Example sketch showing how to control physical relays. 
          // This example will remember relay state even after power failure.
          
          #include <MySensor.h>
          #include <SPI.h>
          #include <DHT.h>
          #include "EmonLib.h"             // Include Emon Library
          EnergyMonitor emon1;  
          
          #define NODE_ID 101
          #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
          #define NUMBER_OF_RELAYS 2 // Total number of attached relays
          #define RELAY_ON 1  // GPIO value to write to turn on attached relay
          #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
          
          #define CHILD_ID_HUM 0
          #define CHILD_ID_TEMP 1
          #define CHILD_ID_WATT 17
          #define CHILD_ID_KWH 18
          #define HUMIDITY_SENSOR_DIGITAL_PIN 12
          unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
          unsigned long lastSend;
          unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
          MySensor gw(48, 49);
          
          DHT dht;
          
          float lastTemp;
          float lastHum;
          boolean metric = true; 
          
          MyMessage msgHum(CHILD_ID_HUM, V_HUM);
          MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
          MyMessage IrmsMsg(CHILD_ID_WATT,V_WATT);
          MyMessage kWhMsg(CHILD_ID_KWH,V_KWH);
          
          unsigned long lastCheckTime = millis();
          
          void setup()  
          {   
            // Initialize library and add callback for incoming messages
            gw.begin(incomingMessage, NODE_ID, true);
            // Send the sketch version information to the gateway and Controller
            gw.sendSketchInfo("Relay", "1.0");
            gw.sendSketchInfo("Energy Meter", "1.0");  // Send the sketch version information to the gateway and Controller
            gw.present(CHILD_ID_KWH, S_POWER);  // Register this device as power sensor
            emon1.current(A0, 29.0);       // Current: input pin, calibration.
          
            // Fetch relay status
            for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
              // Register all sensors to gw (they will be created as child devices)
              gw.present(sensor, S_LIGHT);
              // Then set relay pins in output mode
              pinMode(pin, OUTPUT);   
              // Set relay to last known state (using eeprom storage) 
              //digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
              digitalWrite(pin, RELAY_OFF);
            }
            
            dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
            // Register all sensors to gw (they will be created as child devices)
            gw.present(CHILD_ID_HUM, S_HUM);
            gw.present(CHILD_ID_TEMP, S_TEMP);
            
            //metric = gw.getConfig().isMetric;
          }
          
          
          void loop() 
          {
            // Alway process incoming messages whenever possible
            gw.process();
            updateHumidityTemp();
            unsigned long now = millis();
            //emon1.serialprint();           // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
            double Irms = emon1.calcIrms(1480);
            bool sendTime = now - lastSend > SEND_FREQUENCY;
            if (sendTime) {
              gw.send(IrmsMsg.set((Irms*232.0)*1000, 1));
          //    Serial.print("Watt: ");
          //    Serial.println(Irms*232.0);
              gw.send(kWhMsg.set((Irms*232.0)/1000, 1));
          //    Serial.print("kWH: ");
          //    Serial.println((Irms*232.0)/1000);
              lastSend = now;
            }
          
            //gw.sleep(SLEEP_TIME); //sleep a bit
          }
          
          void updateHumidityTemp() {
            
            if(lastCheckTime + SLEEP_TIME < millis() || lastCheckTime == 0) {
              //delay(dht.getMinimumSamplingPeriod());
            
              float humidity = dht.getHumidity();
              if (isnan(humidity)) {
                  Serial.println("Failed reading humidity from DHT");
              } else if (humidity != lastHum) {
                  lastHum = humidity;
                  gw.send(msgHum.set(humidity, 1));
                  Serial.print("H: ");
                  Serial.println(humidity);
              }
              lastCheckTime = millis();
            }
            
            float temperature = dht.getTemperature();
            if (isnan(temperature)) {
                Serial.println("Failed reading temperature from DHT");
            } else if (temperature != lastTemp) {
              lastTemp = temperature;
              if (!metric) {
                temperature = dht.toFahrenheit(temperature);
              }
              gw.send(msgTemp.set(temperature, 1));
              Serial.print("T: ");
              Serial.println(temperature);
            }
          }
          
          void incomingMessage(const MyMessage &message) {
            // We only expect one type of message from controller. But we better check anyway.
            if (message.type==V_LIGHT) {
               // Change relay state
               digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
               // Store state in eeprom
               gw.saveState(message.sensor, message.getBool());
               // Write some debug info
               Serial.print("Incoming change for sensor:");
               Serial.print(message.sensor);
               Serial.print(", New status: ");
               Serial.println(message.getBool());
             } 
          }
          

          Arduino serial Gateway sketch:

            /*
           * Copyright (C) 2013 Henrik Ekblad <henrik.ekblad@gmail.com>
           * 
           * This program is free software; you can redistribute it and/or
           * modify it under the terms of the GNU General Public License
           * version 2 as published by the Free Software Foundation.
           * 
           * DESCRIPTION
           * The ArduinoGateway prints data received from sensors on the serial link. 
           * The gateway accepts input on seral which will be sent out on radio network.
           *
           * The GW code is designed for Arduino Nano 328p / 16MHz
           *
           * Wire connections (OPTIONAL):
           * - Inclusion button should be connected between digital pin 3 and GND
           * - RX/TX/ERR leds need to be connected between +5V (anode) and digital ping 6/5/4 with resistor 270-330R in a series
           *
           * LEDs (OPTIONAL):
           * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
           * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
           * - ERR (red) - fast blink on error during transmission error or recieve crc error  
           */
          
          #include <SPI.h>  
          #include <MySensor.h>  
          #include <MyGateway.h>  
          #include <stdarg.h>
          
          #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
          #define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button
          
          
          MyGateway gw(DEFAULT_CE_PIN, DEFAULT_CS_PIN, INCLUSION_MODE_TIME, INCLUSION_MODE_PIN,  6, 5, 4);
          
          char inputString[MAX_RECEIVE_LENGTH] = "";    // A string to hold incoming commands from serial/ethernet interface
          int inputPos = 0;
          boolean commandComplete = false;  // whether the string is complete
          
          void setup()  
          { 
            gw.begin();
          }
          
          void loop()  
          { 
            gw.processRadioMessage();   
            if (commandComplete) {
              // A command wass issued from serial interface
              // We will now try to send it to the actuator
              gw.parseAndSend(inputString);
              commandComplete = false;  
              inputPos = 0;
            }
          }
          
          
          /*
            SerialEvent occurs whenever a new data comes in the
           hardware serial RX.  This routine is run between each
           time loop() runs, so using delay inside loop can delay
           response.  Multiple bytes of data may be available.
           */
          void serialEvent() {
            while (Serial.available()) {
              // get the new byte:
              char inChar = (char)Serial.read(); 
              // if the incoming character is a newline, set a flag
              // so the main loop can do something about it:
              if (inputPos<MAX_RECEIVE_LENGTH-1 && !commandComplete) { 
                if (inChar == '\n') {
                  inputString[inputPos] = 0;
                  commandComplete = true;
                } else {
                  // add it to the inputString:
                  inputString[inputPos] = inChar;
                  inputPos++;
                }
              } else {
                 // Incoming message too long. Throw away 
                  inputPos = 0;
              }
            }
          }
          

          For the moment only the temp and humidity are displayed on the localhost.

          I would kindly ask somebody who can help me where or what do i have to modify to see this SCT-013-000 work (i copied already the emon addon file in the addons folder) and the two switches too!

          As i said on the beginning of this topic, there are people who try to make it work but its impossible without your help here.

          Thanks for any advice.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ewgor
            wrote on last edited by ewgor
            #5

            After a few minutes the dht11 stoper to work or it didn't work from the beginning. I think maybe it didn't refresh well and i was still seeing the old values!
            Any suggestion will be kindly appreciated.
            Ps: all the connection between nrf and arduino are ok!

            1 Reply Last reply
            0
            • T Offline
              T Offline
              TimO
              Hero Member
              wrote on last edited by
              #6

              Take a closer look at the table with the mappings in the rule file and the corresponding node and child ids in the sketch. I'm on my mobile so I'm only able to give you that hint.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TimO
                Hero Member
                wrote on last edited by
                #7

                Let's begin with the sketch. You have to change the child ids. Because in your sketch you present TEMP and Relay with child id 1, that will confuse at least the controller. :)

                // Example sketch showing how to control physical relays. 
                // This example will remember relay state even after power failure.
                
                #include <MySensor.h>
                #include <SPI.h>
                #include <DHT.h>
                #include "EmonLib.h"             // Include Emon Library
                EnergyMonitor emon1;  
                
                #define NODE_ID 101
                #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                #define NUMBER_OF_RELAYS 2 // Total number of attached relays
                #define RELAY_ON 1  // GPIO value to write to turn on attached relay
                #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
                
                #define CHILD_ID_HUM 0
                // CHILD IDs 1 and 2 will be used by the relays!! ###########################
                #define CHILD_ID_TEMP 3 // ###########################
                #define CHILD_ID_WATT 4 // 17 should work too ###########################
                #define CHILD_ID_KWH 5 // 17 should work too ###########################
                #define HUMIDITY_SENSOR_DIGITAL_PIN 12
                unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                unsigned long lastSend;
                unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
                MySensor gw(48, 49);
                
                DHT dht;
                
                float lastTemp;
                float lastHum;
                boolean metric = true; 
                
                MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                MyMessage IrmsMsg(CHILD_ID_WATT,V_WATT);
                MyMessage kWhMsg(CHILD_ID_KWH,V_KWH);
                
                unsigned long lastCheckTime = millis();
                
                void setup()  
                {   
                  // Initialize library and add callback for incoming messages
                  gw.begin(incomingMessage, NODE_ID, true);
                  // Send the sketch version information to the gateway and Controller
                  gw.sendSketchInfo("Relay + Energy Meter", "1.0"); 
                  //gw.sendSketchInfo("Energy Meter", "1.0");  // Send the sketch version information to the gateway and Controller
                  gw.present(CHILD_ID_KWH, S_POWER);  // Register this device as power sensor
                  emon1.current(A0, 29.0);       // Current: input pin, calibration.
                
                  // Fetch relay status
                  for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
                    // Register all sensors to gw (they will be created as child devices)
                    gw.present(sensor, S_LIGHT);
                    // Then set relay pins in output mode
                    pinMode(pin, OUTPUT);   
                    // Set relay to last known state (using eeprom storage) 
                    //digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
                    digitalWrite(pin, RELAY_OFF);
                  }
                  
                  dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
                  // Register all sensors to gw (they will be created as child devices)
                  gw.present(CHILD_ID_HUM, S_HUM);
                  gw.present(CHILD_ID_TEMP, S_TEMP);
                  
                  //metric = gw.getConfig().isMetric;
                }
                
                
                void loop() 
                {
                  // Alway process incoming messages whenever possible
                  gw.process();
                  updateHumidityTemp();
                  unsigned long now = millis();
                  //emon1.serialprint();           // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
                  double Irms = emon1.calcIrms(1480);
                  bool sendTime = now - lastSend > SEND_FREQUENCY;
                  if (sendTime) {
                    gw.send(IrmsMsg.set((Irms*232.0)*1000, 1));
                //    Serial.print("Watt: ");
                //    Serial.println(Irms*232.0);
                    gw.send(kWhMsg.set((Irms*232.0)/1000, 1));
                //    Serial.print("kWH: ");
                //    Serial.println((Irms*232.0)/1000);
                    lastSend = now;
                  }
                
                  //gw.sleep(SLEEP_TIME); //sleep a bit
                }
                
                void updateHumidityTemp() {
                  
                  if(lastCheckTime + SLEEP_TIME < millis() || lastCheckTime == 0) {
                    //delay(dht.getMinimumSamplingPeriod());
                  
                    float humidity = dht.getHumidity();
                    if (isnan(humidity)) {
                        Serial.println("Failed reading humidity from DHT");
                    } else if (humidity != lastHum) {
                        lastHum = humidity;
                        gw.send(msgHum.set(humidity, 1));
                        Serial.print("H: ");
                        Serial.println(humidity);
                    }
                    lastCheckTime = millis();
                  }
                  
                  float temperature = dht.getTemperature();
                  if (isnan(temperature)) {
                      Serial.println("Failed reading temperature from DHT");
                  } else if (temperature != lastTemp) {
                    lastTemp = temperature;
                    if (!metric) {
                      temperature = dht.toFahrenheit(temperature);
                    }
                    gw.send(msgTemp.set(temperature, 1));
                    Serial.print("T: ");
                    Serial.println(temperature);
                  }
                }
                
                void incomingMessage(const MyMessage &message) {
                  // We only expect one type of message from controller. But we better check anyway.
                  if (message.type==V_LIGHT) {
                     // Change relay state
                     digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
                     // Store state in eeprom
                     gw.saveState(message.sensor, message.getBool());
                     // Write some debug info
                     Serial.print("Incoming change for sensor:");
                     Serial.print(message.sensor);
                     Serial.print(", New status: ");
                     Serial.println(message.getBool());
                   } 
                }
                

                So the mappings in the rules file should look something like

                // Mappings
                var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
                    "101;0;"            -> "livingHum01",    // looks good
                    "livingHum01"       -> "101;0;",
                    "101;5;"            -> "livingKwh01",  // CHILD_ID_KWH == 5 and in the sitemaps it is called livingKwh01!!
                    "livingKwh01"       -> "101;5;",
                    "101;3;"            -> "livingTemp01", 
                    "livingTemp01"      -> "101;3;"
                    "101;1;"            -> "lightBar01",
                    "lightBar01"        -> "101;1;",
                    "101;2;"            -> "lightKitchenCabinet01", 
                    "lightKitchenCabinet01" -> "101;2;",
                )
                

                sitemap:

                {
                  Frame label="Dormitor" {
                    Text item=livingTemp01
                    Text item=livingHum01
                    Text item=livingKwh01
                  }
                   Frame label="Lights" {
                        Group item=kLights label="Lights" {
                            Switch item=lightBar01 label="Bar Lights"
                            Switch item=lightKitchenCabinet01 label="Cabinet Lights"
                        }
                    }
                

                In the items file you need to define those switches like

                Switch           lightBar01                          "Bar Lights"
                Switch           lightKitchenCabinet01               "Cabinet Lights"
                

                In the rules there is a typo:

                if (subType == V_KWH){
                                    postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                    println ("Kwh item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " kwh: " + msg )
                                    }
                

                So, that are some fixes to start with! ;-)

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  ewgor
                  wrote on last edited by
                  #8

                  Thanks TimO, i didn't have time today to check your example but yesterday i deleted everything and started all over again following your example. During the tests I saw that if I add some new addresses in the hash map the local host is not refreshing anymore and in the server side I still see the updates but is just the hum or temp value without any label like livingTemp01 Temp: 31as it is if I delete the new addresses for the kWh like "101;18;" ->"livingkwh01".
                  Today il try your example from above and hopefully it will work :)
                  Many thanks and sorry for any spell mistakes, this time I'm writing on my phone too :)
                  Have a nice day!

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    ewgor
                    wrote on last edited by ewgor
                    #9

                    I have tested your example (above) and its not working. After i deleted all in the hashmap in the rule file, i can say its not refreshing the values on the localhost but i still can see them in the server monitor:
                    This is how it shows if i have only the temp and hum in the hashmap:

                    2015-07-22 19:58:11.891 [INFO ] [runtime.busevents             ] - livingTemp01
                    state updated to 33.0
                    Temp item: livingTemp01 temp: 33.0
                    

                    If i add another address in the hashmap like this:

                    "101;18;"            -> "livingKwh18",  // CHILD_ID_KWH == 18 changed in the sketch too!
                    "livingKwh18"        -> "101;18;",
                    

                    the local host is freezing but the server is still updating the values only that this time in a different way:

                    2015-07-22 20:08:53.140 [INFO ] [runtime.busevents             ] - Arduino state
                     updated to 0;0;3;0;9;read: 101-101-0 s=3,c=1,t=0,pt=7,l=5:33.0
                    101;3;1;0;0;33.0
                    

                    As for the Kwh i see something in the server side which i suppose is the Kwh value (don't have the CT sensor connected yet) but it doesn't appear in the localhost!
                    This is what it shows and i suppose the last value 0,6 is the value read on Arduino analog pin A0:

                    2015-07-22 20:12:38.319 [INFO ] [runtime.busevents             ] - Arduino state
                     updated to 0;0;3;0;9;read: 101-101-0 s=17,c=1,t=17,pt=7,l=5:607246.3
                    101;17;1;0;17;607246.3
                    0;0;3;0;9;read: 101-101-0 s=18,c=1,t=18,pt=7,l=5:0.6
                    101;18;1;0;18;0.6
                    

                    Regarding the two switches, they are still dead after i added the items you gave me in the items file and i get this error on the server when i switch on /off any of them but it seems its still sending the command:

                    2015-07-22 20:46:43.839 [INFO ] [runtime.busevents             ] - lightKitchenC
                    abinet01 received command OFF
                    2015-07-22 20:46:43.840 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:43.844 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:43.845 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:43.846 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:43.847 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:44.151 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:44.156 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:44.157 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:44.158 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:44.159 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:44.312 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:44.315 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:44.316 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:44.317 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:44.317 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrie
                    ve item kLights for widget org.openhab.model.sitemap.Group
                    2015-07-22 20:46:58.925 [INFO ] [runtime.busevents             ] - Arduino state
                    

                    which i suppose is related to the sitemap, items and the rule files and here i still can work until i lose the errors but the problem is (i think !) in the Arduino sketch because i dont think they match with that code I have right now from you, speaking about the same sketch you posted here http://forum.mysensors.org/topic/655/serial-gateway-connection-to-openhab/3.
                    Any chance to make it work? :(:cry: :weary:

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      TimO
                      Hero Member
                      wrote on last edited by
                      #10

                      Remove the "item=kLights" that makes no sense and produces the error you posted.

                      {
                        Frame label="Dormitor" {
                          Text item=livingTemp01
                          Text item=livingHum01
                          Text item=livingKwh01
                        }
                         Frame label="Lights" {
                              Group label="Lights" {
                                  Switch item=lightBar01 label="Bar Lights"
                                  Switch item=lightKitchenCabinet01 label="Cabinet Lights"
                              }
                          }
                      

                      The update of the Temperature looks good, can't figure out, why the value is not shown in on the webpage.

                      Here is my output :

                      Temp item: workTemp01 temp: 25.4
                      2015-07-22 21:53:14.902 [INFO ] [runtime.busevents             ] - workTemp01 state updated to 25.4
                      

                      Did you refresh the webpage (silly question I know)?

                      Regarding the switches:

                      rule "lightBar04 Switch Rule"
                          when
                              Item lightBar04 changed
                          then
                              switchOperation.apply(lightBar04, Arduino, sensorToItemsMap.get("lightBar04"), V_LIGHT)         
                      end 
                      

                      Change that to:

                      rule "Light"
                              when
                                      Item lightBar01 received update
                              then
                                     if(receivedCommand == ON) {
                                  sendCommand(Arduino, "101;1;1;0;2;1\n")
                              }
                              if(receivedCommand == OFF) {
                                 sendCommand(Arduino, "101;1;1;0;2;0\n")
                              }
                      end
                      

                      Let's see what works now. ;-)

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        ewgor
                        wrote on last edited by
                        #11

                        Hi TimO,
                        There is no chance to make it work. The server is ok, receive info from both sides, from web switches (ok now with that stupid klight removed) and from sensors too one by one (it can be seeing by addresses: s0, s3, s4, s5) but the webpage (on localhost) is frozen, cant understand why!
                        Could you please test this files on your pc? bellow are the files modified according to your indications:
                        Openhab items, rules, sitemap:

                        String Arduino "Arduino" { serial="COM4@115200" }
                        Number          livingTemp01                            "Temperatura [%.1f °C]" <temperature> 
                        Number          livingHum01                             "Umiditate [%.1f %%]" <water>
                        Number          livingWatt01                             "Consum Electric Watt [%.1f Watt]" <energy>
                        Number          livingKwh01                             "Consum Electric Kilowattora [%.1f kWh]" <energy>
                        Switch           lightBar01                          "Bar Lights"
                        Switch           lightKitchenCabinet01               "Cabinet Lights"
                        ===================================================================
                        import org.openhab.core.library.types.*
                        import org.openhab.core.persistence.*
                        import org.openhab.model.script.actions.*
                        import org.joda.time.*
                        import java.util.*
                        import org.eclipse.xtext.xbase.lib.*
                        import org.openhab.core.items.*
                        
                        
                        var String ArduinoUpdate = ""
                        var String sketchName = ""
                        
                        var int V_TEMP = 0
                        var int V_HUM = 1
                        var int V_LIGHT = 2
                        var int V_DIMMER = 3
                        var int V_PRESSURE = 4
                        var int V_FORECAST = 5
                        var int V_RAIN = 6
                        var int V_RAINRATE = 7
                        var int V_WIND = 8
                        var int V_GUST = 9
                        var int V_DIRECTION = 10
                        var int V_UV = 11
                        var int V_WEIGHT = 12
                        var int V_DISTANCE = 13
                        var int V_IMPEDANCE = 14
                        var int V_ARMED = 15
                        var int V_TRIPPED = 16
                        var int V_WATT = 17
                        var int V_KWH = 18
                        var int V_SCENE_ON = 19
                        var int V_SCENE_OFF = 20
                        var int V_HEATER = 21
                        var int V_HEATER_SW = 22
                        var int V_LIGHT_LEVEL = 23
                        var int V_VAR1 = 24
                        var int V_VAR2 = 25
                        var int V_VAR3 = 26
                        var int V_VAR4 = 27
                        var int V_VAR5 = 28
                        var int V_UP = 29
                        var int V_DOWN = 30
                        var int V_STOP = 31
                        var int V_IR_SEND = 32
                        var int V_IR_RECEIVE = 33
                        var int V_FLOW = 34
                        var int V_VOLUME = 35
                        var int V_LOCK_STATUS = 36
                        var int V_DUST_LEVEL = 37
                        var int V_VOLTAGE = 38
                        var int V_CURRENT = 39
                        var int msgPresentation = 0
                        var int msgSet = 1
                        var int msgReq = 2
                        var int msgInternal = 3
                        var int msgStream = 4
                        var int alarmArmor = 1
                        
                        // Internal Commands
                        
                        var int I_BATTERY_LEVEL = 0
                        var int I_TIME = 1
                        var int I_VERSION = 2
                        var int I_ID_REQUEST = 3
                        var int I_ID_RESPONSE = 4
                        var int I_INCLUSION_MODE = 5
                        var int I_CONFIG = 6
                        var int I_FIND_PARENT = 7
                        var int I_FIND_PARENT_RESPONSE = 8
                        var int I_LOG_MESSAGE = 9
                        var int I_CHILDREN = 10
                        var int I_SKETCH_NAME = 11
                        var int I_SKETCH_VERSION = 12
                        var int I_REBOOT = 13
                        var int I_GATEWAY_READY = 14
                        
                        // Mappings
                        var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
                            "101;0;"            -> "livingHum01",    // looks good
                            "livingHum01"       -> "101;0;",
                            "101;1;"            -> "lightBar01",
                            "lightBar01"        -> "101;1;",
                        	"101;2;"            -> "lightKitchenCabinet01", 
                            "lightKitchenCabinet01" -> "101;2;",
                        	"101;3;"            -> "livingTemp01", 
                            "livingTemp01"      -> "101;3;"
                        	"101;4;"            -> "livingWatt01",  // CHILD_ID_KWH == 4 and in the sitemaps it is called livingKwh01!!
                            "livingWatt01"       -> "101;4;",
                        	"101;5;"            -> "livingKwh01",  // CHILD_ID_KWH == 5 and in the sitemaps it is called livingKwh01!!
                            "livingKwh01"       -> "101;5;",
                            
                            
                            
                        )
                            
                        
                        //receiving msg from mysensors gateway
                        rule "Arduino sends to Openhab"
                            when
                                Item Arduino received update
                            then
                                var String lineBuffer =  Arduino.state.toString.split("\n")
                                for (String line : lineBuffer) {
                                    var String[] message = line.split(";")
                                    var Integer nodeId = new Integer(message.get(0))
                                    var Integer childId = new Integer(message.get(1))
                                    var Integer msgType = new Integer(message.get(2))
                                    var Integer ack = new Integer(message.get(3))
                                    var Integer subType = new Integer(message.get(4))
                                    var String msg = message.get(5)
                                    if(msgType == 1 ){
                                        if (subType == V_TEMP){
                                            postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                            println ("Temp item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " temp: " + msg )
                                            }
                                        if (subType == V_HUM){
                                            postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                            println ("Hum item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " hum: " + msg )
                                            }
                                        if (subType == V_WATT){
                                            postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                            println ("Watt item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " watt: " + msg )
                                            }
                        				if (subType == V_KWH){
                                            postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                            println ("Kwh item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " kwh: " + msg )
                                            }
                                        if (subType == V_LIGHT){
                                            var String state
                                            var Integer statusInt = new Integer(message.get(5))
                                            if(statusInt == 1) { 
                                                state = "ON"
                                                } 
                                            else { 
                                                state = "OFF" 
                                                }
                                            postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), state)
                                            println ("Light Item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Light: " + state )
                                            }
                                        }    
                                    // Internal Command
                                    if(msgType == 3){
                                        if(subType == I_SKETCH_NAME){
                                                println("Sketch name: " + msg )
                                                sketchName=msg
                                            }
                                        if(subType == I_SKETCH_VERSION){
                                                println("Sketch version: " + msg )
                                                postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), sketchName+" " +msg )
                                                sketchName=""
                                            }
                                        }
                                    }   
                                }
                        end
                        rule "Light"
                                when
                                        Item lightBar01 received update
                                then
                                       if(receivedCommand == ON) {
                                    sendCommand(Arduino, "101;1;1;0;2;1\n")
                                }
                                if(receivedCommand == OFF) {
                                   sendCommand(Arduino, "101;1;1;0;2;0\n")
                                }
                        end
                        =======================================================================
                        sitemap demo label="Acasa"
                        {
                          Frame label="Dormitor" {
                            Text item=livingTemp01
                            Text item=livingHum01
                            Text item=livingWatt01
                        	Text item=livingKwh01
                          }
                           Frame label="Lights" {
                                Group label="Lights" {
                                    Switch item=lightBar01 label="Bar Lights"
                                    Switch item=lightKitchenCabinet01 label="Cabinet Lights"
                                }
                            }
                        

                        and the same Arduino sketch:

                        // Example sketch showing how to control physical relays. 
                        // This example will remember relay state even after power failure.
                        
                        #include <MySensor.h>
                        #include <SPI.h>
                        #include <DHT.h>
                        #include "EmonLib.h"             // Include Emon Library
                        EnergyMonitor emon1;  
                        
                        #define NODE_ID 101
                        #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                        #define NUMBER_OF_RELAYS 2 // Total number of attached relays
                        #define RELAY_ON 1  // GPIO value to write to turn on attached relay
                        #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
                        
                        #define CHILD_ID_HUM 0
                        // CHILD IDs 1 and 2 will be used by the relays!! ###########################
                        #define CHILD_ID_TEMP 3 // ###########################
                        #define CHILD_ID_WATT 4 // 17 should work too ###########################
                        #define CHILD_ID_KWH 5 // 17 should work too ###########################
                        #define HUMIDITY_SENSOR_DIGITAL_PIN 12
                        unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                        unsigned long lastSend;
                        unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
                        MySensor gw(48, 49);
                        
                        DHT dht;
                        
                        float lastTemp;
                        float lastHum;
                        boolean metric = true; 
                        
                        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                        MyMessage IrmsMsg(CHILD_ID_WATT,V_WATT);
                        MyMessage kWhMsg(CHILD_ID_KWH,V_KWH);
                        
                        unsigned long lastCheckTime = millis();
                        
                        void setup()  
                        {   
                          // Initialize library and add callback for incoming messages
                          gw.begin(incomingMessage, NODE_ID, true);
                          // Send the sketch version information to the gateway and Controller
                          gw.sendSketchInfo("Relay + Energy Meter", "1.0"); 
                          //gw.sendSketchInfo("Energy Meter", "1.0");  // Send the sketch version information to the gateway and Controller
                          gw.present(CHILD_ID_KWH, S_POWER);  // Register this device as power sensor
                          emon1.current(A0, 29.0);       // Current: input pin, calibration.
                        
                          // Fetch relay status
                          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
                            // Register all sensors to gw (they will be created as child devices)
                            gw.present(sensor, S_LIGHT);
                            // Then set relay pins in output mode
                            pinMode(pin, OUTPUT);   
                            // Set relay to last known state (using eeprom storage) 
                            //digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
                            digitalWrite(pin, RELAY_OFF);
                          }
                          
                          dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
                          // Register all sensors to gw (they will be created as child devices)
                          gw.present(CHILD_ID_HUM, S_HUM);
                          gw.present(CHILD_ID_TEMP, S_TEMP);
                          
                          //metric = gw.getConfig().isMetric;
                        }
                        
                        
                        void loop() 
                        {
                          // Alway process incoming messages whenever possible
                          gw.process();
                          updateHumidityTemp();
                          unsigned long now = millis();
                          //emon1.serialprint();           // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
                          double Irms = emon1.calcIrms(1480);
                          bool sendTime = now - lastSend > SEND_FREQUENCY;
                          if (sendTime) {
                            gw.send(IrmsMsg.set((Irms*232.0)*1000, 1));
                        //    Serial.print("Watt: ");
                        //    Serial.println(Irms*232.0);
                            gw.send(kWhMsg.set((Irms*232.0)/1000, 1));
                        //    Serial.print("kWH: ");
                        //    Serial.println((Irms*232.0)/1000);
                            lastSend = now;
                          }
                        
                          //gw.sleep(SLEEP_TIME); //sleep a bit
                        }
                        
                        void updateHumidityTemp() {
                          
                          if(lastCheckTime + SLEEP_TIME < millis() || lastCheckTime == 0) {
                            //delay(dht.getMinimumSamplingPeriod());
                          
                            float humidity = dht.getHumidity();
                            if (isnan(humidity)) {
                                Serial.println("Failed reading humidity from DHT");
                            } else if (humidity != lastHum) {
                                lastHum = humidity;
                                gw.send(msgHum.set(humidity, 1));
                                Serial.print("H: ");
                                Serial.println(humidity);
                            }
                            lastCheckTime = millis();
                          }
                          
                          float temperature = dht.getTemperature();
                          if (isnan(temperature)) {
                              Serial.println("Failed reading temperature from DHT");
                          } else if (temperature != lastTemp) {
                            lastTemp = temperature;
                            if (!metric) {
                              temperature = dht.toFahrenheit(temperature);
                            }
                            gw.send(msgTemp.set(temperature, 1));
                            Serial.print("T: ");
                            Serial.println(temperature);
                          }
                        }
                        
                        void incomingMessage(const MyMessage &message) {
                          // We only expect one type of message from controller. But we better check anyway.
                          if (message.type==V_LIGHT) {
                             // Change relay state
                             digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
                             // Store state in eeprom
                             gw.saveState(message.sensor, message.getBool());
                             // Write some debug info
                             Serial.print("Incoming change for sensor:");
                             Serial.print(message.sensor);
                             Serial.print(", New status: ");
                             Serial.println(message.getBool());
                           } 
                        }
                        

                        Many thanks for your time.

                        1 Reply Last reply
                        0
                        • E Offline
                          E Offline
                          ewgor
                          wrote on last edited by ewgor
                          #12

                          About the sensors, if i add another address in the hashmap other than temp and hum the web freezes, if i leave only the temp and hum, the web page can be refreshed and will display the temp and hum values. In the mean time my server receive info as i said previously from both sides (webpage and sensors) but is not sending them forward.
                          have anyone made it with relay with button actuators and openhab? the task would be to switch on/off the relay from webpage and button and to get the status on the web page even if the relay is operated from that physical button.

                          About the CT sensor, in the server monitor i get this msg:

                          2015-07-24 13:34:09.614 [WARN ] [.model.script.actions.BusEvent] - Item 'null' does not exist.
                          Watt item: null watt: 621372.3 2015-07-24 13:34:13.805 [WARN ] [.model.script.actions.BusEvent] - Item 'null' does not exist. Kwh item: null kwh: 0.6
                          

                          I guess this "null" is because i didnt connect yet the CT sensor? Can anyone who have exp. with this kind of sensor help me? my Openhab config are above.
                          Thanks for any help.

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            stevenwatson011
                            wrote on last edited by
                            #13
                            This post is deleted!
                            1 Reply Last reply
                            0
                            • E Offline
                              E Offline
                              ewgor
                              wrote on last edited by ewgor
                              #14

                              With this rule:

                              rule "Light"
                                      when
                                              Item lightBar01 received update
                                      then
                                             if(receivedCommand == ON) {
                                          sendCommand(Arduino, "101;1;1;0;2;1\n")
                                      }
                                      if(receivedCommand == OFF) {
                                         sendCommand(Arduino, "101;1;1;0;2;0\n")
                                      }
                              end
                              

                              i get this error:

                              2015-07-24 17:40:02.994 [INFO ] [runtime.busevents             ] - lightBar01 received command ON
                              2015-07-24 17:40:03.020 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Light': The name 'receivedCommand' cannot be resolved toan item or type.
                              

                              i cant believe that there are 1.7k users here, more than 1k online, more than 500 views (including mine (maybe half them :)) and nobody helps :eyes:

                              1 Reply Last reply
                              0
                              • E Offline
                                E Offline
                                ewgor
                                wrote on last edited by
                                #15

                                Help please.

                                1 Reply Last reply
                                0
                                • E Offline
                                  E Offline
                                  ewgor
                                  wrote on last edited by
                                  #16

                                  can anyone try my example above and tell me if it is working or not? speaking to hero members, not to those as me! Common people, please help us, we are not stealing your jobs or future, we just want to light a simple led on/off!
                                  thanks to all intelligent people here :P

                                  1 Reply Last reply
                                  0
                                  • hekH Offline
                                    hekH Offline
                                    hek
                                    Admin
                                    wrote on last edited by
                                    #17

                                    i cant believe that there are 1.7k users here, more than 1k online, more than 500 views (including mine (maybe half them :)) and nobody helps :eyes:

                                    People might not have run into the same problems as you're having you know. And the amount of community members running OpenHab+MQTT isn't that huge I guess. So even if many here would like to help you we don't have the time or possibility to re-create your environment.

                                    A good approach to isolate the problem (shaving off as much as much irrelevant stuff as possible). You know that the wireless communication is working... so something must be wrong in the rules or you've found some kind of bug in OpenHab.

                                    You don't need CTs to test sending in a value from the Arduino.. Just set and send any value using the API to test it. Mocking is a good approach when testing.

                                    E 1 Reply Last reply
                                    0
                                    • hekH hek

                                      i cant believe that there are 1.7k users here, more than 1k online, more than 500 views (including mine (maybe half them :)) and nobody helps :eyes:

                                      People might not have run into the same problems as you're having you know. And the amount of community members running OpenHab+MQTT isn't that huge I guess. So even if many here would like to help you we don't have the time or possibility to re-create your environment.

                                      A good approach to isolate the problem (shaving off as much as much irrelevant stuff as possible). You know that the wireless communication is working... so something must be wrong in the rules or you've found some kind of bug in OpenHab.

                                      You don't need CTs to test sending in a value from the Arduino.. Just set and send any value using the API to test it. Mocking is a good approach when testing.

                                      E Offline
                                      E Offline
                                      ewgor
                                      wrote on last edited by
                                      #18

                                      @hek thanks for your replay! i'm not using OpenHab+MQTT but the serial gateway communication explained by @TimO and i got the errors shown above so my questions are point by point. i tried different ways to see if i can get loose of the errors but no chance and than i came here asking for help.
                                      My idea was if somebody have the needed time to test my config (opehab + arduino) and to tell me if is working on their pc or not and maybe some instructions where or what needs to be changed, modified deleted or added.
                                      I count on experienced people who can see quikly where is the mistake and who could give me useful information as for example @TimO did at one point.

                                      Once again, besides hum and temp that works at this hour i need to add a few buttons who could turn a light on/of from openhab and from physiscal buttons too and to understand why if i add a new device as CT sensor its not displaying anymore the rest of the devices.
                                      Thanks for understanding.

                                      1 Reply Last reply
                                      0
                                      • T Offline
                                        T Offline
                                        TimO
                                        Hero Member
                                        wrote on last edited by
                                        #19

                                        Hi @ewgor ,

                                        could you make your whole configuration available for download? It is easier for us to help you to find the error.

                                        E 1 Reply Last reply
                                        0
                                        • T TimO

                                          Hi @ewgor ,

                                          could you make your whole configuration available for download? It is easier for us to help you to find the error.

                                          E Offline
                                          E Offline
                                          ewgor
                                          wrote on last edited by
                                          #20

                                          @TimO what do you mean by " configuration available for download"? i'm combining different Arduino sketches found here on the site and i'm trying to find a way to match them with the Openhab configuration found here too! All my files are above but right now i'm trying to combine the Arduino sketch from above with this one for relay with button actuator from here http://www.mysensors.org/build/relay and its very difficult. couldn't do it today, maybe tomorrow :(
                                          As a conclusion because i don't know if i was very clear: Could anyone help me combine Arduino sketch from above with the one for relay with button actuator for 2 (two relays and two buttons) devices and to check the Openhab config which are above too? As i already said, today o tried all day long to combine them but cant lose the errors, it cant compile :(

                                          Hoping for an answer ...

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          11

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular