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. Controllers
  3. OpenHAB
  4. openHAB 2.0 binding

openHAB 2.0 binding

Scheduled Pinned Locked Moved OpenHAB
534 Posts 88 Posters 480.6k Views 99 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.
  • L Offline
    L Offline
    LastSamurai
    Hardware Contributor
    wrote on last edited by
    #407

    I just tried to get the openhab 2 binding up and running. I have a serial gateway and domoticz + openhab running on a pi. I stopped the domoticz service and installed the serial and mysensors addons for openhab like mentioned in the github readme (bundle:list showed them both). I also added the openhab user to the dialout group.
    I then created a demo.things file in config/things with

    Bridge mysensors:bridge-ser:gateway [ serialPort="/dev/ttyUSB0", sendDelay=200 ] {
        /** define things connected to that bridge here */
      }
    

    The log of openhab shows these errors though:

    2017-03-19 00:03:59.855 [ERROR] [col.serial.MySensorsSerialConnection] - Can't connect to serial port. Wrong port?
    2017-03-19 00:03:59.897 [ERROR] [col.serial.MySensorsSerialConnection] - Failed connecting to bridge...next retry in 10 seconds (Retry No.:46)
    

    Any idea why? This works just fine:

    cat /dev/ttyUSB0
    
    AndrewZA 1 Reply Last reply
    0
    • L LastSamurai

      I just tried to get the openhab 2 binding up and running. I have a serial gateway and domoticz + openhab running on a pi. I stopped the domoticz service and installed the serial and mysensors addons for openhab like mentioned in the github readme (bundle:list showed them both). I also added the openhab user to the dialout group.
      I then created a demo.things file in config/things with

      Bridge mysensors:bridge-ser:gateway [ serialPort="/dev/ttyUSB0", sendDelay=200 ] {
          /** define things connected to that bridge here */
        }
      

      The log of openhab shows these errors though:

      2017-03-19 00:03:59.855 [ERROR] [col.serial.MySensorsSerialConnection] - Can't connect to serial port. Wrong port?
      2017-03-19 00:03:59.897 [ERROR] [col.serial.MySensorsSerialConnection] - Failed connecting to bridge...next retry in 10 seconds (Retry No.:46)
      

      Any idea why? This works just fine:

      cat /dev/ttyUSB0
      
      AndrewZA Offline
      AndrewZA Offline
      AndrewZ
      wrote on last edited by AndrewZ
      #408

      @LastSamurai please check the group ownership

      $ ls -l /dev/ttyUSB0
      

      Make sure the port you're using is included in EXTRA_JAVA_OPTS as described here

      1 Reply Last reply
      1
      • L Offline
        L Offline
        LastSamurai
        Hardware Contributor
        wrote on last edited by
        #409

        Thank you, that helped! Should anyone ever face the same problem: after changing the EXTRA_JAVA_OPTS I also needed to restart openhab (more likely the java vm).

        1 Reply Last reply
        0
        • L Offline
          L Offline
          LastSamurai
          Hardware Contributor
          wrote on last edited by
          #410

          So openhab is running now and discovers my sensors when I restart them while scanning. My RGBW controller nodes pop up as RGBW sensors though. The on/off switch works, but what do I have to do to actually control the colors?
          I tried editing the 4 variables but that doesn't seem to change the lights.

          0_1490048386134_upload-9bf82cdd-ddd8-4249-973e-65bd30a3a959

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

            @LastSamurai : What does your sketch expect? One ASCII formated RGB code like described here: https://www.mysensors.org/download/serial_api_20 or a value between 0 and 100% per color (r,g,b,w)? I see different implementations (in openhab and in mysensors) and maybe we have to adjust the binding.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              LastSamurai
              Hardware Contributor
              wrote on last edited by
              #412

              @TimO Right, I guess thats the problem. I have written my sketch against domoticz, so it expects either a 6 bit hex string (rgb = e.g. ff00ff) or a 9 bit (idk why) rgbw hex string (e.g. #ff00ff00).
              According to the mysensors docu "ff00ff00" would be right, I guess.

              T RVMRVMR 2 Replies Last reply
              0
              • AndrewZA Offline
                AndrewZA Offline
                AndrewZ
                wrote on last edited by
                #413

                Just noticed in the log:

                [WARN ] [.discovery.MySensorsDiscoveryService] - Cannot automatic discover thing node: 0, child: 255 please insert it manually
                

                Is that normal or any additional configuration is needed?
                Thanks!

                T 1 Reply Last reply
                0
                • AndrewZA AndrewZ

                  Just noticed in the log:

                  [WARN ] [.discovery.MySensorsDiscoveryService] - Cannot automatic discover thing node: 0, child: 255 please insert it manually
                  

                  Is that normal or any additional configuration is needed?
                  Thanks!

                  T Offline
                  T Offline
                  TimO
                  Hero Member
                  wrote on last edited by
                  #414

                  @AndrewZ hmmmm, a child that represents itself with an id of 255 shouldn't exist. 255 is used for battery status for example. What's the message that comes in before that?

                  AndrewZA 1 Reply Last reply
                  1
                  • L LastSamurai

                    @TimO Right, I guess thats the problem. I have written my sketch against domoticz, so it expects either a 6 bit hex string (rgb = e.g. ff00ff) or a 9 bit (idk why) rgbw hex string (e.g. #ff00ff00).
                    According to the mysensors docu "ff00ff00" would be right, I guess.

                    T Offline
                    T Offline
                    TimO
                    Hero Member
                    wrote on last edited by
                    #415

                    @LastSamurai I'm working on a solution! RGB seems easy, but I haven't looked at RGBW. The Colopicker in OpenHAB only sends RGB.

                    L 1 Reply Last reply
                    0
                    • T TimO

                      @AndrewZ hmmmm, a child that represents itself with an id of 255 shouldn't exist. 255 is used for battery status for example. What's the message that comes in before that?

                      AndrewZA Offline
                      AndrewZA Offline
                      AndrewZ
                      wrote on last edited by
                      #416

                      @TimO here is the output:

                      2017-03-23 20:51:32.531 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin servlet at /habmin
                      2017-03-23 20:51:33.754 [WARN ] [.discovery.MySensorsDiscoveryService] - Cannot automatic discover thing node: 0, child: 255 please insert it manually
                      2017-03-23 20:51:33.772 [INFO ] [al.protocol.ip.MySensorsIpConnection] - Successfully connected to MySensors Bridge.
                      
                      T 1 Reply Last reply
                      0
                      • AndrewZA AndrewZ

                        @TimO here is the output:

                        2017-03-23 20:51:32.531 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin servlet at /habmin
                        2017-03-23 20:51:33.754 [WARN ] [.discovery.MySensorsDiscoveryService] - Cannot automatic discover thing node: 0, child: 255 please insert it manually
                        2017-03-23 20:51:33.772 [INFO ] [al.protocol.ip.MySensorsIpConnection] - Successfully connected to MySensors Bridge.
                        
                        T Offline
                        T Offline
                        TimO
                        Hero Member
                        wrote on last edited by
                        #417

                        @AndrewZ the message occurs right after startup and before the bridge gets connected?! Just ignore the message if everything else is working fine. :D
                        I'll release the refactored version soon. It's already available via the new IoT marketplace.

                        AndrewZA 1 Reply Last reply
                        1
                        • T TimO

                          @AndrewZ the message occurs right after startup and before the bridge gets connected?! Just ignore the message if everything else is working fine. :D
                          I'll release the refactored version soon. It's already available via the new IoT marketplace.

                          AndrewZA Offline
                          AndrewZA Offline
                          AndrewZ
                          wrote on last edited by
                          #418

                          @TimO yes, message occurs on startup and I'm already using version from marketplace, I see it as market:binding-3328323 - 1.0

                          T 1 Reply Last reply
                          0
                          • AndrewZA AndrewZ

                            @TimO yes, message occurs on startup and I'm already using version from marketplace, I see it as market:binding-3328323 - 1.0

                            T Offline
                            T Offline
                            TimO
                            Hero Member
                            wrote on last edited by
                            #419

                            @AndrewZ oh okay! I will look at it!

                            1 Reply Last reply
                            0
                            • T TimO

                              @LastSamurai I'm working on a solution! RGB seems easy, but I haven't looked at RGBW. The Colopicker in OpenHAB only sends RGB.

                              L Offline
                              L Offline
                              LastSamurai
                              Hardware Contributor
                              wrote on last edited by
                              #420

                              @TimO Cool, I'll test it once you are done. Domoticz only allows to either use the white channel or a RGB value (without the white) at the moment. Perhaps it can be done similarly in openhab.

                              T 1 Reply Last reply
                              0
                              • L LastSamurai

                                @TimO Cool, I'll test it once you are done. Domoticz only allows to either use the white channel or a RGB value (without the white) at the moment. Perhaps it can be done similarly in openhab.

                                T Offline
                                T Offline
                                TimO
                                Hero Member
                                wrote on last edited by
                                #421

                                @LastSamurai Could you please take a look at this: https://github.com/tobof/openhab2-addons/issues/76 ?

                                I've added the RGB & RGBW channels and because I'm not that confident about the RGBW implementation I'm kindly asking you to test the implementation and give me some feedback. :-)
                                The conversion from HSB, which is used by OpenHAB2 internally, to RGBW left me pretty confused. ;-)

                                1 Reply Last reply
                                0
                                • L Offline
                                  L Offline
                                  LastSamurai
                                  Hardware Contributor
                                  wrote on last edited by
                                  #422

                                  I'll test it. Might take some days to get to it though ;)

                                  1 Reply Last reply
                                  1
                                  • B balder88

                                    Hey guys, first message on this forum. Been reading alot before. But now I have a problem I just can't solve.
                                    It's about smartsleep with openhab 2.
                                    Im using wifi gw rfm 69.
                                    Regular messages works as it should both ways.
                                    But it almost seems like the smartsleep isn't enabled in the binding.
                                    Here are my configs and logs.

                                    Things file:

                                    Bridge mysensors:bridge-eth:gw69 [ ipAddress="192.168.1.235", tcpPort=5003, sendDelay=100, enableNetworkSanCheck=true ] {
                                    //  Anarduino
                                        humidity        AnHum   [ nodeId="66", childId="0" ]
                                        temperature     AnTemp  [ nodeId="66", childId="1" ]
                                        light           light02 [ nodeId="66", childId="3", smartSleep=true ]
                                      }
                                    

                                    Items file:

                                    Switch  TestLight   "Test lampa" (Test) { channel="mysensors:light:gw69:light02:status" }
                                    

                                    Sketch: (Cleaned up the parts that dont matter, RTC and so on.)

                                    // Enable debug prints to serial monitor
                                    #define MY_DEBUG 
                                    
                                    // Enable and select radio type attached
                                    #define MY_RADIO_RFM69
                                    #define MY_IS_RFM69HW
                                    #define MY_NODE_ID 66
                                    #define MY_RFM69_NETWORKID 100
                                    #define MY_RFM69_FREQUENCY RF69_433MHZ
                                    #define MY_SMART_SLEEP_WAIT_DURATION_MS 1000
                                    #include <MySensors.h>
                                    #include <TimeLib.h>
                                    #include <Wire.h>
                                    #include <MCP7940RTC.h>
                                    #include <DHT.h>
                                    
                                    #define MCP7940_CTRL_ID 0x6F
                                    #define CSMEM_PIN 5
                                    
                                    #define LEDPIN 9
                                    
                                    long sleepIntervalSec=5;
                                    long loopCnt=0;
                                    uint8_t d[8];
                                    uint8_t dAlarm[8];
                                    int d1[8];
                                    
                                    // Set this to the pin you connected the DHT's data pin to
                                    #define DHT_DATA_PIN 6
                                    
                                    // Set this offset if the sensor has a permanent small offset to the real temperatures
                                    #define SENSOR_TEMP_OFFSET 0
                                    
                                    // Sleep time between sensor updates (in milliseconds)
                                    // Must be >1000ms for DHT22 and >2000ms for DHT11
                                    static const uint64_t UPDATE_INTERVAL = 5000;
                                    
                                    // Force sending an update of the temperature after n sensor reads, so a controller showing the
                                    // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
                                    // the value didn't change since;
                                    // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
                                    static const uint8_t FORCE_UPDATE_N_READS = 10;
                                    
                                    #define CHILD_ID_HUM 0
                                    #define CHILD_ID_TEMP 1
                                    #define CHILD_ID_MULTIMETER 2
                                    
                                    float lastTemp;
                                    float lastHum;
                                    uint8_t nNoUpdatesTemp;
                                    uint8_t nNoUpdatesHum;
                                    bool metric = true;
                                    
                                    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                                    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                                    MyMessage msgVolt(CHILD_ID_MULTIMETER, V_VOLTAGE);
                                    
                                    DHT dht;
                                    
                                    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                                    int oldBatteryPcnt = 0;
                                    int batteryBasement = 812;
                                    int batteryFull = 922;
                                    float batteryConstant = 100.0 / (batteryFull - batteryBasement);
                                    float lastbatteryV = 0;
                                    
                                    const int buzzer = 7; //buzzer to arduino pin 7
                                    
                                    #define RELAY_1  8  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                                    #define NUMBER_OF_RELAYS 1 // 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
                                    
                                    void before()
                                    {
                                      for (int sensor=3, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
                                        // Then set relay pins in output mode
                                        pinMode(pin, OUTPUT);
                                        // Set relay to last known state (using eeprom storage)
                                        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
                                      }
                                    }
                                    
                                    void setup()  
                                    {
                                       // use the 1.1 V internal reference
                                       analogReference(INTERNAL);
                                    
                                      pinMode(LEDPIN, OUTPUT);
                                      digitalWrite(LEDPIN, LOW);
                                      Wire.begin();
                                      pinMode(CSMEM_PIN, OUTPUT);
                                      digitalWrite(CSMEM_PIN, HIGH);
                                    
                                       dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
                                      if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
                                        Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
                                      }
                                      // Sleep for the time of the minimum sampling period to give the sensor time to power up
                                      // (otherwise, timeout errors might occure for the first reading)
                                      sleepIntervalSec = dht.getMinimumSamplingPeriod();
                                      clearAlarm();
                                      delay(20);
                                      setNewAlarm();
                                      sleep(dht.getMinimumSamplingPeriod());
                                      analogRead(BATTERY_SENSE_PIN);
                                     }
                                    
                                    void presentation() {
                                       // Send the sketch version information to the gateway and Controller
                                       sendSketchInfo("Humidity sensor", "1.0");
                                       present(CHILD_ID_MULTIMETER, S_MULTIMETER, "VOLT", true);
                                       present(CHILD_ID_HUM, S_HUM, "HUMIDITY", true);
                                       present(CHILD_ID_TEMP, S_TEMP, "TEMP", true);
                                      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)
                                        present(sensor, S_BINARY);
                                      }
                                      metric = getControllerConfig().isMetric;
                                    }
                                    
                                    
                                    void loop()
                                    {
                                      wait(100);
                                       int sensorValue = analogRead(BATTERY_SENSE_PIN);
                                       #ifdef MY_DEBUG
                                       Serial.println(sensorValue);
                                       #endif
                                       float batteryV  = sensorValue * 0.004551646;
                                       if(sensorValue < batteryBasement) {
                                        sensorValue = batteryBasement;
                                        batteryV = 0;
                                       }
                                       else if (sensorValue > batteryFull) {
                                        sensorValue = batteryFull;
                                       }
                                       int batteryPcnt = (sensorValue - batteryBasement) * batteryConstant;
                                           if ((abs(oldBatteryPcnt - batteryPcnt) > 1)) {
                                          sendBatteryLevel(batteryPcnt);
                                          oldBatteryPcnt = batteryPcnt;
                                        }
                                       
                                       if(batteryV != lastbatteryV) {
                                       send(msgVolt.set(batteryV, 2));
                                       lastbatteryV = batteryV;
                                       }
                                       #ifdef MY_DEBUG
                                       Serial.print("Battery Voltage: ");
                                       Serial.print(batteryV);
                                       Serial.println(" V");
                                       Serial.print("Battery percent: ");
                                       Serial.print(batteryPcnt);
                                       Serial.println(" %");
                                       #endif
                                    
                                      // Force reading sensor, so it works also after sleep()
                                      dht.readSensor(true);
                                    
                                      // Get temperature from DHT library
                                      float temperature = dht.getTemperature();
                                      if (isnan(temperature)) {
                                        Serial.println("Failed reading temperature from DHT!");
                                      } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
                                        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
                                        lastTemp = temperature;
                                        if (!metric) {
                                          temperature = dht.toFahrenheit(temperature);
                                        }
                                        // Reset no updates counter
                                        nNoUpdatesTemp = 0;
                                        temperature += SENSOR_TEMP_OFFSET;
                                        send(msgTemp.set(temperature, 1));
                                        #ifdef MY_DEBUG
                                        Serial.print("T: ");
                                        Serial.println(temperature);
                                        #endif
                                      } else {
                                        // Increase no update counter if the temperature stayed the same
                                        nNoUpdatesTemp++;
                                      }
                                    
                                      // Get humidity from DHT library
                                      float humidity = dht.getHumidity();
                                      if (isnan(humidity)) {
                                        Serial.println("Failed reading humidity from DHT");
                                      } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
                                        // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
                                        lastHum = humidity;
                                        // Reset no updates counter
                                        nNoUpdatesHum = 0;
                                        send(msgHum.set(humidity, 1));
                                    
                                        #ifdef MY_DEBUG
                                        Serial.print("H: ");
                                        Serial.println(humidity);
                                        #endif
                                      } else {
                                        // Increase no update counter if the humidity stayed the same
                                        nNoUpdatesHum++;
                                      }
                                    long sleepTime = UPDATE_INTERVAL;
                                    if (batteryPcnt < 50) {
                                      sleepTime = (sleepTime * 2);
                                    }
                                      // Sleep for a while to save energy
                                      sleepIntervalSec = sleepTime / 1000;
                                      Serial.println();
                                      Serial.print("Setting new sleep time: ");
                                      Serial.print(sleepIntervalSec);
                                      Serial.println(" seconds.");
                                      clearAlarm();
                                      delay(20);
                                      setNewAlarm();
                                      smartSleep(sleepTime);
                                    
                                    }
                                    
                                    void receive(const MyMessage &message)
                                    {
                                      // We only expect one type of message from controller. But we better check anyway.
                                      if (message.type==V_STATUS) {
                                        // Change relay state
                                        digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
                                        // Store state in eeprom
                                        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());
                                      }
                                    }
                                    

                                    Sensor startup:

                                    0 MCO:BGN:INIT NODE,CP=RRNNA--,VER=2.1.1
                                    3 MCO:BGN:BFR
                                    4 TSM:INIT
                                    5 TSF:WUR:MS=0
                                    8 TSM:INIT:TSP OK
                                    9 TSM:INIT:STATID=66
                                    11 TSF:SID:OK,ID=66
                                    13 TSM:FPAR
                                    143 TSF:MSG:SEND,66-66-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
                                    524 TSF:MSG:READ,0-0-66,s=255,c=3,t=8,pt=1,l=1,sg=0:0
                                    529 TSF:MSG:FPAR OK,ID=0,D=1
                                    2150 TSM:FPAR:OK
                                    2151 TSM:ID
                                    2152 TSM:ID:OK
                                    2154 TSM:UPL
                                    2161 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
                                    2181 TSF:MSG:READ,0-0-66,s=255,c=3,t=25,pt=1,l=1,sg=0:1
                                    2186 TSF:MSG:PONG RECV,HP=1
                                    2189 TSM:UPL:OK
                                    2190 TSM:READY:ID=66,PAR=0,DIS=1
                                    2199 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
                                    2253 TSF:MSG:READ,0-0-66,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
                                    2310 TSF:MSG:SEND,66-66-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
                                    2366 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
                                    2403 TSF:MSG:READ,0-0-66,s=255,c=3,t=6,pt=0,l=1,sg=0:M
                                    2461 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=11,pt=0,l=15,sg=0,ft=0,st=OK:Humidity sensor
                                    2562 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
                                    2618 TSF:MSG:SEND,66-66-0-0,s=2,c=0,t=30,pt=0,l=4,sg=0,ft=0,st=OK:VOLT
                                    2757 !TSF:MSG:SEND,66-66-0-0,s=0,c=0,t=7,pt=0,l=8,sg=0,ft=0,st=NACK:HUMIDITY
                                    2777 TSF:MSG:SEND,66-66-0-0,s=1,c=0,t=6,pt=0,l=4,sg=0,ft=1,st=OK:TEMP
                                    2912 !TSF:MSG:SEND,66-66-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=NACK:
                                    2918 MCO:REG:REQ
                                    2974 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=1,st=OK:2
                                    2991 TSF:MSG:READ,0-0-66,s=255,c=3,t=27,pt=1,l=1,sg=0:1
                                    2996 MCO:PIM:NODE REG=1
                                    2999 MCO:BGN:STP
                                    3154 MCO:SLP:MS=2000,SMS=0,I1=255,M1=255,I2=255,M2=255
                                    3160 MCO:SLP:TPD
                                    3161 MCO:SLP:WUP=-1
                                    3163 MCO:BGN:INIT OK,TSP=1
                                    

                                    Log Sensor: (This is when I press the button when the sensor is awake)
                                    It's sends away it's heartbeat correctly.

                                    125578 TSF:MSG:READ,0-0-66,s=3,c=1,t=2,pt=0,l=1,sg=0:0
                                    Incoming change for sensor:3, New status: 0
                                    
                                    Setting new sleep time: 5 seconds.
                                    137926 MCO:SLP:MS=5000,SMS=1,I1=255,M1=255,I2=255,M2=255
                                    137939 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=22,pt=5,l=4,sg=0,ft=0,st=OK:134932
                                    

                                    Log Openhab: And the gateway receives heartbeat.

                                    18:21:37.174 [DEBUG] [rs.internal.protocol.MySensorsWriter] - Sending to MySensors: 66;3;1;0;2;0
                                    18:21:37.178 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'TestLight' received command OFF
                                    18:21:37.181 [INFO ] [marthome.event.ItemStateChangedEvent] - TestLight changed from ON to OFF
                                    18:22:15.416 [DEBUG] [rs.internal.protocol.MySensorsReader] - 66;255;3;0;22;134932
                                    18:22:16.372 [DEBUG] [rs.internal.protocol.MySensorsWriter] - Sending to MySensors: 0;0;3;0;2;
                                    18:22:16.408 [DEBUG] [rs.internal.protocol.MySensorsReader] - 0;255;3;0;2;2.1.1
                                    

                                    Log Openhab: When the node sleeps..

                                    18:26:52.396 [DEBUG] [rs.internal.protocol.MySensorsWriter] - Sending to MySensors: 66;3;1;0;2;0
                                    18:26:52.397 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'TestLight' received command OFF
                                    18:26:52.399 [INFO ] [marthome.event.ItemStateChangedEvent] - TestLight changed from ON to OFF
                                    

                                    As you can see there is no mention in the openhab log file about buffering or smart sleep. Or a received heartbeat. Which it gets.
                                    What am I doing wrong?

                                    B Offline
                                    B Offline
                                    balder88
                                    wrote on last edited by
                                    #423

                                    I found the solution myself. About a week ago i upgraded the binding. And it worked.
                                    Everything seems to work as it should. Except I can't recieve var1 (custom) for neither the hum or temp child.

                                    smartSleep is nice. I use it once an hour (regular sleep every minute) to get configurations from openhab about sleep time and other small things in the code.

                                    @balder88 said in openHAB 2.0 binding:

                                    Hey guys, first message on this forum. Been reading alot before. But now I have a problem I just can't solve.
                                    It's about smartsleep with openhab 2.
                                    Im using wifi gw rfm 69.
                                    Regular messages works as it should both ways.
                                    But it almost seems like the smartsleep isn't enabled in the binding.
                                    Here are my configs and logs.

                                    Things file:

                                    Bridge mysensors:bridge-eth:gw69 [ ipAddress="192.168.1.235", tcpPort=5003, sendDelay=100, enableNetworkSanCheck=true ] {
                                    //  Anarduino
                                        humidity        AnHum   [ nodeId="66", childId="0" ]
                                        temperature     AnTemp  [ nodeId="66", childId="1" ]
                                        light           light02 [ nodeId="66", childId="3", smartSleep=true ]
                                      }
                                    

                                    Items file:

                                    Switch  TestLight   "Test lampa" (Test) { channel="mysensors:light:gw69:light02:status" }
                                    

                                    Sketch: (Cleaned up the parts that dont matter, RTC and so on.)

                                    // Enable debug prints to serial monitor
                                    #define MY_DEBUG 
                                    
                                    // Enable and select radio type attached
                                    #define MY_RADIO_RFM69
                                    #define MY_IS_RFM69HW
                                    #define MY_NODE_ID 66
                                    #define MY_RFM69_NETWORKID 100
                                    #define MY_RFM69_FREQUENCY RF69_433MHZ
                                    #define MY_SMART_SLEEP_WAIT_DURATION_MS 1000
                                    #include <MySensors.h>
                                    #include <TimeLib.h>
                                    #include <Wire.h>
                                    #include <MCP7940RTC.h>
                                    #include <DHT.h>
                                    
                                    #define MCP7940_CTRL_ID 0x6F
                                    #define CSMEM_PIN 5
                                    
                                    #define LEDPIN 9
                                    
                                    long sleepIntervalSec=5;
                                    long loopCnt=0;
                                    uint8_t d[8];
                                    uint8_t dAlarm[8];
                                    int d1[8];
                                    
                                    // Set this to the pin you connected the DHT's data pin to
                                    #define DHT_DATA_PIN 6
                                    
                                    // Set this offset if the sensor has a permanent small offset to the real temperatures
                                    #define SENSOR_TEMP_OFFSET 0
                                    
                                    // Sleep time between sensor updates (in milliseconds)
                                    // Must be >1000ms for DHT22 and >2000ms for DHT11
                                    static const uint64_t UPDATE_INTERVAL = 5000;
                                    
                                    // Force sending an update of the temperature after n sensor reads, so a controller showing the
                                    // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
                                    // the value didn't change since;
                                    // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
                                    static const uint8_t FORCE_UPDATE_N_READS = 10;
                                    
                                    #define CHILD_ID_HUM 0
                                    #define CHILD_ID_TEMP 1
                                    #define CHILD_ID_MULTIMETER 2
                                    
                                    float lastTemp;
                                    float lastHum;
                                    uint8_t nNoUpdatesTemp;
                                    uint8_t nNoUpdatesHum;
                                    bool metric = true;
                                    
                                    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                                    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                                    MyMessage msgVolt(CHILD_ID_MULTIMETER, V_VOLTAGE);
                                    
                                    DHT dht;
                                    
                                    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                                    int oldBatteryPcnt = 0;
                                    int batteryBasement = 812;
                                    int batteryFull = 922;
                                    float batteryConstant = 100.0 / (batteryFull - batteryBasement);
                                    float lastbatteryV = 0;
                                    
                                    const int buzzer = 7; //buzzer to arduino pin 7
                                    
                                    #define RELAY_1  8  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                                    #define NUMBER_OF_RELAYS 1 // 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
                                    
                                    void before()
                                    {
                                      for (int sensor=3, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
                                        // Then set relay pins in output mode
                                        pinMode(pin, OUTPUT);
                                        // Set relay to last known state (using eeprom storage)
                                        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
                                      }
                                    }
                                    
                                    void setup()  
                                    {
                                       // use the 1.1 V internal reference
                                       analogReference(INTERNAL);
                                    
                                      pinMode(LEDPIN, OUTPUT);
                                      digitalWrite(LEDPIN, LOW);
                                      Wire.begin();
                                      pinMode(CSMEM_PIN, OUTPUT);
                                      digitalWrite(CSMEM_PIN, HIGH);
                                    
                                       dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
                                      if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
                                        Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
                                      }
                                      // Sleep for the time of the minimum sampling period to give the sensor time to power up
                                      // (otherwise, timeout errors might occure for the first reading)
                                      sleepIntervalSec = dht.getMinimumSamplingPeriod();
                                      clearAlarm();
                                      delay(20);
                                      setNewAlarm();
                                      sleep(dht.getMinimumSamplingPeriod());
                                      analogRead(BATTERY_SENSE_PIN);
                                     }
                                    
                                    void presentation() {
                                       // Send the sketch version information to the gateway and Controller
                                       sendSketchInfo("Humidity sensor", "1.0");
                                       present(CHILD_ID_MULTIMETER, S_MULTIMETER, "VOLT", true);
                                       present(CHILD_ID_HUM, S_HUM, "HUMIDITY", true);
                                       present(CHILD_ID_TEMP, S_TEMP, "TEMP", true);
                                      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)
                                        present(sensor, S_BINARY);
                                      }
                                      metric = getControllerConfig().isMetric;
                                    }
                                    
                                    
                                    void loop()
                                    {
                                      wait(100);
                                       int sensorValue = analogRead(BATTERY_SENSE_PIN);
                                       #ifdef MY_DEBUG
                                       Serial.println(sensorValue);
                                       #endif
                                       float batteryV  = sensorValue * 0.004551646;
                                       if(sensorValue < batteryBasement) {
                                        sensorValue = batteryBasement;
                                        batteryV = 0;
                                       }
                                       else if (sensorValue > batteryFull) {
                                        sensorValue = batteryFull;
                                       }
                                       int batteryPcnt = (sensorValue - batteryBasement) * batteryConstant;
                                           if ((abs(oldBatteryPcnt - batteryPcnt) > 1)) {
                                          sendBatteryLevel(batteryPcnt);
                                          oldBatteryPcnt = batteryPcnt;
                                        }
                                       
                                       if(batteryV != lastbatteryV) {
                                       send(msgVolt.set(batteryV, 2));
                                       lastbatteryV = batteryV;
                                       }
                                       #ifdef MY_DEBUG
                                       Serial.print("Battery Voltage: ");
                                       Serial.print(batteryV);
                                       Serial.println(" V");
                                       Serial.print("Battery percent: ");
                                       Serial.print(batteryPcnt);
                                       Serial.println(" %");
                                       #endif
                                    
                                      // Force reading sensor, so it works also after sleep()
                                      dht.readSensor(true);
                                    
                                      // Get temperature from DHT library
                                      float temperature = dht.getTemperature();
                                      if (isnan(temperature)) {
                                        Serial.println("Failed reading temperature from DHT!");
                                      } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
                                        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
                                        lastTemp = temperature;
                                        if (!metric) {
                                          temperature = dht.toFahrenheit(temperature);
                                        }
                                        // Reset no updates counter
                                        nNoUpdatesTemp = 0;
                                        temperature += SENSOR_TEMP_OFFSET;
                                        send(msgTemp.set(temperature, 1));
                                        #ifdef MY_DEBUG
                                        Serial.print("T: ");
                                        Serial.println(temperature);
                                        #endif
                                      } else {
                                        // Increase no update counter if the temperature stayed the same
                                        nNoUpdatesTemp++;
                                      }
                                    
                                      // Get humidity from DHT library
                                      float humidity = dht.getHumidity();
                                      if (isnan(humidity)) {
                                        Serial.println("Failed reading humidity from DHT");
                                      } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
                                        // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
                                        lastHum = humidity;
                                        // Reset no updates counter
                                        nNoUpdatesHum = 0;
                                        send(msgHum.set(humidity, 1));
                                    
                                        #ifdef MY_DEBUG
                                        Serial.print("H: ");
                                        Serial.println(humidity);
                                        #endif
                                      } else {
                                        // Increase no update counter if the humidity stayed the same
                                        nNoUpdatesHum++;
                                      }
                                    long sleepTime = UPDATE_INTERVAL;
                                    if (batteryPcnt < 50) {
                                      sleepTime = (sleepTime * 2);
                                    }
                                      // Sleep for a while to save energy
                                      sleepIntervalSec = sleepTime / 1000;
                                      Serial.println();
                                      Serial.print("Setting new sleep time: ");
                                      Serial.print(sleepIntervalSec);
                                      Serial.println(" seconds.");
                                      clearAlarm();
                                      delay(20);
                                      setNewAlarm();
                                      smartSleep(sleepTime);
                                    
                                    }
                                    
                                    void receive(const MyMessage &message)
                                    {
                                      // We only expect one type of message from controller. But we better check anyway.
                                      if (message.type==V_STATUS) {
                                        // Change relay state
                                        digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
                                        // Store state in eeprom
                                        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());
                                      }
                                    }
                                    

                                    Sensor startup:

                                    0 MCO:BGN:INIT NODE,CP=RRNNA--,VER=2.1.1
                                    3 MCO:BGN:BFR
                                    4 TSM:INIT
                                    5 TSF:WUR:MS=0
                                    8 TSM:INIT:TSP OK
                                    9 TSM:INIT:STATID=66
                                    11 TSF:SID:OK,ID=66
                                    13 TSM:FPAR
                                    143 TSF:MSG:SEND,66-66-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
                                    524 TSF:MSG:READ,0-0-66,s=255,c=3,t=8,pt=1,l=1,sg=0:0
                                    529 TSF:MSG:FPAR OK,ID=0,D=1
                                    2150 TSM:FPAR:OK
                                    2151 TSM:ID
                                    2152 TSM:ID:OK
                                    2154 TSM:UPL
                                    2161 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
                                    2181 TSF:MSG:READ,0-0-66,s=255,c=3,t=25,pt=1,l=1,sg=0:1
                                    2186 TSF:MSG:PONG RECV,HP=1
                                    2189 TSM:UPL:OK
                                    2190 TSM:READY:ID=66,PAR=0,DIS=1
                                    2199 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
                                    2253 TSF:MSG:READ,0-0-66,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
                                    2310 TSF:MSG:SEND,66-66-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
                                    2366 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
                                    2403 TSF:MSG:READ,0-0-66,s=255,c=3,t=6,pt=0,l=1,sg=0:M
                                    2461 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=11,pt=0,l=15,sg=0,ft=0,st=OK:Humidity sensor
                                    2562 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
                                    2618 TSF:MSG:SEND,66-66-0-0,s=2,c=0,t=30,pt=0,l=4,sg=0,ft=0,st=OK:VOLT
                                    2757 !TSF:MSG:SEND,66-66-0-0,s=0,c=0,t=7,pt=0,l=8,sg=0,ft=0,st=NACK:HUMIDITY
                                    2777 TSF:MSG:SEND,66-66-0-0,s=1,c=0,t=6,pt=0,l=4,sg=0,ft=1,st=OK:TEMP
                                    2912 !TSF:MSG:SEND,66-66-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=NACK:
                                    2918 MCO:REG:REQ
                                    2974 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=1,st=OK:2
                                    2991 TSF:MSG:READ,0-0-66,s=255,c=3,t=27,pt=1,l=1,sg=0:1
                                    2996 MCO:PIM:NODE REG=1
                                    2999 MCO:BGN:STP
                                    3154 MCO:SLP:MS=2000,SMS=0,I1=255,M1=255,I2=255,M2=255
                                    3160 MCO:SLP:TPD
                                    3161 MCO:SLP:WUP=-1
                                    3163 MCO:BGN:INIT OK,TSP=1
                                    

                                    Log Sensor: (This is when I press the button when the sensor is awake)
                                    It's sends away it's heartbeat correctly.

                                    125578 TSF:MSG:READ,0-0-66,s=3,c=1,t=2,pt=0,l=1,sg=0:0
                                    Incoming change for sensor:3, New status: 0
                                    
                                    Setting new sleep time: 5 seconds.
                                    137926 MCO:SLP:MS=5000,SMS=1,I1=255,M1=255,I2=255,M2=255
                                    137939 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=22,pt=5,l=4,sg=0,ft=0,st=OK:134932
                                    

                                    Log Openhab: And the gateway receives heartbeat.

                                    18:21:37.174 [DEBUG] [rs.internal.protocol.MySensorsWriter] - Sending to MySensors: 66;3;1;0;2;0
                                    18:21:37.178 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'TestLight' received command OFF
                                    18:21:37.181 [INFO ] [marthome.event.ItemStateChangedEvent] - TestLight changed from ON to OFF
                                    18:22:15.416 [DEBUG] [rs.internal.protocol.MySensorsReader] - 66;255;3;0;22;134932
                                    18:22:16.372 [DEBUG] [rs.internal.protocol.MySensorsWriter] - Sending to MySensors: 0;0;3;0;2;
                                    18:22:16.408 [DEBUG] [rs.internal.protocol.MySensorsReader] - 0;255;3;0;2;2.1.1
                                    

                                    Log Openhab: When the node sleeps..

                                    18:26:52.396 [DEBUG] [rs.internal.protocol.MySensorsWriter] - Sending to MySensors: 66;3;1;0;2;0
                                    18:26:52.397 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'TestLight' received command OFF
                                    18:26:52.399 [INFO ] [marthome.event.ItemStateChangedEvent] - TestLight changed from ON to OFF
                                    

                                    As you can see there is no mention in the openhab log file about buffering or smart sleep. Or a received heartbeat. Which it gets.
                                    What am I doing wrong?

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      antonholmstedt
                                      wrote on last edited by
                                      #424

                                      First I want to thank you for this binding, got it working with my esp8266 gateway without any problems at all. However, I want to ask how the reconnection problem is developing, any plans to solve it or is it not possible? I've tried to scan the thread but didn't find any information regarding it.

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        Alpoy
                                        wrote on last edited by Alpoy
                                        #425

                                        Thanks for making this binding! :)

                                        One question, is there a specific reason motion (tripped) sensors have to be Contact items?
                                        In OH2 all the Z-wave motion sensors are Switches (AFAIK) so it would be nice if the mysensor PIR's could also be Switches so I can just add these to my existing motion sensor groups and rules.

                                        (I tried setting a triggered channel as Switch but it didn't work)

                                        andreacioniA 1 Reply Last reply
                                        0
                                        • A Alpoy

                                          Thanks for making this binding! :)

                                          One question, is there a specific reason motion (tripped) sensors have to be Contact items?
                                          In OH2 all the Z-wave motion sensors are Switches (AFAIK) so it would be nice if the mysensor PIR's could also be Switches so I can just add these to my existing motion sensor groups and rules.

                                          (I tried setting a triggered channel as Switch but it didn't work)

                                          andreacioniA Offline
                                          andreacioniA Offline
                                          andreacioni
                                          wrote on last edited by
                                          #426

                                          @Alpoy check this discussion on GitHub. The question is still open.

                                          @antonholmstedt reconnection is currently implemented in binding (look here). Feel free to open an issue if you experience reconnection fails in your environment :smiley:

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


                                          15

                                          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