Navigation

    • Register
    • Login
    • Search
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. ShadeX12
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    ShadeX12

    @ShadeX12

    4
    Reputation
    10
    Posts
    241
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    ShadeX12 Follow

    Best posts made by ShadeX12

    • RE: Sketch kills batteries in 2-3 days

      @Nca78 Oh right!. Makes sense. If I recall correctly I think I removed that because I was having issues with door sensor not interrupting the loop to send the status update.I forgot to add it back in. I will play around tonight and see if I can get it working with sleep included again.

      I am not very experienced coding this stuff so I appreciate the help!

      posted in Development
      ShadeX12
      ShadeX12
    • RE: Adding Door sensor to Multisensor not working...

      Okay I figured this out!

      The problem was actually with where I was defining the pins. They where withing the if statement for the DHT warning. I have moved them outside that statement and it seems to be working fine.

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * 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.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Henrik Ekblad
       *
       * DESCRIPTION
       * Motion Sensor example using HC-SR501
       * http://www.mysensors.org/build/motion
       *
       */
      
      // Enable debug prints
      #define MY_DEBUG
      #define MY_NODE_ID 233
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #include <MySensors.h>
      #include <SPI.h>
      #include <DHT.h>
      #include <Bounce2.h>
      
      unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      #define DIGITAL_INPUT_SENSOR 2   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
      #define DIGITAL_INPUT_SENSOR2 3 // The input for door sensor
      #define CHILD_ID_MOTION 1   // Id of the sensor child
      #define CHILD_ID_HUM 2
      #define CHILD_ID_TEMP 3
      #define CHILD_ID_DOOR 4
      
      // Set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 4
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      
      
      // 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;
      
      
      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);
      // Initialize motion message
      MyMessage msg(CHILD_ID_MOTION, V_TRIPPED);
      MyMessage msgDoor(CHILD_ID_DOOR, V_TRIPPED);
      DHT dht;
      
      
      void presentation()  
      { 
        // Send the sketch version information to the gateway
        sendSketchInfo("TemperatureAndHumidity", "1.1");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
        present(CHILD_ID_MOTION, S_MOTION);
        present(CHILD_ID_DOOR, S_DOOR); 
        metric = getControllerConfig().isMetric;
      }
      
      
      void setup()
      {
        dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
        if (1200000 <= 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)
        sleep(dht.getMinimumSamplingPeriod());
        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
        pinMode(DIGITAL_INPUT_SENSOR2, INPUT);      // sets the door sensor digital pin as input
        digitalWrite(DIGITAL_INPUT_SENSOR2,HIGH);   // Activate internal pull-up
      }
      
      
      void loop()      
      {  
        // 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++;
        }
      
        // Read digital motion value
          bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
      
          Serial.println(tripped);
          send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
      
          
        // Read digital door value
          bool tripped2 = digitalRead(DIGITAL_INPUT_SENSOR2) == HIGH;
      
          Serial.println(tripped2);
          send(msgDoor.set(tripped2?"1":"0"));  // Send tripped value to gw
      
      
      
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, digitalPinToInterrupt(DIGITAL_INPUT_SENSOR2), CHANGE, SLEEP_TIME); 
      }
      

      Thanks again for all your help everyone!

      posted in Troubleshooting
      ShadeX12
      ShadeX12

    Latest posts made by ShadeX12

    • RE: ESP8266 Gateway with local sensors stuck in loop

      After surfing around the web a bit I eventually came up with this:

      
      void loop() {
      
        long state = digitalRead(DIGITAL_INPUT_SENSOR);
          if(state == HIGH) {
            Serial.println("Motion detected!");
            send(msg.set("1"));
            delay(1000);
          }
          else {
            Serial.println("Motion absent!");
            send(msg.set("0"));
            delay(1000);
            }
      }
      

      This seems to be working fine.

      posted in Troubleshooting
      ShadeX12
      ShadeX12
    • RE: ESP8266 Gateway with local sensors stuck in loop

      Thanks for the reply.

      I removed sleep and added wait instead. Now it just seems to output a sensor as tripped regardless of what is going on. It seems like it is not reading the state from the pin.

      void loop()
      {
      
        // Read digital motion value
        boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
              
        Serial.println(tripped);
        send(msg.set(tripped?"1":"0"));  // Send tripped value to gw 
      
        wait(5000);
      
      }
      

      Here is the serial output:

      143021 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      148086 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      153151 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      158216 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      163281 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      168346 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      173411 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      178476 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      183541 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      188606 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      193671 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      1
      198736 GWT:TPS:TOPIC=homeassistant-out/0/1/1/0/16,MSG SENT
      
      

      Any ideas?

      posted in Troubleshooting
      ShadeX12
      ShadeX12
    • ESP8266 Gateway with local sensors stuck in loop

      Hi Guys,

      I previously had this sketch working fine with a local sensor on Arduino Uno. I want to move to NodeMCU for the sake of simplicity.

      I have loaded the sketch that worked previosuly on the Ardunio onto the NodeMCU and it is stuck in the infinite loop. I suspect this has something to do with sleep not working?

      Here is the code:

      //Set NODE ID
      #define MY_NODE_ID 0
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
      #define MY_BAUD_RATE 9600
      
      // Enables and select radio type (if attached)
      //#define MY_RADIO_RF24
      //#define MY_RADIO_RFM69
      //#define MY_RADIO_RFM95
      
      #define MY_GATEWAY_MQTT_CLIENT
      #define MY_GATEWAY_ESP8266
      
      // Set this node's subscribe and publish topic prefix
      #define MY_MQTT_PUBLISH_TOPIC_PREFIX "homeassistant-out"
      #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "homeassistant-in"
      
      // Set MQTT client id
      #define MY_MQTT_CLIENT_ID "mysensors-1"
      
      // Enable these if your MQTT broker requires username/password
      #define MY_MQTT_USER "####"
      #define MY_MQTT_PASSWORD "#####"
      
      // Set WIFI SSID and password
      #define MY_WIFI_SSID "######"
      #define MY_WIFI_PASSWORD "######!"
      
      // Set the hostname for the WiFi Client. This is the hostname
      // passed to the DHCP server if not static.
      #define MY_HOSTNAME "KITCHEN_MQTT_GW"
      
      // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
      //#define MY_IP_ADDRESS 192,168,178,87
      
      // If using static ip you can define Gateway and Subnet address as well
      //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
      //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
      
      // MQTT broker ip address.
      #define MY_CONTROLLER_IP_ADDRESS 192, 168, 87, 179
      
      //MQTT broker if using URL instead of ip address.
      // #define MY_CONTROLLER_URL_ADDRESS "test.mosquitto.org"
      
      // The MQTT broker port to to open
      #define MY_PORT 1883
      
      // Enable inclusion mode
      //#define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      //#define MY_INCLUSION_BUTTON_FEATURE
      // Set inclusion mode duration (in seconds)
      //#define MY_INCLUSION_MODE_DURATION 60
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN D1
      
      // Set blinking period
      //#define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Flash leds on rx/tx/err
      //#define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
      
      #include <MySensors.h>
      
      unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
      #define CHILD_ID_PH_LOCAL 1   // Id of the sensor child
      
      // Initialize motion message
      MyMessage msg(CHILD_ID_PH_LOCAL, V_TRIPPED);
      
      void setup()
      {
        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Kitchen Motion Sensor", "2.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_PH_LOCAL, S_MOTION);
      }
      
      void loop()
      {
        // Read digital motion value
        boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
              
        Serial.println(tripped);
        send(msg.set(tripped?"1":"0"));  // Send tripped value to gw 
      
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
      }
      

      Any help you anyone can provide would be greatly appreciated.

      Thank You!

      posted in Troubleshooting
      ShadeX12
      ShadeX12
    • RE: Sketch kills batteries in 2-3 days

      So this has been an interesting journey. It turns out that you cannot use bounce with sleep, or so I read. This is what I eventually came up with for the sketch. So far it seems to be working well.

      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      #define MY_NODE_ID 213
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
      
      // Enable and select radio type attached
      #define MY_RADIO_RF24
      
      #include <SPI.h>
      #include <MySensors.h>
      
      #define DIGITAL_INPUT_SENSOR 2   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
      #define CHILD_ID_DOOR 1  
      
      // 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;
      
      int oldValue=-1;
      int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
      uint32_t SLEEP_TIME = 900000;  // sleep time between reads (seconds * 1000 milliseconds)
      int oldBatteryPcnt = 0;
      bool metric = true;
      
      MyMessage msg(CHILD_ID_DOOR, V_TRIPPED);
      
      void presentation() 
      {
        // Send the sketch version information to the gateway
        sendSketchInfo("Closet Door", "3.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_DOOR, S_DOOR);  
        metric = getControllerConfig().isMetric;
      }
      
      void setup()  
      {  
          // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
          analogReference(INTERNAL1V1);
      #else
          analogReference(INTERNAL);
      #endif
      
        // Setup the button
        pinMode(DIGITAL_INPUT_SENSOR,INPUT);
        // Activate internal pull-up
        digitalWrite(DIGITAL_INPUT_SENSOR,HIGH);
      
      }
      
      
      void loop() 
      {
      
             // get the battery Voltage
           int sensorValue = analogRead(BATTERY_SENSE_PIN);
           Serial.println(sensorValue);
           int batteryPcnt = sensorValue / 10;
           sendBatteryLevel(batteryPcnt);
           oldBatteryPcnt = batteryPcnt;
      
        // Read digital motion value
          bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
      
          Serial.println(tripped);
          send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
      
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME); 
        
      }```
      posted in Development
      ShadeX12
      ShadeX12
    • RE: Sketch kills batteries in 2-3 days

      @Nca78 Oh right!. Makes sense. If I recall correctly I think I removed that because I was having issues with door sensor not interrupting the loop to send the status update.I forgot to add it back in. I will play around tonight and see if I can get it working with sleep included again.

      I am not very experienced coding this stuff so I appreciate the help!

      posted in Development
      ShadeX12
      ShadeX12
    • Sketch kills batteries in 2-3 days

      Greetings All,

      I suspect the issue I have is with my sketch and not hardware. I've had this issue on two different sensors with the same result. Also, I noticed that the status LED remains lit. I don't see this with my other sketches. I basically tried to combine a door sensor with battery metering using the examples. Perhaps someone can point out where I went wrong?

      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      #define MY_NODE_ID 8
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      
      #define CHILD_ID 1
      #define BUTTON_PIN  2  // Arduino Digital I/O pin for button/reed switch
      
      Bounce debouncer = Bounce(); 
      int oldValue=-1;
      int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
      uint32_t SLEEP_TIME = 900000;  // sleep time between reads (seconds * 1000 milliseconds)
      int oldBatteryPcnt = 0;
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(CHILD_ID,V_TRIPPED);
      
      void setup()  
      {  
          // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
          analogReference(INTERNAL1V1);
      #else
          analogReference(INTERNAL);
      #endif
      
        // Setup the button
        pinMode(BUTTON_PIN,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN,HIGH);
      
        // After setting up the button, setup debouncer
        debouncer.attach(BUTTON_PIN);
        debouncer.interval(5);
      
      }
      
      void presentation() {
        // Register binary input sensor to gw (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        present(CHILD_ID, S_DOOR);  
        sendSketchInfo("Front Door", "1.0");
      }
      
      
      //  Check if digital input has changed and send in new value
      void loop() 
      {
        debouncer.update();
        // Get the update value
        int value = debouncer.read();
      
        if (value != oldValue) {
           // Send in the new value
           send(msg.set(value==HIGH ? 1 : 0));
           oldValue = value;
             // get the battery Voltage
           int sensorValue = analogRead(BATTERY_SENSE_PIN);
           Serial.println(sensorValue);
           int batteryPcnt = sensorValue / 10;
           sendBatteryLevel(batteryPcnt);
           oldBatteryPcnt = batteryPcnt;
        }
      }
      
      posted in Development
      ShadeX12
      ShadeX12
    • RE: Adding Door sensor to Multisensor not working...

      Okay I figured this out!

      The problem was actually with where I was defining the pins. They where withing the if statement for the DHT warning. I have moved them outside that statement and it seems to be working fine.

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * 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.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Henrik Ekblad
       *
       * DESCRIPTION
       * Motion Sensor example using HC-SR501
       * http://www.mysensors.org/build/motion
       *
       */
      
      // Enable debug prints
      #define MY_DEBUG
      #define MY_NODE_ID 233
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #include <MySensors.h>
      #include <SPI.h>
      #include <DHT.h>
      #include <Bounce2.h>
      
      unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      #define DIGITAL_INPUT_SENSOR 2   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
      #define DIGITAL_INPUT_SENSOR2 3 // The input for door sensor
      #define CHILD_ID_MOTION 1   // Id of the sensor child
      #define CHILD_ID_HUM 2
      #define CHILD_ID_TEMP 3
      #define CHILD_ID_DOOR 4
      
      // Set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 4
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      
      
      // 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;
      
      
      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);
      // Initialize motion message
      MyMessage msg(CHILD_ID_MOTION, V_TRIPPED);
      MyMessage msgDoor(CHILD_ID_DOOR, V_TRIPPED);
      DHT dht;
      
      
      void presentation()  
      { 
        // Send the sketch version information to the gateway
        sendSketchInfo("TemperatureAndHumidity", "1.1");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
        present(CHILD_ID_MOTION, S_MOTION);
        present(CHILD_ID_DOOR, S_DOOR); 
        metric = getControllerConfig().isMetric;
      }
      
      
      void setup()
      {
        dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
        if (1200000 <= 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)
        sleep(dht.getMinimumSamplingPeriod());
        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
        pinMode(DIGITAL_INPUT_SENSOR2, INPUT);      // sets the door sensor digital pin as input
        digitalWrite(DIGITAL_INPUT_SENSOR2,HIGH);   // Activate internal pull-up
      }
      
      
      void loop()      
      {  
        // 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++;
        }
      
        // Read digital motion value
          bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
      
          Serial.println(tripped);
          send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
      
          
        // Read digital door value
          bool tripped2 = digitalRead(DIGITAL_INPUT_SENSOR2) == HIGH;
      
          Serial.println(tripped2);
          send(msgDoor.set(tripped2?"1":"0"));  // Send tripped value to gw
      
      
      
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, digitalPinToInterrupt(DIGITAL_INPUT_SENSOR2), CHANGE, SLEEP_TIME); 
      }
      

      Thanks again for all your help everyone!

      posted in Troubleshooting
      ShadeX12
      ShadeX12
    • RE: Adding Door sensor to Multisensor not working...

      Thanks a lot everyone for the responses. I have got a little further. I am now able to get readings from the door sensor...sort of.

      Everything works fine with the sensor if the door switch is close. As soon as the switch is open, it flips to open the close over and over again a spams the gateway with the messages.

      Here's what I've got for code. I suspect maybe something is wrong with the loop.

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * 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.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Henrik Ekblad
       *
       * DESCRIPTION
       * Motion Sensor example using HC-SR501
       * http://www.mysensors.org/build/motion
       *
       */
      
      // Enable debug prints
      #define MY_DEBUG
      #define MY_NODE_ID 233
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #include <MySensors.h>
      #include <SPI.h>
      #include <DHT.h>
      #include <Bounce2.h>
      
      unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      #define DIGITAL_INPUT_SENSOR 2   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
      #define DIGITAL_INPUT_SENSOR2 3 // The input for door sensor
      #define CHILD_ID_MOTION 1   // Id of the sensor child
      #define CHILD_ID_HUM 2
      #define CHILD_ID_TEMP 3
      #define CHILD_ID_DOOR 4
      
      // Set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 4
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      
      
      // 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;
      
      
      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);
      // Initialize motion message
      MyMessage msg(CHILD_ID_MOTION, V_TRIPPED);
      MyMessage msgDoor(CHILD_ID_DOOR, V_TRIPPED);
      DHT dht;
      
      
      void presentation()  
      { 
        // Send the sketch version information to the gateway
        sendSketchInfo("TemperatureAndHumidity", "1.1");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
        present(CHILD_ID_MOTION, S_MOTION);
        present(CHILD_ID_DOOR, S_DOOR); 
        metric = getControllerConfig().isMetric;
      }
      
      
      void setup()
      {
        dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
        if (1200000 <= dht.getMinimumSamplingPeriod()) {
          Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
          pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
          pinMode(DIGITAL_INPUT_SENSOR2, INPUT);      // sets the door sensor digital pin as input
          digitalWrite(DIGITAL_INPUT_SENSOR2,HIGH);   // Activate internal pull-up
        }
        // 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)
        sleep(dht.getMinimumSamplingPeriod());
      }
      
      
      void loop()      
      {  
        // 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++;
        }
      
        // Read digital motion value
          bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
      
          Serial.println(tripped);
          send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
      
          
        // Read digital door value
          bool tripped2 = digitalRead(DIGITAL_INPUT_SENSOR2) == HIGH;
      
          Serial.println(tripped2);
          send(msgDoor.set(tripped2?"1":"0"));  // Send tripped value to gw
      
      
      
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, digitalPinToInterrupt(DIGITAL_INPUT_SENSOR2), CHANGE, SLEEP_TIME); 
      }
      
      
      
      posted in Troubleshooting
      ShadeX12
      ShadeX12
    • RE: Adding Door sensor to Multisensor not working...

      @alexsh1

      Thanks for the response. I should have been more clear. I currently have motion, temperature and humidity. I am trying to add a reed switch to use as a door sensor.

      With the code a I posted above motion temp and humidity all work fine but I cannot get any output from the reed switch. I have tested the switch itself and it is fine, so I know it is my code. I am not much of a coder so I mostly sticking stuff together from the examples and trying to learn and improve but I really don't know what I am doing.

      BUTTON_PIN I believe is where i define which pin on the Arduino to connect the reed switch to.

      The serial output shows that the reed switch registers with the gateway and I can see it in Home Assisstant, but it never updates or outputs anything in the logs again after this line:

      189 TSF:MSG:SEND,233-233-0-0,s=4,c=0,t=0,pt=0,l=0,sg=0,ft=0,st=OK:

      I made the change to the code as you suggested but it didn't seem to any effect, positive or negative.

      posted in Troubleshooting
      ShadeX12
      ShadeX12
    • Adding Door sensor to Multisensor not working...

      Greetings All,

      I previously had a working sketch for a multi-sensor. I have since tried to add a door switch to the sketch but i can't get it working at all. All the other sensors seem to be working. Any advice you can provide would be greatly appreciated.

      // Enable debug prints
      #define MY_DEBUG
      #define MY_NODE_ID 233
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      
      #include <MySensors.h>
      #include <SPI.h>
      #include <DHT.h>
      #include <Bounce2.h>
      
      unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
      #define CHILD_ID_MOTION 1   // Id of the sensor child
      #define CHILD_ID_HUM 2
      #define CHILD_ID_TEMP 3
      #define CHILD_ID_DOOR 4
      
      // Set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 5
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      #define BUTTON_PIN  7  // Arduino Digital I/O pin for button/reed switch
      
      // 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;
      
      Bounce debouncer = Bounce(); 
      int oldValue=-1;
      
      float lastTemp;
      float lastHum;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      bool metric = true;
      
      MyMessage msgHum(CHILD_ID_HUM, V_HUM), msgDoor(CHILD_ID_DOOR, V_TRIPPED), msgTemp(CHILD_ID_TEMP, V_TEMP), msg(CHILD_ID_MOTION, V_TRIPPED);
      DHT dht;
      
      
      void presentation()  
      { 
        // Send the sketch version information to the gateway
        sendSketchInfo("TemperatureHumidityMotionAndDoor", "1.2");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
        present(CHILD_ID_MOTION, S_MOTION);
        present(CHILD_ID_DOOR, S_DOOR); 
      
        metric = getControllerConfig().isMetric;
      }
      
      
      void setup()
      {
        dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
        if (1200000 <= dht.getMinimumSamplingPeriod()) {
          Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
          pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
            // Setup the button
          pinMode(BUTTON_PIN,INPUT_PULLUP);
           // Activate internal pull-up
          digitalWrite(BUTTON_PIN,HIGH);
      
           // After setting up the button, setup debouncer
          debouncer.attach(BUTTON_PIN);
          debouncer.interval(5);
        }
        // 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)
        sleep(dht.getMinimumSamplingPeriod());
      }
      
      
      void loop()      
      {  
      
        // 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++;
        }
      
        debouncer.update();
        // Get the update value
        int value = debouncer.read();
      
        if (value != oldValue) {
           // Send in the new value
           send(msgDoor.set(value==HIGH ? 1 : 0));
           oldValue = value;
      
          #ifdef MY_DEBUG
          Serial.print("D: ");
          Serial.println(value);
          #endif
        }
      
        // Read digital motion value
          bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
      
          Serial.println(tripped);
          send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
      
      
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
         sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME); 
      }
      

      Thanks!

      posted in Troubleshooting
      ShadeX12
      ShadeX12