OK, HomeAssistant runs on RaspberryPi, but the RPi only has digital in/out, but what if I want to read analog values from sensors? One solution appears to be to use an Arduino, since this is the sort of thing they do well. However, finding details of how to do this seems a bit sketchy. I could use I2C, but that seems a bit tricky. I did read that I can use USB, which is convenient because that will also give me power for the Arduino. To use an Arduino as an add-on board for the RPi, I had read about something called Firmata, which loads as a sketch running on the Arduino. This is easy at the Arduino end, as it is just one of the examples pre-installed, upload and it’s ready to go.
I set up the configuration in HomeAssistant and immediately got a whole heap of errors, mostly referring to needing PyMata 2.14. Now PyMata is a client library that allows Python to control the Arduino. Obviously not part of the standard RPi/Hassbian image. After a bit of messing around here’s what I managed to do:
Plug the Arduino into your computer, load up the IDE and upload the StandardFirmata sketch (found in the Examples submenu)
Plug the Arduino into a USB port on the RPi. Log into the RPi using SSH
At the command line, run:
sudo pip3 install pymata
If you download the examples from the GitHub repository, you should be able to call the blink sketch to verify that all is working. It should flash the LED 10 times, and you should see the process running in your terminal session counting down. (Note that my UNO clone is connected at ‘/dev/ttyACM0’, so the script works as is.
Add the following entries to your configuration.yaml script and save it:
The LED should show up as another switch in your dashboard, and turning it on should light the pin 13 LED on the Arduino
Note that it appears you can only read analog input pins, and switch digital output pins through this interface. No PWM, and I suppose if you need to read digital inputs then you can do that directly on the RPi.
Thought it was time to step up the home automation effort, so a mention of HomeAssistant on a blog had me interested. So now the RaspberryPi is running some new software and I’ve been tinkering with this seeing what it can do. There’s not too many things in the house that are ‘smart’, but I can turn the TV off and control a WeMo switch. Much of the built-in functionality is impressive, so triggers for sunset or time let one test how it works. Integration with my phone also lets it track location and use geofencing for triggers also.
I’d be interested to see what can be done once I can integrate with other systems in the house, such as the alarm system, thermostat or pool controllers. Being open-source and open, there’s plenty of scope to ‘roll-your-own’ to meet individual needs.
Here’s a useful article on using the Hass.io version of HomeAssistant. Worth a look.
I bought a NodeMCU module a while back, but couldn’t figure out how to use it at the time. I also played with one of the ESP8266 modules using a FTDI adaptor to also convert to 3V3, but it seemed rather flaky. In the end, I found I could simply hook up the NodeMCU to a USB port and use the Arduino IDE. To save a whole lot of messing around, I also set up Blynk, which works briliantly with this type of device. One slight complication is that the NodeMCU tries to map pins to equivalent Arduino pinouts, whilst Blynk is still aware of the GPIO pinouts. Finding a pinout diagram here helped make sense of it.
It also seems that the USB ports on my MacBook Pro aren’t reliable with this device, whether it isn’t so happy with USB 3.0 ports or whether it’s not supplying enough current I can’t tell. When it shows up it is easy to flash it with the Arduino sketch. Plugging the board into a phone charger it works 100%. I’m also testing out an el cheapo phone battery booster from K-Mart as a portable power source for projects, and at only $5 this is great value, so I plan to pick up a few more.
Suddenly I see a whole lot of benefits of using these inexpensive NodeMCU boards in place of Arduinos for lightweight projects, considering that you get Wi-Fi built in.
So this project had been sitting on my desk for ages now with the sensors and RF module spread across two breadboards with a mess of wire connecting it all up. Today I finally found some time to add the RF module to a prototyping shield. The other sensors are still on a breadboard and that’s the extra wires hanging off it, but it’s one step closer to a finished project. Some of the soldering was a bit fiddly but worked straight off.
Last week just as we were getting used to sunshine again the weather reminded us it’s still winter. Sitting in a meeting Thursday afternoon hearing the wind and rain crashing around the building I pulled up the weather feed and you can see when it really hit.
This shot is from about 4:25pm. Temperature dropped about 10 °C in an hour. You can see the humidity shot up too with the rain.
This morning we woke up to a coating of frost on everything, and the weather station told me that despite the bright sunny morning it was -0.4 °C outside. Guess there’s still more days to go skiing this season!
After merging the XC0348 code I had which was receiving the data transmitted by the outdoor sensors with the Xively code there was a bit of tweaking to do to get the sketch to play nicely. The last step was to add the code back for the pressure sensor. This was problematic as the sensor uses I2C and soon as I added the Wire library the whole thing stopped running properly. After some reading I wondered if I was just running out of memory so I commented out a whole lot of serial print statements and it this got things working again. Of course, without the print statements there was a whole lot less debugging going on.
A couple of things that still need attention:
the pressure sensor has been timing out often, so I get false values where a negative error code is returned. I’ve increased the timing loop and am seeing if this works better
we had a heap of rain overnight and my rainfall figure suddenly dropped because I was only using the LSB, and the count had overflowed. A bit of trial and error and now it is showing the true total. A problem with rainfall is that the sensor reports total rainfall, so this will just keep going up and up. I need some way to keep daily totals. Perhaps I need to add a real time clock?
my light values are related to the resistance in the photoresistors, so the curves are inverted i.e. when it is light the value is lowest FIXED Apr 10 – I chose an arbitrary dark value of 1000 and am using that as a reference point to subtract from, so now a bigger value does mean more light rather than more dark!
wind direction is returned as an integer between 0 and 31, which seem to correspond to 16 compass points. I think there might be some sort of moving average calculation used by the base station to reduce errors due to rapidly fluctuating wind shifts.
Just picked up one of these Belkin WeMo switches to try out. I wasn’t worried about the motion-sensing switch version, just the plain single outlet. On opening I expected to find more complicated setup instructions, and thought I would have to set up port forwarding on my router so I could control it over 3G from the phone. Considering the average home user wouldn’t know how to do this, I wondered how they would make this easy to do. However, it doesn’t work this way.
Anyway, it was incredibly easy to set up:
Plug it in. I plugged in a reading lamp as a test. The LED alternately blinked blue and orange. I tried the manual switch and the lamp turned on and off.
Download the WeMo app from the app store. Launch the app, then it asks you to go into Settings to join the phone to the WeMo’s local WiFi network.
The app begins setup and once finished, the single remote switch appears in a list view.
That’s it! At this point you just hit the button in the list item and the light turns on and off.
The app notified that a firmware update was needed, which installed with no problems.
So, first experiences are favourable. I’m still curious as to how remote control works from outside the WiFi network. I am assuming that the device must be sending requests out to a server somewhere and polling for state changes.
At the moment I’m probably just going to use it to switch the Christmas lights (when they actually get set up). This saves me going outside or down to the garage to switch the powerpoints off. We do have some old-style mechanical timers around but this is far more fun.
Belkin also publish an SDK for WeMo, which is a nice change considering that most manufacturers have no interest in making their devices open or interoperable. Building the demo app for my iPhone immediately finds the configured WeMo outlet and I can switch it from the iOS simulator. I do wonder what security implications this may have, but assume that only devices recognised by my local network can control the WeMo switch. Some testing may be required.