Jump to content


Photo

Creating Devices


  • Please log in to reply
8 replies to this topic

#1 neilstreet6036

neilstreet6036

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 15 July 2014 - 09:47 AM

Hi,

 

Is there anymore detailed information on creating devices. Most of the scripts link to generic routines and functions but where are these, is there a fill list of procedures and functions?

 

I think this is a great product and wish to use as the engine under OpenHab but I need to add additional devices such a the DHT11/22 etc.

 

Thanks.

 

 


  • Ekbergtum, Rudyrhill, Howarddum and 3 others like this

#2 Felix

Felix

    Member

  • Members
  • PipPip
  • 19 posts

Posted 15 July 2014 - 08:03 PM

Sounds like you are interested in creating a new device?  It looks like the DHT11/22 devices use a proprietary digital protocol that is time sensitive.  If that's the case, what they connect to will need to be a (somewhat) real time device.  People seem to like to connect these to Arduinos, Raspberry Pis and Beaglebones.

 

Without knowing your host, I'll guess you want to connect to a Raspberry Pi and are using a Python library to read the temperature and humidity.

 

The easiest way to create a device would be to create a Virtual Device.  In this case, you would start with a Python program which read the sensor and printed out the temperature and humidity.  Once you had that working, you would create a Virtual Device which called the Python program, captured the printed output, and then reported the output on the Device's temperature and humidity terminals.  Your Virtual Device would look something like this:

 

module DHT11

private

##################################################################
# When see an event on the "in" terminal, update "temp"

# and "humidity" terminals.
##################################################################
def respond_to_inputs(inputs, outputs = {})
  if inputs["in"]

    # run your Python script and capture its output

    prog_output = `./dht11_reader.py`

    # Pull the temp and humidity values out of the printed output.

    # Here we assume the program prints out the 2 values separated by a space or

    # a carriage return.  Temperature is printed first.

    outputs["temp"], outputs["humidity"] = prog_output.scan(/[\d\.]+/)

  end

  outputs # return result

end

 

##################################################################
# Define our terminals
##################################################################
def terminal_dids
  %W[in temp humidity]
end

end # module

 

This device will update its "temp" and "humidity" terminals each time it sees an event

on its "in" terminal.  If you wired the "in" terminal to a timer, you could get regular updates.

You could also make the Device asynchronous, and have it update automatically after a 

particular time interval.

 

All the proprietary methods we use are documented in the Virtual Devices area:

 

http://catalinacompu...gVirtualDevices

 

The other methods are standard Ruby.

 

In summary, an easy way to create new devices is to create a program (in any language you wish),

and call the program from a Virtual Device (written in Ruby).



#3 neilstreet6036

neilstreet6036

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 17 July 2014 - 06:32 PM

Hi Felix,

 

many thanks; the DHT11 will be connected to and aduino, which in turn will be connected to the pi. Does the firmata implementation used in VW allow the DHT11 to be read via the library. I looked for a firmata gem in the VW installation but couldn't see one? So what does the appt call firmata from?

 

I have found code in c++ for the arduino to read the sensor but this is standalone code and im not sure how to embed it into VW. I have read that it may need a ruby wrapper but im new to ruby and alike so on a steep learning curve.

 

The end result of all of this will my HA system for my selfbuild with around 150 digital sensors and some 30 analog sensor plus outputs to relays, dimmers, sockets etc etc.

 

Neil.



#4 Felix

Felix

    Member

  • Members
  • PipPip
  • 19 posts

Posted 17 July 2014 - 08:18 PM

Firmata is a standard application we run on the Arduino which allows VW to bit twiddle the Arduino pins and read Arduino pin values.  Given the DHT11 has some time dependencies, I don't think standard Firmata can be used to talk to the DHT.

 

It sounds like we have a couple of choices: hook the DHT11 to the Arduino or hook it to the Pi.

 

The C++ code you found sounds like code you could use to read the DHT from an Arduino.  I can't tell what you currently have running on your Arduinos, so I'm not sure how easy it would be for you to add the DHT code.  Perhaps it's better to just run Firmata on the Arduinos and use VW and the Arduinos to talk to your analog sensors, and digital inputs and outputs.

 

