Navigation

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

    Bryden

    @Bryden

    2
    Reputation
    19
    Posts
    378
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Bryden Follow

    Best posts made by Bryden

    • RE: 💬 Sonoff relay using MySensors ESP8266 wifi or mqtt gateway

      Another I have had these running posts.

      I have had 3 Sonoff relays running on 240v 50Hz for 2-3 months straight.

      2 of them in IP67 outdoor lights with Phillips LED Lamps, switch on and off several times per day, Not a single hardware issue.

      best $6 ever

      posted in OpenHardware.io
      Bryden
      Bryden
    • RE: DHT22 verify issue.

      seems to be fixed after I deleted and reinstalled the DHT library several time.

      Thanks mfalkvidd

      posted in Troubleshooting
      Bryden
      Bryden

    Latest posts made by Bryden

    • RE: 💬 Sonoff relay using MySensors ESP8266 wifi or mqtt gateway

      Another I have had these running posts.

      I have had 3 Sonoff relays running on 240v 50Hz for 2-3 months straight.

      2 of them in IP67 outdoor lights with Phillips LED Lamps, switch on and off several times per day, Not a single hardware issue.

      best $6 ever

      posted in OpenHardware.io
      Bryden
      Bryden
    • RE: 💬 Sonoff relay using MySensors ESP8266 wifi or mqtt gateway

      Does anyone know how I can request the current state of the relay via MQTT.

      Eg HASS has rebooted, forgotten what state the switch was previously in, then it wont work untill power is cycled to the sonoff.

      I want to send an MQTT message to the sonoff to get its current state. Tried looking over the forums and page and cant seem to see anything about requesting a state from a binary switch / relay actuator

      posted in OpenHardware.io
      Bryden
      Bryden
    • RE: MQ DHT and Relai receive not working

      What @mfalkvidd said, I had the same issue on an esp8266

      posted in Development
      Bryden
      Bryden
    • RE: Combining DHT and Binary sensor update issue

      Thought it might be a little harder than my pay grade.

      might implement it a little later

      posted in Development
      Bryden
      Bryden
    • Combining DHT and Binary sensor update issue

      Having an issue trying to figure how to get instant response from the binary inputs (reed switch) whilst also having a DHT in the mix.

      The issue is that the binary change only gets sent when the temp or humidity is sent.

      Running the code with out the DHT in there work flawlessly. and state changes are sent immediately

      I assume is has to do with the Wait function in the loop, but with out that wait you poll the DHT too much and it wont read any data.

      Set up is NodeMCU as MQTT gateway. running 2.0

      Thanks

      
      #include <ESP8266WiFi.h>
      #include <MySensors.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #include <DHT.h>
      
      // DHT22
      
      // Set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 12
      
      // 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 = 60000;
      
      // 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 4
      #define CHILD_ID_TEMP 5
      
      float lastTemp;
      float lastHum;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      bool metric = true;
      
      
      // Setting multiple child ID's for each switch and it's GPIO pin
      //Switch 1
      #define CHILD_ID_1 1
      #define BUTTON_PIN_1  4  // Arduino Digital I/O pin for button/reed switch
      
      //Switch 2
      #define CHILD_ID_2 2
      #define BUTTON_PIN_2  5  // Arduino Digital I/O pin for button/reed switch
      
      //Switch 3
      #define CHILD_ID_3 3
      #define BUTTON_PIN_3  10  // Arduino Digital I/O pin for button/reed switch
      
      //Switch 1
      Bounce debouncer_1 = Bounce(); 
      int oldValue_1=-1;
      
      //Switch 2
      Bounce debouncer_2 = Bounce(); 
      int oldValue_2=-1;
      
      //Switch 3
      Bounce debouncer_3 = Bounce(); 
      int oldValue_3=-1;
      
      // Setting mysensor message string (ChildID, V type)
      MyMessage msg1(CHILD_ID_1,V_TRIPPED);
      MyMessage msg2(CHILD_ID_2,V_TRIPPED);
      MyMessage msg3(CHILD_ID_3,V_TRIPPED);
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      DHT dht;
      
      //Presenting each child ID
      void presentation() {
        // Register binary input sensor to gw (they will be created as child devices)
        //Switch
        present(CHILD_ID_1, S_DOOR);
        present(CHILD_ID_2, S_DOOR);
        present(CHILD_ID_3, S_DOOR);  
        //DHT 
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
        
        metric = getControllerConfig().isMetric;
      }
      
      //Setting up each GPIO pin as an input and turning on internal pull up resistor
      void setup()
      {  
       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)
        sleep(dht.getMinimumSamplingPeriod());
      
        // Setup button 1
        pinMode(BUTTON_PIN_1,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_1,HIGH);
        // After setting up the button, setup debouncer
        debouncer_1.attach(BUTTON_PIN_1);
        debouncer_1.interval(5);
      
        // Setup button 2
        pinMode(BUTTON_PIN_2,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_2,HIGH);
        // After setting up the button, setup debouncer
        debouncer_2.attach(BUTTON_PIN_2);
        debouncer_2.interval(5);
      
        // Setup button 3
        pinMode(BUTTON_PIN_3,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_3,HIGH);
        // After setting up the button, setup debouncer
        debouncer_3.attach(BUTTON_PIN_3);
        debouncer_3.interval(5);
      }
      
      void loop() 
      {
        //DHT
        // 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++;
        }
      
          
        // Switch 1
        debouncer_1.update();
        // Get the update value
        int value_1 = debouncer_1.read();
        if (value_1 != oldValue_1) {
           // Send in the new value
           send(msg1.set(value_1==HIGH ? 1 : 0));
           oldValue_1 = value_1;
        }
        // Switch 2
        debouncer_2.update();
        // Get the update value
        int value_2 = debouncer_2.read();
        if (value_2 != oldValue_2) {
           // Send in the new value
           send(msg2.set(value_2==HIGH ? 1 : 0));
           oldValue_2 = value_2;
        }
        // Switch 3
        debouncer_3.update();
        // Get the update value
        int value_3 = debouncer_3.read();
        if (value_3 != oldValue_3) {
           // Send in the new value
           send(msg3.set(value_3==HIGH ? 1 : 0));
           oldValue_3 = value_3;
        }
      
          // Sleep for a while to save energy
        wait(UPDATE_INTERVAL); 
      }```
      posted in Development
      Bryden
      Bryden
    • RE: 💬 Sonoff relay using MySensors ESP8266 wifi or mqtt gateway

      This sketch is awesome, First MySensors sketch I have used that worked straight off the bat.

      The details page does need a few extra bits of info....

      3.3v FTDI tool needed

      Hold down the button on the Sonoff when you power it up to enter flash mode.

      posted in OpenHardware.io
      Bryden
      Bryden
    • MQTT 3 Door switch sketch (Single relay to be added)

      Hey Guys,

      After searching a ton and doing a heap of reading, I couldn't find a multiple door switch sketch that works on 2.xx at all.

      I have this sketch working on the bench on a nodeMCU, Works best when 10k external pull ups are used as well.

      Going to add a relay to the sketch as well next now I have the 3 door switch's working.

      So I'm just sharing this so others can see hows its done.

      I'm a copy paste programmer so please dont shoot any mistakes or lack of knowledge, I'm sure there is a better way of doing it like I have seen in the relay sketch with some ++ sort of thing I have yet to work out.

      This is designed to be used with Home Assistant, It will monitor a garage door with open and closed reed switches, The internal door into the house, and the relay will trigger the garage internal light. But you could use it with whatever you want.
      Enjoy.

      /**
       * 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
       * The ESP8266 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker.
       * The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network
       *
       * LED purposes:
       * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch
       * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
       * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
       * - ERR (red) - fast blink on error during transmission error or recieve crc error
       *
       * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions.
       * nRF24L01+  ESP8266
       * VCC        VCC
       * CE         GPIO4
       * CSN/CS     GPIO15
       * SCK        GPIO14
       * MISO       GPIO12
       * MOSI       GPIO13
       *
       * Not all ESP8266 modules have all pins available on their external interface.
       * This code has been tested on an ESP-12 module.
       * The ESP8266 requires a certain pin configuration to download code, and another one to run code:
       * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
       * - Connect GPIO15 via 10K pulldown resistor to GND
       * - Connect CH_PD via 10K resistor to VCC
       * - Connect GPIO2 via 10K resistor to VCC
       * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
       *
        * Inclusion mode button:
       * - Connect GPIO5 via switch to GND ('inclusion switch')
       *
       * Hardware SHA204 signing is currently not supported!
       *
       * Make sure to fill in your ssid and WiFi password below for ssid & pass.
       */
      
      
      // 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_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_GATEWAY_MQTT_CLIENT
      #define MY_GATEWAY_ESP8266
      
      // Set this node's subscribe and publish topic prefix
      #define MY_MQTT_PUBLISH_TOPIC_PREFIX "ESP2-out"
      #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "ESP2-in"
      
      // Set MQTT client id
      #define MY_MQTT_CLIENT_ID "ESP2"
      
      // Enable these if your MQTT broker requires usenrame/password
      #define MY_MQTT_USER "******"
      #define MY_MQTT_PASSWORD "******"
      
      // Set WIFI SSID and password
      #define MY_ESP8266_SSID "******"
      #define MY_ESP8266_PASSWORD "******"
      
      // Set the hostname for the WiFi Client. This is the hostname
      // it will pass to the DHCP server if not static.
      #define MY_ESP8266_HOSTNAME "ESP2"
      
      // 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 need to 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 ******
      
      // The MQTT broker port to to open
      #define MY_PORT 1883
      
      #include <ESP8266WiFi.h>
      #include <MySensors.h>
      #include <SPI.h>
      #include <Bounce2.h>
      
      
      // Setting multiple child ID's for each switch and it's GPIO pin
      //Switch 1
      #define CHILD_ID_1 1
      #define BUTTON_PIN_1  4  // Arduino Digital I/O pin for button/reed switch
      
      //Switch 2
      #define CHILD_ID_2 2
      #define BUTTON_PIN_2  5  // Arduino Digital I/O pin for button/reed switch
      
      //Switch 3
      #define CHILD_ID_3 3
      #define BUTTON_PIN_3  10  // Arduino Digital I/O pin for button/reed switch
      
      //switch 1
      Bounce debouncer_1 = Bounce(); 
      int oldValue_1=-1;
      
      //switch 2
      Bounce debouncer_2 = Bounce(); 
      int oldValue_2=-1;
      
      //switch 3
      Bounce debouncer_3 = Bounce(); 
      int oldValue_3=-1;
      
      // Setting mysensor message string (ChildID, V type)
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg1(CHILD_ID_1,V_TRIPPED);
      MyMessage msg2(CHILD_ID_2,V_TRIPPED);
      MyMessage msg3(CHILD_ID_3,V_TRIPPED);
      
      
      //Presenting each child ID
      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_1, S_DOOR);
        present(CHILD_ID_2, S_DOOR);
        present(CHILD_ID_3, S_DOOR);   
      }
      
      
      //Setting up each GPIO pin as an input and turning on internal pull up resistor
      void setup()
      {  
        // Setup the button 1
        pinMode(BUTTON_PIN_1,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_1,HIGH);
        // After setting up the button, setup debouncer
        debouncer_1.attach(BUTTON_PIN_1);
        debouncer_1.interval(5);
      
          // Setup the button 2
        pinMode(BUTTON_PIN_2,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_2,HIGH);
        // After setting up the button, setup debouncer
        debouncer_2.attach(BUTTON_PIN_2);
        debouncer_2.interval(5);
      
          // Setup the button 3
        pinMode(BUTTON_PIN_3,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_3,HIGH);
        // After setting up the button, setup debouncer
        debouncer_3.attach(BUTTON_PIN_3);
        debouncer_3.interval(5);
      }
      
      
      
      
      void loop() 
      {
      
        // Switch 1
        debouncer_1.update();
        // Get the update value
        int value_1 = debouncer_1.read();
        if (value_1 != oldValue_1) {
           // Send in the new value
           send(msg1.set(value_1==HIGH ? 1 : 0));
           oldValue_1 = value_1;
        }
        // Switch 2
        debouncer_2.update();
        // Get the update value
        int value_2 = debouncer_2.read();
        if (value_2 != oldValue_2) {
           // Send in the new value
           send(msg2.set(value_2==HIGH ? 1 : 0));
           oldValue_2 = value_2;
        }
        // Switch 3
        debouncer_3.update();
        // Get the update value
        int value_3 = debouncer_3.read();
        if (value_3 != oldValue_3) {
           // Send in the new value
           send(msg3.set(value_3==HIGH ? 1 : 0));
           oldValue_3 = value_3;
        }
      }
      
      
      posted in My Project
      Bryden
      Bryden
    • RE: By uploading the DHT 22 sketch, I get an error each time.

      @alowhum They seem to be not quite as easy for copy paste programming. I have had to do a heap of reading and learning to get it all down.

      Any the other one is you search the forums for soloutions before posting and half the solutions are pre 2.x and dont work either, I don't like noob posting basic stuff due to my lack of programming skill, but people here seem quite nice and willing to help 🙂

      Wait for my debouncing post later tonight if I cant work it out hahaha

      posted in Development
      Bryden
      Bryden
    • RE: By uploading the DHT 22 sketch, I get an error each time.

      This seems to be a common issue, maybe a change to highlight that the exact listed DHT library mentioned needs to be installed and no other lol

      posted in Development
      Bryden
      Bryden
    • RE: DHT22 verify issue.

      I suppose I could remove the sleep / wait function all together seems as it's going to run off mains and not a battery, which is what I would assume people wanted a sleep function for altogether.

      posted in Troubleshooting
      Bryden
      Bryden