From 596b269323053c04982547fabd2151efc47d5e6a Mon Sep 17 00:00:00 2001 From: Wiebe Nieuwenhuis Date: Tue, 9 Feb 2016 18:27:27 +0100 Subject: [PATCH 1/3] Added PIR device --- device-config-schema.coffee | 61 +++++++++++++++++++------------------ rflink.coffee | 56 ++++++++++++++-------------------- 2 files changed, 55 insertions(+), 62 deletions(-) diff --git a/device-config-schema.coffee b/device-config-schema.coffee index 5d97e77..8bd91b6 100644 --- a/device-config-schema.coffee +++ b/device-config-schema.coffee @@ -245,33 +245,36 @@ module.exports = { # type: "string" # required: false # } -# RFLinkPir: { -# title: "RFLinkPir config options" -# type: "object" -# extensions: ["xLink", "xPresentLabel", "xAbsentLabel"] -# properties: -# protocols: -# description: "The protocols to use." -# type: "array" -# default: [] -# format: "table" -# items: -# type: "object" -# properties: -# name: -# type: "string" -# options: -# description: "The protocol options" -# type: "object" -# autoReset: -# description: """Reset the state after resetTime. Useful for pir sensors, -# that emit present and absent events""" -# type: "boolean" -# default: true -# resetTime: -# description: "Time after that the presence value is reset to absent." -# type: "integer" -# default: 10000 -# required: ["protocols"] -# } + RFLinkPir: { + title: "RFLinkPir config options" + type: "object" + extensions: ["xLink", "xPresentLabel", "xAbsentLabel"] + properties: + protocols: + description: "The switch protocols to use." + type: "array" + default: [] + format: "table" + items: + type: "object" + properties: + name: + type: "string" + id: + description: "The device/home id of the switch" + type: "string" + switch: + description: "The button id of the switch" + type: "string" + required: ["name", "id", "switch"] + autoReset: + description: "Reset the state after resetTime. Useful for pir sensors that don't emit a absent signal" + type: "boolean" + default: true + resetTime: + description: "Time after that the presence value is reset to absent." + type: "integer" + default: 10000 + required: ["protocols"] + } } diff --git a/rflink.coffee b/rflink.coffee index 924b7b2..b346c44 100644 --- a/rflink.coffee +++ b/rflink.coffee @@ -83,7 +83,7 @@ module.exports = (env) -> RFLinkDimmer # RFLinkTemperature # RFLinkWeatherStation -# RFLinkPir + RFLinkPir # RFLinkContactSensor # RFLinkShutter # RFLinkGenericSensor @@ -317,38 +317,28 @@ module.exports = (env) -> # ) # # -# class RFLinkPir extends env.devices.PresenceSensor -# -# constructor: (@config, lastState, @board, @_pluginConfig) -> -# @id = config.id -# @name = config.name -# @_presence = lastState?.presence?.value or false -# -# for p in config.protocols -# _protocol = Board.getRfProtocol(p.name) -# unless _protocol? -# throw new Error("Could not find a protocol with the name \"#{p.name}\".") -# unless _protocol.type is "pir" -# throw new Error("\"#{p.name}\" is not a PIR protocol.") -# -# resetPresence = ( => -# @_setPresence(no) -# ) -# -# @board.on('rf', (event) => -# for p in @config.protocols -# match = doesProtocolMatch(event, p) -# if match -# unless @_setPresence is event.values.presence -# @_setPresence(event.values.presence) -# clearTimeout(@_resetPresenceTimeout) -# if @config.autoReset is true -# @_resetPresenceTimeout = setTimeout(resetPresence, @config.resetTime) -# ) -# super() -# -# getPresence: -> Promise.resolve @_presence -# + class RFLinkPir extends env.devices.PresenceSensor + + constructor: (@config, lastState, @board, @_pluginConfig, @protocol) -> + @id = config.id + @name = config.name + @_presence = lastState?.presence?.value or false + + resetPresence = ( => + @_setPresence(no) + ) + + @board.on('rf', (event) => + for p in @config.protocols + if @protocol.switchEventMatches(event, p) + @_setPresence(event.cmd.state) + if @config.autoReset is true + @_resetPresenceTimeout = setTimeout(resetPresence, @config.resetTime) + ) + super() + + getPresence: -> Promise.resolve @_presence + # # class RFLinkTemperature extends env.devices.TemperatureSensor # From d6309dae7d3a25229669dd92056bb65d08423e6f Mon Sep 17 00:00:00 2001 From: Wiebe Nieuwenhuis Date: Tue, 9 Feb 2016 19:09:37 +0100 Subject: [PATCH 2/3] Added contact sensor --- device-config-schema.coffee | 61 +++++++++++++++++++------------------ rflink.coffee | 50 ++++++++++++------------------ 2 files changed, 52 insertions(+), 59 deletions(-) diff --git a/device-config-schema.coffee b/device-config-schema.coffee index 8bd91b6..2e0dce2 100644 --- a/device-config-schema.coffee +++ b/device-config-schema.coffee @@ -68,35 +68,38 @@ module.exports = { default: true required: ["protocols"] }, -# RFLinkContactSensor: { -# title: "RFLinkContactSensor config options" -# type: "object" -# extensions: ["xConfirm", "xLink", "xClosedLabel", "xOpenedLabel"] -# properties: -# protocols: -# description: "The protocols to use." -# type: "array" -# default: [] -# format: "table" -# items: -# type: "object" -# properties: -# name: -# type: "string" -# options: -# description: "The protocol options" -# type: "object" -# autoReset: -# description: """Reset the state after resetTime. Useful for contact sensors, -# that only emit open or close events""" -# type: "boolean" -# default: false -# resetTime: -# description: """Time after that the contact state is reseted.""" -# type: "integer" -# default: 10000 -# required: ["protocols"] -# } + RFLinkContactSensor: { + title: "RFLinkContactSensor config options" + type: "object" + extensions: ["xConfirm", "xLink", "xClosedLabel", "xOpenedLabel"] + properties: + protocols: + description: "The switch protocols to use." + type: "array" + default: [] + format: "table" + items: + type: "object" + properties: + name: + type: "string" + id: + description: "The device/home id of the switch" + type: "string" + switch: + description: "The button id of the switch" + type: "string" + required: ["name", "id", "switch"] + autoReset: + description: "Reset the state after resetTime. Useful for pir sensors that emit a absent signal" + type: "boolean" + default: true + resetTime: + description: "Time after that the presence value is reset to absent." + type: "integer" + default: 10000 + required: ["protocols"] + } # RFLinkShutter: { # title: "RFLinkShutter config options" # type: "object" diff --git a/rflink.coffee b/rflink.coffee index b346c44..3fe9295 100644 --- a/rflink.coffee +++ b/rflink.coffee @@ -84,7 +84,7 @@ module.exports = (env) -> # RFLinkTemperature # RFLinkWeatherStation RFLinkPir -# RFLinkContactSensor + RFLinkContactSensor # RFLinkShutter # RFLinkGenericSensor ] @@ -238,35 +238,25 @@ module.exports = (env) -> ) -# class RFLinkContactSensor extends env.devices.ContactSensor -# -# constructor: (@config, lastState, @board, @_pluginConfig) -> -# @id = config.id -# @name = config.name -# @_contact = lastState?.contact?.value or false -# -# for p in config.protocols -# _protocol = Board.getRfProtocol(p.name) -# unless _protocol? -# throw new Error("Could not find a protocol with the name \"#{p.name}\".") -# -# @board.on('rf', (event) => -# for p in @config.protocols -# match = doesProtocolMatch(event, p) -# if match -# hasContact = ( -# if event.values.contact? then event.values.contact -# else (not event.values.state) -# ) -# @_setContact(hasContact) -# if @config.autoReset is true -# clearTimeout(@_resetContactTimeout) -# @_resetContactTimeout = setTimeout(( => -# @_setContact(!hasContact) -# ), @config.resetTime) -# ) -# super() -# + class RFLinkContactSensor extends env.devices.ContactSensor + + constructor: (@config, lastState, @board, @_pluginConfig, @protocol) -> + @id = config.id + @name = config.name + @_contact = lastState?.contact?.value or false + + @board.on('rf', (event) => + for p in @config.protocols + if @protocol.switchEventMatches(event, p) + @_setContact(event.cmd.state) + if @config.autoReset is true + clearTimeout(@_resetContactTimeout) + @_resetContactTimeout = setTimeout(( => + @_setContact(!event.cmd.state) + ), @config.resetTime) + ) + super() + # class RFLinkShutter extends env.devices.ShutterController # # constructor: (@config, lastState, @board, @_pluginConfig) -> From d5c7ae08cb56af5ebceb3994e1fb6519b41db0a3 Mon Sep 17 00:00:00 2001 From: Wiebe Nieuwenhuis Date: Tue, 9 Feb 2016 19:14:01 +0100 Subject: [PATCH 3/3] Added examples for ContactSensor and PIR sensor. --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index ad65428..82a81f3 100644 --- a/README.md +++ b/README.md @@ -99,4 +99,38 @@ is used for sending or receiving. Default is `true` for both. "switch": "1" }] } +``` + +### ContactSensor example: +```json +{ + "id": "window", + "name": "Window", + "class": "RFLinkContactSensor", + "autoReset": false, + "protocols": [ + { + "name": "NewKaku", + "id": "00d199ee", + "switch": "1" + } + ] +}, +``` + +### PIR sensor example: +```json +{ + "id": "movement", + "name": "Movement", + "class": "RFLinkPir", + "autoReset": false, + "protocols": [ + { + "name": "NewKaku", + "id": "00d189ee", + "switch": "1" + } + ] +}, ``` \ No newline at end of file