If you've got a Pi and are willing to wire the DHT to your Pi, there are some solutions which may be of use to you.  Adufruit has a howto on their site (see https://learn.adafru...h-gdocs-logging) which tells you how to wire a DHT to a Pi and how to get software running on your Pi which will read temperature and humidity.  If you can get the howto work, you'll have a program that prints out temperature and humidity.  That's exactly what we need (see above Virtual Device solution).   You'll need to substitute your application name (something like "./ Adafruit_DHT.py 11 <GPIO pin number>" instead of of "./dht11_reader.py") into the Virtual Device code, and then you'll have made your own VW Virtual Device which reads temperature and humidity from a DHT11 (using the Pi).

 

If your are interested in using Arduinos and just reading temperatures (and not humidity), it's easy to use SeeedStudio Grove temperature sensors (see http://www.catalinac...perature_sensor).



#5 neilstreet6036

neilstreet6036

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 18 July 2014 - 08:44 AM

Hi Felix,

 

I am only running the VW application, the arduino's have no other code running on them. I could have a dedicated arduino purely for the temp sensors but I would like to integrate into vw, does this sound possible?

 

If I do have the dedicated code, how could I read values using VR, would it be the way described, i.e using a scipt?

 

In terms of fermata, do you have a function and procedure list that may be called from the VW scripts or is this not necessary.

 

Many thanks, sorry for so many questions.



#6 Felix

Felix

    Member

  • Members
  • PipPip
  • 19 posts

Posted 18 July 2014 - 04:15 PM

Perhaps the easiest approach would be to have your Arduinos just running Firmata.  The Arduinos would connect to all your HA devices, except for the DHT sensors.  The DHT sensors would be wired directly to your Raspberry Pi.  The Pi would use the howto and the Virtual Device code above to create a VW DHT Device.  This way, your whole system will be running within VW.

 

If you follow the howto, you should be able to get a program which reads the DHTs from the Pi.  Then use the Virtual Device code shown above to create a Virtual Device which uses the howto program to read the DHTs.  To create your DHT Device (we'll assume you saved the code in a file called dht_11.rb), go to the Console and type (see http://catalinacompu...gVirtualDevices for details):

 

add_device(type_file:"virtual_devices", module_file:"dht_11", id:"my_dht")

 

You should be up and running.

 

I did some poking around on the internet, and there are some I2C parts for sensing temperature and humidity.  (See http://www.seeedstud...ml?cPath=25_125).  We are going to be releasing support for some I2C parts in the near future.  Would you like us to look into supporting these?  I'm pretty sure we can support these on Arduinos running Firmata.  If this is the case, they will just work - no coding needed.

 

You don't need to know Firmata to use it (you just need to have it running on your Arduinos).  For more information about Firmata, see:

http://www.firmata.org/wiki/Main_Page



#7 neilstreet6036

neilstreet6036

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 19 July 2014 - 08:57 AM

Hi Felix,

 

I think the I2C would be a very welcome addition and useful protocol to introduce. I hope my system is still in the development stage so that I can introduce it to my system. When my system is complete, perhaps I can pass you on details, it may make an interesting addition to the projects page in view of the scope of sensors etc?

 

I look forward to the updated software, in the interim I shall experiment with the DHT11 but I am sure I shall replace with the I2C sensors.

 

Regards,

 

Neil.



#8 Felix

Felix

    Member

  • Members
  • PipPip
  • 19 posts

Posted 19 July 2014 - 09:14 PM

We just ordered some of the I2C temp/humidity sensors, so we should be able to start testing them in a few days.  We'll post an announcement on the forum when the new release is out.

 

If you get an HA project you wish to share, that's great (you can contact me using the forum).  We could add it to our projects area.  You must have seen the one we have there already (http://www.catalinac...tomationProject).  There's a zip file with lots of Scripts, some of which you may find useful.



#9 Felix

Felix

    Member

  • Members
  • PipPip
  • 19 posts

Posted 15 October 2014 - 03:08 PM

Our latest software release, 1.6.0, supports I2C temperature/humidity sensors - see http://www.catalinac...ty_sensor_hiacc.

 

 

If you want to use I2C devices, make sure you upgrade your Arduinos to Firmata version 2.3 (or higher).  Only these later versions of Firmata support I2C devices.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users