Navigation

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

    Posts made by stephenmhall

    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Hi Anthony.

      Funnily enough I went from the MAX system to a Honeywell Evo system and Domoticz as I have elderly parents and could not risk the times the max just forgot about all its radiators and either left the heating off or on all day.

      Had the Evo for maybe a year now with no problems. The only thing I miss with the evo is notification as to when the heating is actually on. And being able to work on my code as I did enjoy writing it.

      If you need any help with the code just ask, although it has been a while since I looked at it πŸ™‚

      Stephen

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: ESP8266 MQTT gateway + sonoff_MQTT code + vera + HA_Bridge + Alexa, oh my

      Switches working well but I can't get Temperature to update on a device.

      When switching on a sonoff locally it sends

      mygateway1-in/20/10/1/1/2/1
      

      to the MQTT broker, which immediately causes the switch on the device in Vera to show on, this is passed back out and is sent back to the sonoff.

      However I cannot get a temperature device to update. I send

      mygateway1-in/50/1/1/0/0/20.70
      

      to the Broker but get no change. I can send an html command to update the temp fine.

      here is the Vera device parameters.
      alt text

      I have tried sending to the in and the out topic just to be sure.

      Does anyone have a log from an actual temp node showing the message passed to the gateway just in case someting is not right with my message?

      Also is there a way to monitor the serial messages passed into the Vera from the gateway to check the messages are passing?

      posted in Development
      stephenmhall
      stephenmhall
    • RE: ESP8266 MQTT gateway + sonoff_MQTT code + vera + HA_Bridge + Alexa, oh my

      Would it not need to be added to the Vera as another gateway? I only have a serial gateway on the vera at the moment, I seem to remember I had problems the last time I tried to upgrade to an esp8266 ethernet Gateway and had to go back to the old serial one.

      Mysensor plugin is reporting version 1.5 lib 2.0.0

      posted in Development
      stephenmhall
      stephenmhall
    • RE: ESP8266 MQTT gateway + sonoff_MQTT code + vera + HA_Bridge + Alexa, oh my

      @Efflon I don't think it would, I'm assuming your Home Assistant controller is telling the sonoff to switch using MQTT with your config code

      mysensors:
        gateways:
          - device: mqtt
            persistence_file: '/home/homeassistant/.homeassistant/sonoff.json'
            topic_in_prefix: 'sonoff-out'
            topic_out_prefix: 'sonoff-in'
        debug: false
        optimistic: false
        persistence: true
        retain: true
        version: 2.0
      

      The problem is the Vera controller does not speak MQTT at all, there is a plugin to send device statuses out to a Broker but it's not two way. So all you could do is send the fact that the switch is on or off, but not change it.

      This gets round that by sending out a MySensors message which is then converted into MQTT to switch the Sonoff. so the Vera does not need to know about MQTT and the Sonoff units do not need to know about MySensors.

      posted in Development
      stephenmhall
      stephenmhall
    • RE: ESP8266 MQTT gateway + sonoff_MQTT code + vera + HA_Bridge + Alexa, oh my

      Broker is running on my Synology Diskstation, keeps it all in house as it were. The HA bridge is just there to allow Alexa to control Vera devices.

      posted in Development
      stephenmhall
      stephenmhall
    • ESP8266 MQTT gateway + sonoff_MQTT code + vera + HA_Bridge + Alexa, oh my

      Hi guys, I have been playing with a sonoff using MQTT and a Mosquitto server on my Synology diskstation.

      But could not see a way to get control of the sonoff on my vera (with Mysensors) as it does not support MQTT.

      I started to play with the ESP8266 MQTT gateway, the gateway has an NRF radio but is Not connected to the vera as an actual gateway.

      (I just opened a second page on Mysensors to check something and saw Efflon posted a MQTT Sonoff post but his uses home assistant which supports MQTT so I think mine is different enough to keep going)

      Ok so, here is the working chain:

      • "Alexa switch on mains plug 1"

      • Alexa talks to HA Bridge (also running on my Synology) where mains plug 1 is the friendly name of Vera virtual switch device no 181 id 20;10 parent 3

      • HA Bridge talks to Vera in html to switch on the Virtual switch with id 20;10 (I have a 433Txnode with id 20 and 6 switches) with parent id 3(Mysensors plugin)

      • Message then goes out the Mysensors serial gateway and is broadcast over NRF (20/10/1/1/2 1)

      • The ESP8266_MQTT_gateway picks up the message on NRF and sends it on to the MQTT broker (mygateway1-out/20/10/1/1/2 with message 1)

      • The SONOFF unit is subscribed to the broker and picks up the message and switches on.

      if you press the button on the sonoff it works in reverse as far as Vera, sending a message to mygateway1-in/20/10/1/1/2 0 or 1 switching the state of the virtual switch.

      The ESP8266 MQTT gateway code was unchanged.

      Sonoff MQTT code from esp8266.com

      The only change was to the topic name

      /*
      
       It connects to an MQTT server then:
        - on 0 switches off relay
        - on 1 switches on relay
        - on 2 switches the state of the relay
      
        - sends 0 on off relay
        - sends 1 on on relay
      
       It will reconnect to the server if the connection is lost using a blocking
       reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
       achieve the same result without blocking the main loop.
      
       The current state is stored in EEPROM and restored on bootup
      
      */
      
      #include <ESP8266WiFi.h>
      #include <PubSubClient.h>
      #include <Bounce2.h>
      #include <EEPROM.h>
      
      
      const char* ssid = "ssid";
      const char* password = "password";
      const char* mqtt_server = "broker IP address";
      
      WiFiClient espClient;
      PubSubClient client(espClient);
      long lastMsg = 0;
      char msg[50];
      int value = 0;
      
      //const char* outTopic = "Sonoff1out";
      const char* outTopic = "mygateway1-in/20/10/1/1/2";
      //const char* inTopic = "Sonoff1in";
      const char* inTopic = "mygateway1-out/20/10/1/1/2";
      
      int relay_pin = 12;
      int button_pin = 0;
      bool relayState = LOW;
      
      // Instantiate a Bounce object :
      Bounce debouncer = Bounce(); 
      
      
      void setup_wifi() {
      
        delay(10);
        // We start by connecting to a WiFi network
        Serial.println();
        Serial.print("Connecting to ");
        Serial.println(ssid);
      
        WiFi.begin(ssid, password);
      
        while (WiFi.status() != WL_CONNECTED) {
          extButton();
          for(int i = 0; i<500; i++){
            extButton();
            delay(1);
          }
          Serial.print(".");
        }
        digitalWrite(13, LOW);
        delay(500);
        digitalWrite(13, HIGH);
        delay(500);
        digitalWrite(13, LOW);
        delay(500);
        digitalWrite(13, HIGH);
        Serial.println("");
        Serial.println("WiFi connected");
        Serial.println("IP address: ");
        Serial.println(WiFi.localIP());
      }
      
      void callback(char* topic, byte* payload, unsigned int length) {
        Serial.print("Message arrived [");
        Serial.print(topic);
        Serial.print("] ");
        for (int i = 0; i < length; i++) {
          Serial.print((char)payload[i]);
        }
        Serial.println();
      
        // Switch on the LED if an 1 was received as first character
        if ((char)payload[0] == '0') {
          digitalWrite(relay_pin, LOW);   // Turn the LED on (Note that LOW is the voltage level
          Serial.println("relay_pin -> LOW");
          relayState = LOW;
          EEPROM.write(0, relayState);    // Write state to EEPROM
          EEPROM.commit();
        } else if ((char)payload[0] == '1') {
          digitalWrite(relay_pin, HIGH);  // Turn the LED off by making the voltage HIGH
          Serial.println("relay_pin -> HIGH");
          relayState = HIGH;
          EEPROM.write(0, relayState);    // Write state to EEPROM
          EEPROM.commit();
        } else if ((char)payload[0] == '2') {
          relayState = !relayState;
          digitalWrite(relay_pin, relayState);  // Turn the LED off by making the voltage HIGH
          Serial.print("relay_pin -> switched to ");
          Serial.println(relayState); 
          EEPROM.write(0, relayState);    // Write state to EEPROM
          EEPROM.commit();
        }
      }
      
      void reconnect() {
        // Loop until we're reconnected
        while (!client.connected()) {
          Serial.print("Attempting MQTT connection...");
          // Attempt to connect
          if (client.connect("ESP8266Client")) {
            Serial.println("connected");
            // Once connected, publish an announcement...
            client.publish(outTopic, "Sonoff1 booted");
            // ... and resubscribe
            client.subscribe(inTopic);
          } else {
            Serial.print("failed, rc=");
            Serial.print(client.state());
            Serial.println(" try again in 5 seconds");
            // Wait 5 seconds before retrying
            for(int i = 0; i<5000; i++){
              extButton();
              delay(1);
            }
          }
        }
      }
      
      void extButton() {
        debouncer.update();
         
         // Call code if Bounce fell (transition from HIGH to LOW) :
         if ( debouncer.fell() ) {
           Serial.println("Debouncer fell");
           // Toggle relay state :
           relayState = !relayState;
           digitalWrite(relay_pin,relayState);
           EEPROM.write(0, relayState);    // Write state to EEPROM
           if (relayState == 1){
            client.publish(outTopic, "1");
           }
           else if (relayState == 0){
            client.publish(outTopic, "0");
           }
         }
      }
      
      void setup() {
        EEPROM.begin(512);              // Begin eeprom to store on/off state
        pinMode(relay_pin, OUTPUT);     // Initialize the relay pin as an output
        pinMode(button_pin, INPUT);     // Initialize the relay pin as an output
        pinMode(13, OUTPUT);
        relayState = EEPROM.read(0);
        digitalWrite(relay_pin,relayState);
        
        debouncer.attach(button_pin);   // Use the bounce2 library to debounce the built in button
        debouncer.interval(50);         // Input must be low for 50 ms
        
        digitalWrite(13, LOW);          // Blink to indicate setup
        delay(500);
        digitalWrite(13, HIGH);
        delay(500);
        
        Serial.begin(115200);
        setup_wifi();                   // Connect to wifi 
        client.setServer(mqtt_server, 1883);
        client.setCallback(callback);
      }
      
      void loop() {
      
        if (!client.connected()) {
          reconnect();
        }
        client.loop();
        extButton();
      }
      
      //- See more at: http://www.esp8266.com/viewtopic.php?f=29&t=8746#sthash.vhv33y8Q.dpuf
      

      You don't need to add any extra gateways to Vera, you just add Virtual Switches and program each sonoff (or any other ESP8266) with the different Broker topics needed.

      posted in Development
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      if you need any help with my software let me know, I have swapped to a Honywell system myself so no longer use it but if I can help I will.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: πŸ’¬ Building a MQTT Gateway

      Not sure if you want to leave the GPS on there unless that isn't your house with the double hot tub in tha back garden πŸ™‚

      posted in Announcements
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Damn, just weeks after I changed to a Honeywell system. Talk about bad timing.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      As far as Cube to valves and valves to cube comms, I think it must be bi-directional as if you change anything on the cube app it happens pretty much instantly. How the cube and valves communicate could be magic for all I know πŸ™‚ they are on the 868Mhz band but what the protocol is I don't know.

      I recently read about a company in Germany called busware.de that makes a Raspberry interface card that has firmware that speaks MAX protocol, I have sent them an email looking to confirm this but not heard anything back yet. If I could cut the Cube out of my system I would be very happy as it is the least reliable part, it seems to factory reset itself every couple of months.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      What I do is only supply heat if valve is open more than 80% or more than 2 valves open 60% so heat shuts off at about 21.9 if you are looking for 22, then the residual heat in the radiator takes temp to about 22.2 before the room starts to slowly cool over the next hour or so down to 21.7 when the valve opens up enough to bring the heat back on.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Never seen that before, reading the instructions it looks like it switches the boiler on using a daily timer function like the room heating and and a thermostat temperature, possibly if it switches on if any of the rooms are cold that would work. Not saying mine is better but it monitors the valves and gives you heat on demand when any of the radiators call for it.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      @twisted I have added a text file to explain the variables. As for not turning the heating off, not sure, remember that normally the Max system will gradually close the valves on the radiators as the temp goes over the requested temp, you will normally get a half degree or so higher. if it never shuts off I don't understand that it just sends the same vera command with a 1 or a 0.

      link to variables file on Git.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      I have now changed the folder layout on github to make installing easier, also updated some of the files to hopefully stop the error on first run.

      I tried on a blank Raspberry and it all seemed to work ok.

      Give the README instructions a once over and see how it goes.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      For @simrob problem.

      I think the problem is in the database, and my code of course, With the way I developed it over time I think I added features later that cause a problem with a fresh install because It asks for the room names before it creates them. Where my database already had room names populated before I got to that point.
      Could you install "DB Browser for SQLite" and have a look at the heating.db file that was created. Under brows data there should be a rooms table like mine.

      "4" "Living Room" "1051D6"
      "5" "Dining-Extension" "106FD5"
      "2" "Bathroom" "1051DA"
      "3" "Bedroom 1" "116B63"
      "1" "Bedroom 2" "1163A5"

      If it is empty possibly just adding one record with the correct name and a random GroupID might be enough to get it past the point where it fails so it can fully populate the table. Also I think you must be using an older version as your line numbers don't quite match what I have. Try downloading the vera Virtual Thermostats branch and see if that helps, not saying it will but that will become the main branch when I sync it up.
      I will look at getting in installed again on a blank Pi so I can test and fix this properly. But hopefully putting a line of data in the DB rooms table will get you past the problem.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Ok after faffing about for ages I ended up just moving your replace quote code into the database file, keeps it out of the way and seems to work ok if I simulate a room with a quote in it and without.

      It is happy saving names with a quote in to the DB it is just searching after that needs it doubled. Something else learned.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      kk cheers, I wonder why it is needing 2 quotes? I will have a better look.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      LOL me either maybe you cant. You could save it to google drive or dropbox and post a link i think.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      grrr, can you send me a copy of your database? I am wondering if it set the room name before the other changes if there is something extra in there.

      And just to check, you are replacing one ' (quote) with two of them?

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Another tiny update to fix a problem if any of the temperatures went over 25.5 and buy tiny I mean one extra character of code in a binary format string. yesh.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      hehe know what you mean, 2 weeks off for me atm, good job as I just noticed the heating has been off for a while, oops.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Corrected an error in the webui.py code for the 0.0 temps was causing a crash.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Does ESP8266 WIFI only node require IP gateway?

      I am trying to use an ESP8266 as a node using just it's wifi connection, as far as I can see from the examples this needs a gateway with an IP address not just an NRF Radio and serial connection.

      posted in Troubleshooting
      stephenmhall
      stephenmhall
    • Does ESP8266 WIFI only node require IP gateway?

      I was trying to program an ESP8266 only node and not got far before I hit the line

      #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
      

      I currently have a serial gateway to my Vera, do I need to change to a Ethernet or ESP Wifi gateway first so I have an IP address to shoot at?

      posted in Troubleshooting
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Stuart
      I have added a new table to the DB to store good heating values. I only have one room without a wall thermostat so it is a bit hard for me to test for a 0.0 temp, it seems to work fine if there is a good temp from the room. would you be able to give it a go for me? the main changes are in the database.py and webui.py scripts. in the vera_virtual_thermostats branch.

      make sure you back up your current files before you try just in case I breaks it :). your DB too just in case. I tend to make a copy of the whole heating folder onto my PC before using changes on my live system just in case I muck it up.

      Stephen

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      @Stuart-Middleton said:

      BTW, I fixed the ' issue by changing graphing.py to use urllib.unquote() on the room name then replaced a single ' with a double ''. I then had to replace the single ' again for the html print or the page just came out empty.

      Stuart, I have made changes could you backup your graphing.py and try my one. This should be a link.

      Link to graphing.py on Github

      This shows you never know what you don't know about Python πŸ™‚ I was manually removing the html %20 spaces and never thought of other non text characters. And didn't know about the urllib functions. Old dog learning new tricks.

      Stephen

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      @Stuart-Middleton said:

      BTW, I fixed the ' issue by changing graphing.py to use urllib.unquote() on the room name then replaced a single ' with a double ''. I then had to replace the single ' again for the html print or the page just came out empty.

      Good find Stuart I will get that into the files on Github.

      If you are interested I have a new branch that sends temperatures to Vera if you have one, to populate "Virtual" Thermometers, i.e ones with no hardware. It's pretty easy to add them from the developer page. You can turn the feature on and off in the variables so it will become the main branch at some point.

      Stephen

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      If they are radiators without wall thermostats 0.0's are usual. It only seems to know when it is at temperature as it crosses the preset threshold. Then it will send out a correct temp.

      I have tried to save a copy of the last correct temperature to use until a new one comes in but not managed to get it working yet. I was doing a backward search through the database to find a good temperature but it was taking upwards of 3 seconds a room as my DB is about 56MB now. I tried creating a global dictionary to save them but ended up getting lost in the code πŸ™‚

      I might create a new text file like the variables to save them in as it does annoy me also. If you have wall thermostats its not a problem.

      posted in My Project
      stephenmhall
      stephenmhall
    • serial gateway V2 not visible to Vera

      Just tried upgrading my serial gateway to V2 but Vera will not see the serial connection. Luckily I kept the original V1.5 Nano and used another so i could swap it back and get it working again.

      Are there any changes to the serial setup I need to make changes for? Or are there slightly different Nano's that might cause problems? I tried 2 different ones with the same outcome.

      posted in Troubleshooting
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      @Stuart-Middleton Just to let you know I have updated the master branch on Github I found an error in the MAX code I borrowed that messed up the reported temps if the actual temperature went over 25.5 as you can understand in Scotland we don't see that very often. Anyway it's fixed in the Master. Also cleaned up some errors that popped up if not using the neopixel display.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      its programmed never to apologise, but I make sure it has no connection to the doors.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Thanks for that Stuart, always good to see it is getting used. Here is my latest live unit in its natural environment.

      alt text

      and a link to a video of it running on my gdrive

      Running video

      The video does not pick it up that good, it is less glowie than the film.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      @twisted Glad to be of service πŸ™‚ I was unaware of node-red before your post, It may have brushed past my awareness but not stuck. I don't see why you could not use it if you can create decoders for the MAX messages as the Cube is happy to spit out data all day. How are you physically switching your boiler?

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      North is Boiler function On/Off, East is Max Cube state, West is Vera state, South is heating normal/On/Off. The others are a Red-Heating on, Blue Heating off heartbeat.

      An update to the Mk1 version. as in this link

      Mk1 videot

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Thanks for all that @p_battino , Any recent updates have been in the Neopixel branch rather than the master, I have added direct relay support in that branch for those with no Vera. The main changes have been to change the local display from individual led's to a neopixel ring controlled by a WeMos D1 mini ESP2866 board. I only use the serial and I2C connections on the GPIO to talk to the ESP and an I2C real time clock board (which is not necessary if the RPi can see the interwebs ) All the buttons and outputs are done by the ESP. The neopixel Libraries are much better for the Arduino based boards.

      I will post some pictures when I remember how to do that 😞

      ah got it πŸ™‚
      The connector by the WeMos is for the Relay.
      0_1460565562795_IMG_20160413_170002.jpg

      0_1460565773407_IMG_20160413_170015.jpg

      link to small video of it running

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      The eco auto message is the one I have yet to find as well. I wondered if pressing it while the MAX software is connected would save a copy of the message in the logs

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Battery percentage - Help needed

      here is the battery related code from my battery powered temp sensor. Took a while to get the battery correct. Before this thread I had not seen any other code correcting for battery max / min voltages. I am using the 3.7V li-ion cells which actually seem to top out at 4.2V. I cap the percent at 99 for Vera.

      float fmap(float x, float in_min, float in_max, float out_min, float out_max) {
        return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
      }
      
      void loop()      
      {  
        delay(dht.getMinimumSamplingPeriod());
        int sensorValue = analogRead(BATTERY_SENSE_PIN);
      
         // 1M, 330K divider across battery and using internal ADC ref of 1.1V
         // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
         // ((1e6+330e3)/330e3)*1.1 = Vmax = 4.43 Volts
         // 4.43/1023 = Volts per bit = 0.0043336591723688
         // 4.2 = 100% 2.5 = 0%
      
         float batteryV  = sensorValue * 0.004333659;
         float batteryVmap = fabs(fmap(batteryV, 2.5, 4.2, 0.0, 1000.0));
         int batteryPcnt = batteryVmap / 10;
         if(batteryPcnt >= 100){
          batteryPcnt = 99;
      
      
      posted in Hardware
      stephenmhall
      stephenmhall
    • RE: Infrared Temp Sensor

      maybe you could mount 4 together on the roof and get temperatures of 4 room walls averaging out the room temperature.

      Or maybe a cheap person detector, is uncle bob sat in his favourite chair? 18deg or 30deg.

      posted in Hardware
      stephenmhall
      stephenmhall
    • RE: 2 channel in wall dimmer

      I like it, what sort of switch would be on the wall?

      posted in My Project
      stephenmhall
      stephenmhall
    • Wemos D1 mini gateway

      Just for info these work fine as a wifi gateway. Only Β£2.78 each on Aliexpress

      0_1453397837225_wemos_gateway.jpg

      and the stripboard. pretty small and the connections line up nicely.

      0_1453397825529_wemos_gateway_board.jpg

      That is all..

      posted in Hardware
      stephenmhall
      stephenmhall
    • RE: 5000mah solar battery pack

      I think these are a bit of a con. I charged an un-hacked one up to full, plugged it into my flat nexus 9 and it pulled 1.3A out for less than 21 minutes as that is when I looked round and it was off. smells a bit electrical as well if you know what I mean. I know it's been a while since I used my electrical engineering but I'm pretty sure a 5000mAh battery should supply 1A for 5 hours. Oh well, the carabiners are nice.

      posted in Hardware
      stephenmhall
      stephenmhall
    • RE: 5000mah solar battery pack

      Well i would have to say no go on these, only lasted 3 days and with my hack you lose the battery protection cut off for the lipo. seems a huge drain for a nano node, maybe the 5v step up is really inefficient I will take some current measurements. So I think unless it's possible to get around the fact that it will not supply juice to the usb socket unless there is a significant current being pulled these are a no go. shame.

      posted in Hardware
      stephenmhall
      stephenmhall
    • 5000mah solar battery pack

      Hi Guys

      I saw these on ebay and thought I would give them a go for a shed based node.

      ebay

      batterypack.JPG

      the picture is actually bigger than lifesize its just 142mm tall.

      only Β£4.95 delivered free. 5000mah with solar charging. states 200mA under full sunlight so a little daylight should keep a node going for ever.

      Unfortunately they are no use straight out of the box as they must have a current drain circuit and a node is not enough to keep it outputting juice.

      However I cracked it open and the battery is a 4v pack so I fitted a 5V step up module to the battery leads and disconnected one of the USB socket feeds and connected it to the 5V output.

      I am feeding the nano based node straight into the usb connector and the pack is held against a window in the shed which lights the green led to tell you it's charging. Only been in a few days but so far the battery has swung up and down between 93% and 97% probably depending on the amount of light. which considering the window does not face the sun and its in Scotland with all of 7 hours of sunlight at the moment if were lucky, it's not doing too bad. The current case hack is very rough but if it seems to work OK I will probably print up a new box for everything.

      posted in Hardware
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Finally sorted out the Max send command, it was the base64encode function of Python giving a different encoding . So now I can set mode and temperature via the web UI. I have not implemented the Auto/eco/comfort buttons at the top yet as I am not sure if it's a single command or you have to send for each rfAddress separately. Next update probably.

      2015-12-13.png

      I seem to have fixed the random temperature changes by factory resetting and re-adding some of the valves and wall thermostats, no random changes seen lately.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      nice, I need to rework my time plot more like yours, mine is just plotting the times as text points so if there are gaps in the data it just ignores them, I need to convert to a proper time field I think.

      Just to update, my system isn't working too bad, I did have a problem with the cube last weekend, all of a sudden it was just empty, no attached devices. I had to re pair everything. Also I occasionally get the set points jumping to the open widow temp even though I have no window sensors although that seems to have gone since the rebuild. What replaced it after the rebuild was a couple of the valves picking seemingly random set points at the time of a change, hitting AUTO again would apply the correct temp. I have removed the bedroom 1 valve and wall thermostat and factory reset them before re adding them to see if that helps.

      What I haven't managed to get working yet is sending messages to the cube, I have a test script to set a valve/Thermostat to Manual - at a lower temp but I have been unable to get it working. probably my conversion from openhab's Java to Ptyhon that is the problem.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Just for info on how it's working, this is a day in the life of the downstairs Dining room / Extension which are almost one big room also connected to the living room by a large opening. A single wall thermostat controls a radiator in each of the two rooms. As you can see once the room is up to temp the boiler is off about 60 or 65% of the time. The heating switches to the Living room about 10pm that is why the boiler is on with no valve use shown. I set the boiler on value to 12 and the valve % is /10 to keep the temps clearly visible.

      Temps.PNG

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      @twisted I would prefer wall thermostats everywhere if possible as you get a live temperature to 0.1 deg. The radiator valves report temps when they open and close, at that point they know what temperature they are at. Plus you can get the thermostat where you are looking for the heat to be. I think they would be wife usable as my 75 year old Dad can work them. I have them set to show the actual temp, a push of either + or - will show the set temp and further pushes change it. The Boost gives you 5 mins of 80% valve. The sun and moon jump to pre-set comfort and eco temps and the menu/mode goes between auto/manual/holiday set points.

      Pretty much if you keep it on auto and use + and - you cant go wrong. You can change the current auto set-point but it will change to the next timed temperature change when it comes around.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Lawrence, 6 out of 7 are quiet. One sounds like a World War 2 tank, But I have it in the bathroom, I am not sure if it was the fitting that caused the noise as it was a tight fit between the valve and the wall to get it on i.e. some amount of forced contact was made during installation. It seems to work OK.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Ok Sort of got my head around Github Here is the first upload

      https://github.com/stephenmhall/PiHeating

      Started a new Repository, the original got confused, or I did.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Hey twisted,

      More than happy to help, how close to my system is yours? Boiler switching method, Vera etc, I realise this is the Mysensors forum and I am using that for my switching but it could be switched direct from the Pi with a relay if nesesary, we just wont mention that to the moderators 😏

      I got all my MAX! stuff from http://www.conrad-electronic.co.uk/ I think they are the only distributor. Nearly everything came in a few days. I started off with a cube, 3 radiator valves and 2 wall thermostats. I have a mix of the + Valve and the standard, I was going to try the cheap one but they were out of stock. They are quite bulky compared to a standard thermostat and my plumbing was not great so some ended up mounted facing the wall to clear skirting and pipes but it's not an issue if you are using the software to adjust them. They come with mountings for 3 or so different fittings.

      I got all the details to interface with the cube at Github Max_Cube_protocol

      And the vera supports sending in commands to activate switches. Found that in their documentation.

      The 433Mhz Mysensor node just uses the cheapo Tx units off fleabay.

      I will post all the code to github when I work out how to use it πŸ™‚

      This is definitely a work in progress, butt seems to be working fine so far.

      posted in My Project
      stephenmhall
      stephenmhall
    • Boiler control from MAX! Cube to Drayton Boiler via Raspberry Pi/Vera/Mysensors.

      Hi Guys. A rather specific project that may not be much use to many others but maybe of interest if you are looking for individual radiator heater control.

      I tried the Stella-Z radiator controllers with Vera and in all honesty they were crap, they talk to the system only rarely and they only hold one setpoint at a time, all in all no good.

      So I ended up getting a full set of the eq-3 MAX! kit with 7 radiator controllers, 3 wall thermostats an eco button and the central Cube controller. Apart from the supplied software being a little annoying with it sometimes messing with the heating times it is great. I solved the software problem in the app store with MAX! Remote unofficial replacement software, very good. The only problem I was left with was my Boiler.

      British Gas Boiler fitted with a single wireless wall thermostat in the living room. I had already upgraded the simple thermostat to a Drayton +3RF giving me daily timings but it still just took the one temperature. The problem being if the temp was up in the living room at night the heat would go off and the bedrooms would not heat up for going to bed.

      So to my solution. I already have a Vera automation controller and Mysensors nodes, so I now have a Raspberry Pi that polls the Cube to get all the valve open percentages if it decides the boiler needs to be on it sends a message to the Vera which transmits out on a Mysensors 433Mhz transmitter node to turn the boiler on. The Rpi has a web interface accessible in the house so I can see current temps and boiler state and also a graph of past temps for each room. I hope to implement the Cube controls in the web interface eventually so I don't need 2 pieces of software.

      Web UI
      2015-11-29.png

      Graph
      2015-11-29 (1).png

      Rpi2 very stock and I code in Python
      Heating Pi2.jpg

      And Finally the Mysensor Board, Just done today, has been running on a breadboard until now.
      heating_Mysensor.jpg

      It still needs a box printing.

      I could wire the RPi into the boiler switch direct but I want to have the old Thermostat as backup just in case.

      So if you have a Vera and MAX! radiator valves and an Rpi and a Drayton controlled Boiler, this is for you πŸ™‚

      If anyone is interested I will post the code. It is very much my code as in an actual Python developer would go "What the!!" but it works. So far.

      posted in My Project
      stephenmhall
      stephenmhall
    • Chip the $9 computer

      I was just looking for an arduino with more memory than a nano so I can run an oled screen and remembered backing this on Kickstarter, just waiting for delivery in December. It has built in wifi and bluetooth and can run off a 3.7V lipo battery.

      As standard you get eight GPIO lines, PWM, I2C, SPI and a UART. There is also support for MIPI-CSI cameras and LCD display.

      The device has a 1GHz ARM A13 (Single core Cortex A8) compatible processor with 512MB of RAM and 4GB of Flash storage. It also has a Mali GPU with OpenGL support. beats the nano's 2k memory 32k flash :).

      It comes with a version of Debian Linux and a lot of standard software such as LibreOffice and Scratch.

      In power it sits between a Raspberry Pi B+ and the new version 2.

      Should be awesome for MySensors. Just imagine the power. Just need one as a wifi gateway. then nodes up the yingyang.

      posted in Hardware
      stephenmhall
      stephenmhall
    • RE: PC Power Switch

      pictures of the real thing

      IMG_20150628_172334.jpg

      IMG_20150628_172512.jpg

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: PC Power Switch

      Finally got it on strip board and a box is printing. I would like to get into cnc machining of 2 sided pcb's but I need some smaller bits and some extra knowledge before I start that.

      pcswitchbox3.png

      Here is what the box should look like.

      pcswitchbox2.png

      pcswitchbox.png

      Mod Everything!

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: PC Power Switch

      Well, I turned on my PC before I left work today, because I could πŸ™‚

      posted in My Project
      stephenmhall
      stephenmhall
    • Energy harvesting switches

      I got a new product update from RS components today with these on, I never new such things existed.

      http://uk.rs-online.com/web/p/rocker-switches/8736671/?origin=PSF_428186|rel

      they use the operation of the switch to power it, activations are picked up by a receiver module. And it's not over expensive either.

      posted in Hardware
      stephenmhall
      stephenmhall
    • RE: PC Power Switch

      I have been using imperihome to control my vera, a much nicer interface. and this in my PC Screen. It allows protected operations so I get a confirmation request before pushing a button. And because of the 30 second pc status update from the 5v input, the switches show the state of the PC not the switches.

      pc screen.png

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: PC Power Switch

      All connected up (temporary, you know, next 2 years) and tested. Except the force shut-down, don't want to put my drive trough that unless it is needed; but I'm running the fast lane Windows 10 so probably sometime this week.

      Only changes to circuit I needed was to link the inputs directly to the switches cutting out the test Led's. power switch is 5V but reset was 3.3V but there is no arduino supplied voltage on the inputs so it seems happy enough.

      mysensors pc switch.png

      I would say sorry about the mess, BUT I'M NOT πŸ™‚

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: PC Power Switch

      No, it will turn off and reset too. The circuit will "press" all the buttons needed.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: PC Power Switch

      Eeeeexcellent.. nice library, works great.

      // Example sketch fΓΆr a "light switch" where you can control light or something 
      // else from both vera and a local physical button (connected between digital
      // pin 3 and GND).
      // This node also works as a repeader for other nodes
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <OneButton.h>
      
      // Setup a new OneButton on pin A1.  
      OneButton BUTTON_PWR_PIN(A1, true);
      // Setup a new OneButton on pin A2.  
      OneButton BUTTON_RST_PIN(A2, true);
      
      //#define BUTTON_PWR_PIN  2  // Arduino Digital I/O pin number for button
      //#define BUTTON_RST_PIN  3  // Arduino Digital I/O pin number for button
      #define SWITCH_PRW_PIN  4  // Arduino Digital I/O pin number for SWITCH
      #define SWITCH_RST_PIN  5  // Arduino Digital I/O pin number for SWITCH
      #define PC_ON_PIN 6        // Connected to PC 5v output Molex
      #define PC_ON_LED 7        // PC On LED
      
      #define NODE_ID AUTO
      #define SKETCH_NAME "MySensor_PC_Switch"
      #define SKETCH_VERSION "1.0"
      #define NODE_REPEAT false
       
      #define CHILD_ID_SWITCH_PWR 0
      #define CHILD_ID_SWITCH_RST 1
      #define CHILD_ID_SWITCH_OFF 2
      
      #define SWITCH_ON 0
      #define SWITCH_OFF 1
      
      int pcState=0;
      int currentpcState=0;
      unsigned long status_timer = millis();
      unsigned long now_time = millis();
      unsigned long update_time = 30000;
      bool statePWR;
      bool stateRST;
      MySensor gw;
      MyMessage msgPwr(CHILD_ID_SWITCH_PWR,V_LIGHT);
      MyMessage msgRst(CHILD_ID_SWITCH_RST,V_LIGHT);
      MyMessage msgOff(CHILD_ID_SWITCH_OFF,V_LIGHT);
      
      void setup()  
      {  
        gw.begin(incomingMessage, AUTO, true);
      
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        
        // link the button 1 functions.
        BUTTON_PWR_PIN.attachClick(click1);
        BUTTON_PWR_PIN.attachLongPressStop(longPressStop1);
      
        // link the button 2 functions.
        BUTTON_RST_PIN.attachClick(click2);
      
        // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID_SWITCH_PWR, S_LIGHT);
        gw.present(CHILD_ID_SWITCH_RST, S_LIGHT);
        gw.present(CHILD_ID_SWITCH_OFF, S_LIGHT);
      
        // Make sure SWITCHs are off when starting up
        digitalWrite(SWITCH_PRW_PIN, SWITCH_OFF);
        digitalWrite(SWITCH_RST_PIN, SWITCH_OFF);
        // Then set SWITCH pins in output mode
        pinMode(SWITCH_PRW_PIN, OUTPUT);
        pinMode(SWITCH_RST_PIN, OUTPUT);
        pinMode(PC_ON_LED, OUTPUT);
        
        pinMode(PC_ON_PIN, INPUT);
      }
      
      void loop() {
        gw.process();
      
        BUTTON_PWR_PIN.tick();
        BUTTON_RST_PIN.tick();
        
        currentpcState = digitalRead(PC_ON_PIN);
        if(currentpcState != pcState) {
          if (currentpcState == HIGH) {
            pcState = 1;
            Serial.println("PC Turned on");
            digitalWrite(PC_ON_LED, HIGH);
          }
          else {
            pcState = 0;
            Serial.println("PC Turned off");
            digitalWrite(PC_ON_LED, LOW);
          }
          delay(50);
          sendPCState(1);
        }
        now_time = millis();
        if (now_time - status_timer > update_time) {
          sendPCState(1);
          status_timer = now_time;
        }
      } 
       
      void incomingMessage(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.isAck()) {
           Serial.println("This is an ack from gateway");
        }
      
        if (message.type == V_LIGHT) {
           // Change SWITCH state
           
           if (message.sensor == 0 && !message.isAck()) {
             Serial.println("Pushing Power Button");
             pushButton(SWITCH_PRW_PIN, 200);
           }
           if (message.sensor == 1 && message.getBool()) {
             Serial.println("Pushing Reset Button");
             pushButton(SWITCH_RST_PIN, 200);
           }
           if (message.sensor == 2 && !message.isAck()) {
             Serial.println("Pushing and Holding Power Button");
             pushButton(SWITCH_PRW_PIN, 6000);
           }
           
           // Write some debug info
           Serial.print("Incoming change for sensor:");
           Serial.print(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
         } 
      }
      
      void sendPCState(boolean ack){
        gw.send(msgPwr.set(pcState), ack); // Send new state and request ack back
        delay(100);
        gw.send(msgOff.set(pcState), ack); // Send new state and request ack back
        delay(100);
        gw.send(msgRst.set(stateRST), ack); // Send new state and request ack back
      }
      
      void pushButton(int button, int pushTime) {
        digitalWrite(button, SWITCH_ON);
        delay(pushTime);
        digitalWrite(button, SWITCH_OFF);
      }
      
      // ----- button 1 callback functions
      
      // This function will be called when the button1 was pressed 1 time (and no 2. button press followed).
      void click1() {
        Serial.println("Button 1 click.");
        pushButton(SWITCH_PRW_PIN, 200);
        sendPCState(1);
      } // click1
      
      // This function will be called once, when the button1 is released after beeing pressed for a long time.
      void longPressStop1() {
        Serial.println("Button 1 longPress stop");
        pushButton(SWITCH_PRW_PIN, 6000);
        sendPCState(1);
      } // longPressStop1
      
      
      // ... and the same for button 2:
      
      void click2() {
        Serial.println("Button 2 click.");
        pushButton(SWITCH_RST_PIN, 200);
        sendPCState(1);
      } // click2```
      posted in My Project
      stephenmhall
      stephenmhall
    • PC Power Switch

      Hi Guys

      Looking for more stuff to control and my eyes fell upon my PC. I was away for a week a while back and it could have been useful to be able to turn my PC on and off remotely. So here it is. Just a test circuit at the moment, but it should just be a case of replacing the power and reset led's with inputs from the case buttons to get it working.

      Luckily, and i'm not sure this is universal but my mobo's USB sockets are permanently live with the pc off so power is not an issue.

      It currently shows up as 3 switches in Vera UI7,

      Power ON/OFF
      Reset
      Power Force OFF

      The circuit has a Power switch and Reset switch for local control, What I do need is some nice code to work out if I am long pressing the Power switch to force a close.

      The toggle switch is to simulate 5V coming from the PC when powered up, this is the On detection.

      The 5V feed to the led's would be replaced by the high side of the switches in the PC.

      mysensors_pc_switch.png

      Here is the code.

      // Example sketch fΓΆr a "light switch" where you can control light or something 
      // else from both vera and a local physical button (connected between digital
      // pin 3 and GND).
      // This node also works as a repeader for other nodes
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      
      #define BUTTON_PWR_PIN  2  // Arduino Digital I/O pin number for button
      #define BUTTON_RST_PIN  3  // Arduino Digital I/O pin number for button
      #define SWITCH_PRW_PIN  4  // Arduino Digital I/O pin number for SWITCH
      #define SWITCH_RST_PIN  5  // Arduino Digital I/O pin number for SWITCH
      #define PC_ON_PIN 6        // Connected to PC 5v output Molex
      #define PC_ON_LED 7        // PC On LED
      
      #define NODE_ID AUTO
      #define SKETCH_NAME "MySensor_PC_Switch"
      #define SKETCH_VERSION "1.0"
      #define NODE_REPEAT false
       
      #define CHILD_ID_SWITCH_PWR 0
      #define CHILD_ID_SWITCH_RST 1
      #define CHILD_ID_SWITCH_OFF 2
      
      #define SWITCH_ON 0
      #define SWITCH_OFF 1
      
      Bounce debouncerPWR = Bounce(); 
      Bounce debouncerRST = Bounce(); 
      int oldPWRValue=0;
      int oldRSTValue=0;
      int pcState=0;
      int currentpcState=0;
      unsigned long status_timer = millis();
      unsigned long now_time = millis();
      unsigned long update_time = 30000;
      bool statePWR;
      bool stateRST;
      MySensor gw;
      MyMessage msgPwr(CHILD_ID_SWITCH_PWR,V_LIGHT);
      MyMessage msgRst(CHILD_ID_SWITCH_RST,V_LIGHT);
      MyMessage msgOff(CHILD_ID_SWITCH_OFF,V_LIGHT);
      
      void setup()  
      {  
        gw.begin(incomingMessage, AUTO, true);
      
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      
       // Setup the buttons
        pinMode(BUTTON_PWR_PIN,INPUT);
        digitalWrite(BUTTON_PWR_PIN,HIGH);
        pinMode(BUTTON_RST_PIN,INPUT);
        digitalWrite(BUTTON_RST_PIN,HIGH);
        
        // After setting up the button, setup debouncer
        debouncerPWR.attach(BUTTON_PWR_PIN);
        debouncerPWR.interval(5);
        debouncerRST.attach(BUTTON_RST_PIN);
        debouncerRST.interval(5);
      
        // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID_SWITCH_PWR, S_LIGHT);
        gw.present(CHILD_ID_SWITCH_RST, S_LIGHT);
        gw.present(CHILD_ID_SWITCH_OFF, S_LIGHT);
      
        // Make sure SWITCHs are off when starting up
        digitalWrite(SWITCH_PRW_PIN, SWITCH_OFF);
        digitalWrite(SWITCH_RST_PIN, SWITCH_OFF);
        // Then set SWITCH pins in output mode
        pinMode(SWITCH_PRW_PIN, OUTPUT);
        pinMode(SWITCH_RST_PIN, OUTPUT);
        pinMode(PC_ON_LED, OUTPUT);
        
        pinMode(PC_ON_PIN, INPUT);
            
        // Set SWITCH to last known state (using eeprom storage) 
        //state = gw.loadState(CHILD_ID);
        //digitalWrite(SWITCH_PIN, state?SWITCH_ON:SWITCH_OFF);
      }
      
      
      /*
      *  Example on how to asynchronously check for new messages from gw
      */
      void loop() {
        gw.process();
        debouncerPWR.update();
        debouncerRST.update();
        // Get the update value
        int valuePWR = debouncerPWR.read();
        int valueRST = debouncerRST.read();
        
        if (valuePWR != oldPWRValue && valuePWR==0) {
          pushButton(SWITCH_PRW_PIN, 200);
          sendPCState(1);
        }
        if (valueRST != oldRSTValue && valueRST==0) {
          pushButton(SWITCH_RST_PIN, 200);
          sendPCState(1);
        }
        oldPWRValue = valuePWR;
        oldRSTValue = valueRST;
        
        currentpcState = digitalRead(PC_ON_PIN);
        if(currentpcState != pcState) {
          if (currentpcState == HIGH) {
            pcState = 1;
            Serial.println("PC Turned on");
            digitalWrite(PC_ON_LED, HIGH);
          }
          else {
            pcState = 0;
            Serial.println("PC Turned off");
            digitalWrite(PC_ON_LED, LOW);
          }
          delay(50);
          sendPCState(1);
        }
        now_time = millis();
        if (now_time - status_timer > update_time) {
          sendPCState(1);
          status_timer = now_time;
        }
      } 
       
      void incomingMessage(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.isAck()) {
           Serial.println("This is an ack from gateway");
        }
      
        if (message.type == V_LIGHT) {
           // Change SWITCH state
           
           if (message.sensor == 0 && !message.isAck()) {
             Serial.println("Pushing Power Button");
             pushButton(SWITCH_PRW_PIN, 200);
           }
           if (message.sensor == 1 && message.getBool()) {
             Serial.println("Pushing Reset Button");
             pushButton(SWITCH_RST_PIN, 200);
           }
           if (message.sensor == 2 && !message.isAck()) {
             Serial.println("Pushing and Holding Power Button");
             pushButton(SWITCH_PRW_PIN, 6000);
           }
           
           // Write some debug info
           Serial.print("Incoming change for sensor:");
           Serial.print(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
         } 
      }
      
      void sendPCState(boolean ack){
        gw.send(msgPwr.set(pcState), ack); // Send new state and request ack back
        delay(100);
        gw.send(msgOff.set(pcState), ack); // Send new state and request ack back
        delay(100);
        gw.send(msgRst.set(stateRST), ack); // Send new state and request ack back
      }
      
      void pushButton(int button, int pushTime) {
        digitalWrite(button, SWITCH_ON);
        delay(pushTime);
        digitalWrite(button, SWITCH_OFF);
      }
      

      I am using bounce2 for the switches, if anyone has some nice code to detect long presses that would be great.

      What I would like to do is have just a single device in Vera with all the switches on it, but going through the xml and json files makes my head explode.

      This could be expanded to include temps and fan speeds and all sorts of malarkey.

      Oh I just had a thought, this could be really handy for server farms πŸ™‚

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Serial Gateway Board

      Mk 2 box in white ABS, the lights don't look like the picture they are more distinct.

      IMG_20150619_215949.jpg

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Serial Gateway Board

      I can't disagree on the colour, but I couldn't be bothered changing out the filament that was loaded, it could have ended up not fitting and I would have wasted it. I may redo when I load up some white.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Serial Gateway Board

      Finished and installed. Little bit of fickering to get it in, I forgot to take into account the big solder blobs on the bottom of the antenna connector.

      IMG_20150617_212700.jpg

      IMG_20150617_212728.jpg

      IMG_20150617_214417.jpg

      The lights are more distinct than the photo shows, my phone obviously really likes red.

      IMG_20150617_214442.jpg

      Now back to nodes πŸ™‚

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Serial Gateway Board

      Well I just received a RF board with external antenna so my box hopefully will now look like this.

      serial_gateway_boxB.png

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Serial Gateway Board

      And this is what I thought for a box, tunnels for the led's to shine through the lid.

      serial_gateway_box.png

      posted in My Project
      stephenmhall
      stephenmhall
    • Serial Gateway Board

      Just some pics of my Serial gateway board. Making it tidy to live in the airing cupboard.

      IMG_20150616_201622.jpg

      decided to add the led's but forgot the switch, will add it later

      IMG_20150616_201628.jpg

      And with nano and rf board

      IMG_20150616_201643.jpg

      Just need to print a nice box now.

      Oh and are the led's meant to be on all the time and flash off? cos they do. And damn, those blue led's are bright. (didn't have a yellow), doubles as a light for the cupboard.

      posted in My Project
      stephenmhall
      stephenmhall
    • RE: Combine PIR, relay, distance and gas sensors

      Okydoky

      here is some of my code from a combined temp/humidity sensor a relay and a button to trigger the relay locally. Hopefully you can put your code together with it.

      First I do some variable setup. the gap between checks (30 seconds) and millis() gives time in unix time.

      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      unsigned long CHECK_TIME = millis();
      

      in the void loop I have the gw.process() and code to check for the button being pressed and also a timer that calls the function to check the sensors. It gets the current time, subtracts the old time from it and if the difference is greater than the SLEEP_TIME it calls the check function.

      void loop()      
      {
        gw.process();
        debouncer.update();
        // Get the update value
        int value = debouncer.read();
        if (value != oldValue && value==0) {
            gw.send(msgRelay.set(state?false:true), true); // Send new state and request ack back
        }
        oldValue = value;
        
        // Check Temp and Humidity sensor every set ammount of time
        unsigned long NOW_TIME = millis();
        if(NOW_TIME - CHECK_TIME >= SLEEP_TIME) {
          getTemps();
          CHECK_TIME = NOW_TIME;
        }
      }
      

      Here is the function to read the temps, this goes below the void loop. You probably have the void incommingMesage function for MySensors, it can go above or below that.

      void getTemps(){
        delay(dht.getMinimumSamplingPeriod());
      
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
            Serial.println("Failed reading temperature from DHT");
        } else if (temperature != lastTemp) {
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          gw.send(msgTemp.set(temperature, 1));
          Serial.print("T: ");
          Serial.println(temperature);
        }
        
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
            Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum) {
            lastHum = humidity;
            gw.send(msgHum.set(humidity, 1));
            Serial.print("H: ");
            Serial.println(humidity);
        }  
      }
      

      this does the work of checking the sensors and updating the gateway if the readings have changed.

      This way it is always checking for the button being pressed, and only checking the sensors every 30 seconds, with no sleeptime. Probably not great if on batteries but that's another problem. My Arduino kung-fu is not super strong, I suspect you can set up interrupts and stuff to allow for sleeptime but that is beyond me currently.

      posted in Troubleshooting
      stephenmhall
      stephenmhall
    • RE: Decoding / converting IR-codes

      is it maybe a 48bit binary code 500 0 1350 1

      110001001101001101100100100000000000000000000100

      see if the on and off vary slightly.

      I had to work out something like this for a 433Mhz 5 way switch, if you know the pulse width you can us Rcswitch to transmit. Here is some of the code

      #include <RCSwitch.h>
      #define TRANSMIT_PIN  8  // Arduino Digital I/O pin number for relay
      RCSwitch mySwitch = RCSwitch(); // initiate RC Switch
      
      void setup() {
      // Setup 433 Transmitter
        mySwitch.enableTransmit(TRANSMIT_PIN);
        mySwitch.setPulseLength(200);   // Optional set pulse length.
      }
      
      void loop() {
        mySwitch.send("0100000101010101001100110"); //1 on
      }
      
      posted in Troubleshooting
      stephenmhall
      stephenmhall
    • RE: Combine PIR, relay, distance and gas sensors

      I would try getting rid of the sleep time and use a timer function to call the motion detection every 5 seconds. As noting else can happen during sleep.

      posted in Troubleshooting
      stephenmhall
      stephenmhall
    • RE: Request: New Sensor Type ? Thermostatically controlled switch

      I went with your suggestion, its definitely a work in progress, but there is progress.
      I have a nano with DHT22 sensor and a relay for heating on/off.
      I played with the I_Arduino.xml and L_Arduino.lua files and added

      HVAC = {26, "urn:schemas-upnp-org:device:HVAC_ZoneThermostat:1", "D_HVAC_ZoneThermostat1.xml", "HVAC "}
      
      HVAC = {40, "urn:upnp-org:serviceId:TemperatureSetpoint1", "CurrentSetpoint", "" }
      
      function SetTheNewHvacTemp(device, NewCurrentSetpoint)
      	sendCommand(luup.devices[device].id,"HVAC",NewCurrentSetpoint)
      end
      

      to L_Arduino.lua

      and

      <action>
        <serviceId>urn:upnp-org:serviceId:TemperatureSetpoint1</serviceId>
          <name>SetCurrentSetpoint</name>
            <job>
              if (p ~= nil) then p.SetTheNewHvacTemp(lul_device, lul_settings.NewCurrentSetpoint)  end
        			return 4,0
            </job>
      </action>
      

      to I_Arduino.xml

      Also added V_HVAC and S_HVAC to MyMessage.h for Arduino.

      And I get this on Vera Edge UI7

      vera_arduino_hvac.png

      As of now I can change the setpoint, although it comes back from the node as 27.6 which throws off the vera temp display, makes it 2 line but shows it, I can also send the states "CoolOn", "HeatOn" and so on.

      I haven't worked out how to get the temp on the card instead of separate, or the battery level yet.

      Here is serial from node
      vera_arduino_hvac_serial.png

      Here is my node sketch

      #include <SPI.h>
      #include <MySensor.h>  
      #include <DHT.h>
      #include <Bounce2.h>
      
      #define NODE_ID AUTO
      #define SKETCH_NAME "MySensor_Heater"
      #define SKETCH_VERSION "1.1"
      #define NODE_REPEAT true
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_HVAC 2
      #define CHILD_ID_BATT 3
      #define CHILD_ID_HEATER_SW 4
      
      #define HUMIDITY_SENSOR_DIGITAL_PIN 3
      #define RELAY_PIN  4  // Arduino Digital I/O pin number for relay 
      #define BUTTON_PIN  5  // Arduino Digital I/O pin number for button 
      #define RELAY_ON 0
      #define RELAY_OFF 1
      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      
      Bounce debouncer = Bounce(); 
      int oldValue=0;
      bool state;
      MySensor gw;
      DHT dht;
      float lastTemp;
      float lastHum;
      boolean metric = true;
      unsigned long CHECK_TIME = millis();
      String heaterMode = "Off";
      int setPoint = 20;
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      MyMessage msgHeaterSW(CHILD_ID_HEATER_SW,V_HEATER_SW);
      //MyMessage msgHeaterState(CHILD_ID_HEATER_STATE,V_HEATER);
      MyMessage msgHvac(CHILD_ID_HVAC, V_HVAC);
      MyMessage msgBattery(CHILD_ID_BATT, I_BATTERY_LEVEL);
      
      void setup()  
      { 
        gw.begin(incomingMessage,NODE_ID,NODE_REPEAT);
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      
        // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        
        // 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);
      
        // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID_HUM, S_HUM);
        gw.present(CHILD_ID_TEMP, S_TEMP);
        //gw.present(CHILD_ID_HEATER_SW, S_HEATER);
        //gw.present(CHILD_ID_HEATER_STATE, S_HEATER);
        gw.present(CHILD_ID_HVAC, S_HVAC);
        
        metric = gw.getConfig().isMetric;
        
        // Make sure relays are off when starting up
        digitalWrite(RELAY_PIN, RELAY_OFF);
        // Then set relay pins in output mode
        pinMode(RELAY_PIN, OUTPUT);   
            
        // Set relay to last known state (using eeprom storage) 
        //state = gw.loadState(CHILD_ID);
        //digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
      }
      
      void loop()      
      {
        gw.process();
        debouncer.update();
        // Get the update value
        int value = debouncer.read();
        if (value != oldValue && value==0) {
            gw.send(msgHvac.set(state?false:true), true); // Send new state and request ack back
        }
        oldValue = value;
        
        // Check Temp and Humidity sensor every set ammount of time
        unsigned long NOW_TIME = millis();
        if(NOW_TIME - CHECK_TIME >= SLEEP_TIME) {
          getTemps();
          CHECK_TIME = NOW_TIME;
        }
        
        
      }
      
      void getTemps(){
        delay(dht.getMinimumSamplingPeriod());
      
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
            Serial.println("Failed reading temperature from DHT");
        } else if (temperature != lastTemp) {
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          gw.send(msgTemp.set(temperature, 1));
          //gw.send(msgHvac.set(temperature, 1));
          gw.send(msgBattery.set(65, 1));
          Serial.print("T: ");
          Serial.println(temperature);
        }
        
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
            Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum) {
            lastHum = humidity;
            gw.send(msgHum.set(humidity, 1));
            Serial.print("H: ");
            Serial.println(humidity);
        }
      
        //gw.sleep(SLEEP_TIME); //sleep a bit
        
      }
      
      void incomingMessage(const MyMessage &message) {
        Serial.println(message.type);
        //Serial.println(message.value);
        // We only expect one type of message from controller. But we better check anyway.
        if (message.isAck()) {
           Serial.println("This is an ack from gateway");
        }
      
        if (message.type == V_HVAC) {
           // Change relay state
           Serial.println("Message received");
           setPoint = String(message.data).toInt();
           Serial.println("New Set Temp is : " + String(setPoint));
           gw.send(msgHvac.set(setPoint, 1));
           // Store state in eeprom
           //gw.saveState(CHILD_ID, state);
          
           // Write some debug info
           Serial.print("Incoming change for sensor:");
           Serial.print(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.data);
         }
        if (message.type == V_HEATER_SW) {
          Serial.println("Switch Message received");
          Serial.println(String(message.data));
          if(String(message.data) == "HeatOn"){
            Serial.println("Heating ON");
            digitalWrite(RELAY_PIN, RELAY_ON);
            //gw.send(msgHeaterSW.set("HeatOn", 1));
          }
          if(String(message.data) == "CoolOn"){
            Serial.println("Heating OFF");
            digitalWrite(RELAY_PIN, RELAY_OFF);
            //gw.send(msgHeaterSW.set("CoolOn", 1));
          }
        }
      }
      

      L_Arduino.lua
      I_Arduino1.xml
      MyMessage.h

      I have a couple of StellaZ Zwave radiator thermostats that use the hvac files, and they have many variables for temps and batteries and setpoints, but it is beyond me how to enable these for the mysensors nodes.

      We also need to be able to add a scene that goes

      If currentTemp is > currentSetpoint
        Turn on heat
      

      and looking at scenes to switch on heating, it seems you have to add a temp to create a scene involving temperature. I don't know LUUA code at all at the moment so I do not know if you can create a function that ignores the temp you had to add to create it and looks at current temp and setpoint. babbling now.

      Over to you πŸ™‚

      posted in Feature Requests
      stephenmhall
      stephenmhall