rzwaveway: calling ZWave commands

Still working on the Ruby [dark] side (although I wish I had more time and motivation to go on with my C++ :-)),... I finally implemented something that makes it possible to "invoke" ZWave command class functions on devices.
In Ruby life is easy and this was implemented quite easily: after all, calling a function in ZWay ends up being just a simple HTTP call. In my little rzwaveway library gem I added the notion of "extensions" ("plug-ins" would have been a good name too) that define a clear API (meaning, not a low-level ZWay function call) for a known ZWave device interface.

As a first test, I implemented support for the ZWave siren/strobe alarm device I bought earlier this year. The code for it looks like this:


module RZWaveWay
  module Extensions
    class SSASirenStrobeAlarm
      include CommandClasses

      def initialize(device_id)
        @device_id = device_id
      end

      def disable
        set_value(0)
      end

      def enable
        set_value(STROBE + SIREN)
      end

      def enable_siren
        set_value(SIREN)
      end

      def enable_strobe
        set_value(STROBE)
      end

      def refresh_value
        RZWaveWay::ZWay.instance.execute(@device_id, SWITCH_MULTI_LEVEL, :Get)
      end

      private

      STROBE = 33
      SIREN = 66

      def set_value(value)
        RZWaveWay::ZWay.instance.execute(@device_id, SWITCH_MULTI_LEVEL, :Set, value)
      end
    end
  end
end

I started to use it directly in my "beta" home alarm system like this:


[...]
        zway.on_event(RZWaveWay::LevelEvent) {|event| on_device_level_changed(event) }
      end

      def on_device_level_changed(event)
        alarm_device = RZWaveWay::Extensions::SSASirenStrobeAlarm.new(alarm_device_id)
        if event.level
          alarm_device.enable_strobe
        else
          alarm_device.disable
        end

With that, every-time a door/window is open, the alarm device strobe light is activated.

Comments

  1. Hi!

    I'm starting to dive into the z-wave world, and I must say that your blog has been very helpful.

    I bought a Rpi + Razberry, some door sensors and a remote socket plug, and I'm starting to implement my (small for now) alarm system using the ZWay stack.

    Keep up the good work.

    ReplyDelete

Post a Comment

Popular posts from this blog

ZWay: getting the device list.

First steps with the ZWay library

Libcurl: perform a REST HTTP PUT