Author Topic: Basic HowTo guide for mysensors and Vera with examples  (Read 810 times)

Offline ninkasi

  • Full Member
  • ***
  • Posts: 211
  • Karma: +12/-4
Basic HowTo guide for mysensors and Vera with examples
« on: November 25, 2017, 08:49:19 pm »
Just thought I might try to give back a little here for those who may be curious about, or interested in, using mysensors. There is a lot of detail at mysensors.org, but I suspect some might find it a little overwhelming. If people are interested, I could upload some sample code for the sensors I use. Perhaps others could also say how they are using their mysensor kit with Vera and show their code....

Anyhow, for my environment I use the mysensors kit to provide low cost:
  • temperature monitoring for my fridge & freezers (making sure they aren't running too warm which will allow food to spoil, or too cold which is a waste of energy)
  • temp & humidity monitoring for the cellar
  • door open/close sensors
DataMine2 also records info over time that I can view easily via the ImperiHome app. I've also recently started to create mysensor buttons to activate scenes - providing similar functionality as the Fibaro 'button", only for a fraction of the cost. I even have a sensor using a small passive buzzer and limit switch that plays a tinny version of the star wars imperial march if the freezer door is left open for over a minute (it's loud, really annoying, and very effective in getting my kids to close the door properly).

Future projects for me include:
  • letter box notification that mail has been delivered
  • RF bridge to control my projector screen (as well as sensors, you can create 'actuators' that can be controlled via Vera)
  • BBQ gas bottle weight sensor (to let me know when it's getting low)
  • water tank level

The gateway cost under $10 to make, and each sensor is normally powered by AA batteries and cost under $5 to make.

So, how to do this. Basically, you create a physical mysensor gateway. Then you add that into Vera as a device. Then you create your physical sensor modules and 'include' each into the mysensor network, at which point they will appear as devices in Vera. The physical gateway can talk to Vera via IP (my recommendation) or serial. The sensors can be attached directly to the gateway, or can communicate with the gateway via either IP or (my preference) a dedicated 2.4GHz RF network.

In more detail:
1.   Create a mysensors gateway. You can use an Arduino for this, but (my recommendation) I used an esp8266 (specifically a WeMos D1) as it is about the same price as an arduino but has built in wifi, more onboard memory, and a faster processor. So when including the cost of a wifi module, it's actually cheaper than an arduino as well as faster etc. Code is here: https://www.mysensors.org/build/esp8266_gateway#esp8266gateway-example. After physically assembling the gateway, you download the code to the device using a USB cable and the Arduino IDE (https://www.arduino.cc/en/Main/Software). As noted before, you can modify the code and attach sensors directly to this gateway, or (my preference as you don't muck around with the gateway - and possibly break it - when adding in new sensors) have this as a dedicated gateway with multiple discreet sensors. Sensors can use wifi to communicate, but I like using RF as it allows for very small and cheap sensors that can run off batteries.
2.   Install the mysensors vera plugin - https://www.mysensors.org/controller/vera - and configure it to use your gateway
3.   Create a sensor, then add it in to Vera through the inclusion process (see also https://www.mysensors.org/controller/vera)
 
Pricing is a rough guideline ? I get my kit via aliexpress. Takes a while to arrive, but generally I find the quality to be good if you pick suppliers with solid feedback.

Gateway hardware - $10:
*   WeMos D1R2 - $6.50
*   NRF24L01+ Radio - $1 (generally bought in lots of 10 - range for these are good. If you find you have issues (I haven't so far) you can get modules with better antennas)
*   Ribbon cable to join things - $1 (can use dupont cables to minimise soldering)
*   Micro USB cable & charger for power (free - most people have many of these unused at home)
*   Case $1.50

Sensor hardware - $5:
*   3.3V Arduino pro mini - $2 (can also use an Arduino nano or a 5V pro mini, although they are less suitable for being powered by batteries). Cheaper when bought in bulk.
*   Radio - $1
*   Plastic project box - $1
*   Double AA battery case - $0.50 and two AA batteries, or a hacked usb cable and charger. Yes I know that two AA batteries does not provide 3.3V, but it's near enough and has not caused any issues for me.
*   Sensor (eg door magnetic reed, momentary button, temperature probe, etc - $1.00)

You will also need (if using arduino pro mini for sensors) one FT232RL FTDI USB 3.3V 5.5V to TTL Serial Adapter, plus a soldering iron and some solder (I use 0.7mm 60% tin/40% lead - don't be scared of learning how to solder - just apply the tip of the soldering iron to the joint between the pin and the board, then apply the solder wire to the tip of the iron. With some practise, the solder will melt and properly form a little inverse cone ). The FT232RL is simply used to temporarily provide a usb port for the pro mini to allow you to program it. If powering via batteries, I recommend using needle nose pliers to crush the little led on the Arduino pro mini to reduce power usage (unfortunately there is no software way to disable the light). I find my fridge/freezer sensors easily last 6 months ? and they are set to send info every 45 seconds or so ? and other sensors (that only send info as required, eg door sensors) last much longer again.
« Last Edit: November 25, 2017, 08:55:17 pm by ninkasi »
Home Automation veteran. Rolled own, then MisterHouse and X10, now Vera - mysensor arduino and ESP8266 network - zwave lights, locks, switches - milights - yeelights - google home(s) - Broadlink RM - raspberry pi(s) with various scripts for power and weather station - Logitech Harmony - Imperihome

Offline kulfsson

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +2/-0
Re: Basic HowTo guide for mysensors and Vera with examples
« Reply #1 on: December 13, 2017, 05:06:40 am »
Very good information ! I have been contemplating getting into this myself. My first hurdle us which radio to choose. I see you are using the NRF24l01+ and not the RFM69 do you care to tell us why ? I have read that the RFM69 has longer range, but are there other caveats that you know about ?

Offline ninkasi

  • Full Member
  • ***
  • Posts: 211
  • Karma: +12/-4
Re: Basic HowTo guide for mysensors and Vera with examples
« Reply #2 on: December 13, 2017, 06:05:35 am »
Very good information ! I have been contemplating getting into this myself. My first hurdle us which radio to choose. I see you are using the NRF24l01+ and not the RFM69 do you care to tell us why ? I have read that the RFM69 has longer range, but are there other caveats that you know about ?

If you are just starting then I'd suggest sticking with the NRF24l01+ simply because most existing projects use them so it's less of a hurdle adapting to use for your own projects. They are also two to three times cheaper so it makes each individual sensor cheaper. I'd only suggest using something else if you find you have range issues. Keep in mind you can always have sensors that are also repeater nodes (or just a dedicated repeater node) that can act as a link for remote sensors to get to your central gateway - for example you might have your gateway in the middle of the house somewhere, but you want a sensor in your mailbox and the distance causes issues. If you put a repeater node/sensor for the front door, the mailbox sensor can talk to the front door sensor/repeater that in turn will pass the info on to the central gateway. (https://www.mysensors.org/about/network). It's sort of a mesh network, although more properly a tree network.
Home Automation veteran. Rolled own, then MisterHouse and X10, now Vera - mysensor arduino and ESP8266 network - zwave lights, locks, switches - milights - yeelights - google home(s) - Broadlink RM - raspberry pi(s) with various scripts for power and weather station - Logitech Harmony - Imperihome