Skip to content

Commit

Permalink
v1.0.17 (#17)
Browse files Browse the repository at this point in the history
### Changed
- More detailed error log for http requests

### Fixed
- Fixed `PLC_LightBulb` brightness to be `Byte` value as documented. In fact is was a `Real` please change in PLC if you already use it.
  • Loading branch information
Feilner authored Nov 13, 2020
1 parent 9de1778 commit 2aa02cd
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 64 deletions.
27 changes: 25 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.17] - 2020-11-14

### Changed
- More detailed error log for http requests

### Fixed
- Fixed `PLC_LightBulb` brightness to be `Byte` value as documented. In fact is was a `Real` please change in PLC if you already use it.

## [1.0.16] - 2020-11-09

### Changed
- Only disconnect to PLC on TCP errors mask 0x000fffff of snap7 error codes. Clint errors of PLC does no longer trigger reconnect
- Snap7 error codes are printed in hex values
- Documentation extended

### Fixed
- Fix poll issue for `PLC_TemperatureSensor`, `PLC_HumiditySensor` and `PLC_Thermostat`
- Fix double definition for `PLC_GarageDoorOpener`
- Fixed `PLC_LightBulb` brightness to be `Byte` value as documented. In fact is was a `Real` please change in PLC if you already use it

## [1.0.16] - 2020-11-09

Expand Down Expand Up @@ -126,3 +144,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.0.1] - 2020-10-04
### Added
- Initial Version


The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

116 changes: 59 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ SIEMENS S7 PLC plugin for [Homebridge](https://homebridge.io)
- Supports [**push**](#push) from PLC to homebridge-plc plugin by http PUT/GET
- Supports [**control**](#control) of PLC accessories by http PUT/GET (experimental)
- Supported Accessories:
* [LightBulb as `PLC_LightBulb`](#PLC_LightBulb)
* [Outlet as `PLC_Outlet`](#PLC_Outlet)
* [Switch as `PLC_Switch`](#PLC_Switch)
* [Temperature Sensor as `PLC_TemperatureSensor`](#PLC_TemperatureSensor)
* [Humidity Sensor as `PLC_HumiditySensor`](#PLC_HumiditySensor)
* [Thermostat as `PLC_Thermostat`](#PLC_Thermostat)
* [Shutter as `PLC_WindowCovering`](#PLC_Window)
* [Window as `PLC_Window`](#PLC_Window)
* [Door as `PLC_Door`](#PLC_Window)
* [Occupancy Sensor as `PLC_OccupancySensor`](#PLC_OccupancySensor)
* [Motion Sensor as `PLC_MotionSensor`](#PLC_MotionSensor)
* [Contact Sensor as `PLC_ContactSensor`](#PLC_ContactSensor)
* [Security System as `PLC_SecuritySystem`](#PLC_SecuritySystem)
* [Faucet as `PLC_Faucet`](#PLC_Faucet)
* [Valve as `PLC_Valve`](#PLC_Valve)
* [Button as `PLC_StatelessProgrammableSwitch`](#PLC_StatelessProgrammableSwitch)
* [Lock mechanism as `PLC_LockMechanism`](#PLC_LockMechanism)
* [Boolean lock mechanism as `PLC_LockMechanismBool`](#PLC_LockMechanismBool)
* [Garage door as `PLC_GarageDoorOpener`](#PLC_GarageDoorOpener)
* [LightBulb as `PLC_LightBulb`](#PLC_LightBulb)
* [Outlet as `PLC_Outlet`](#PLC_Outlet)
* [Switch as `PLC_Switch`](#PLC_Switch)
* [Temperature Sensor as `PLC_TemperatureSensor`](#PLC_TemperatureSensor)
* [Humidity Sensor as `PLC_HumiditySensor`](#PLC_HumiditySensor)
* [Thermostat as `PLC_Thermostat`](#PLC_Thermostat)
* [Shutter as `PLC_WindowCovering`](#PLC_Window)
* [Window as `PLC_Window`](#PLC_Window)
* [Door as `PLC_Door`](#PLC_Window)
* [Occupancy Sensor as `PLC_OccupancySensor`](#PLC_OccupancySensor)
* [Motion Sensor as `PLC_MotionSensor`](#PLC_MotionSensor)
* [Contact Sensor as `PLC_ContactSensor`](#PLC_ContactSensor)
* [Security System as `PLC_SecuritySystem`](#PLC_SecuritySystem)
* [Faucet as `PLC_Faucet`](#PLC_Faucet)
* [Valve as `PLC_Valve`](#PLC_Valve)
* [Button attached to PLC as `PLC_StatelessProgrammableSwitch`](#PLC_StatelessProgrammableSwitch)
* [Lock mechanism as `PLC_LockMechanism`](#PLC_LockMechanism)
* [Boolean lock mechanism as `PLC_LockMechanismBool`](#PLC_LockMechanismBool)
* [Garage door as `PLC_GarageDoorOpener`](#PLC_GarageDoorOpener)


# Installation
Expand Down Expand Up @@ -235,9 +235,9 @@ movement detection sensor
- `true`: motion detected

### <a name='PLC_ContactSensor'></a>Contact Sensor as `PLC_ContactSensor`
contact sensor
Generic contact sensor. The home app allows to display as window, door, blind/shutter, garage door or contact sensor.

![homebridge pic](doc/contactsensor.png)
![homebridge pic](doc/contactsensor.png) ![homebridge pic](doc/blind.png) ![homebridge pic](doc/window.png) ![homebridge pic](doc/door.png) ![homebridge pic](doc/garagedoor.png)
- `name`: unique name of the accessory
- `manufacturer`: (optional) description
- `db`: s7 data base number e.g. `4` for `DB4`
Expand Down Expand Up @@ -314,41 +314,41 @@ valve configurable as generic valve, irrigation, shower head or water faucet

### <a name='PLC_StatelessProgrammableSwitch'></a>Button as `PLC_StatelessProgrammableSwitch`
stateless switch from PLC to home app. Trigger actions in home app only works with control center e.g. AppleTV or HomePod.
It will works only in polling mode! The PLC sets a bit that is regularly polled by homebridge after successful reading a 1 of the event the bit it will report the event and set the bit to 0. Change 0->1 is done by PLC change from 1->0 is done by homebridge!
It will works only in polling or push mode! The PLC sets a bit that is regularly polled by homebridge after successful reading a 1 of the event the bit it will report the event and set the bit to 0. Change 0->1 is done by PLC change from 1->0 is done by homebridge-plc! In push mode the new value is just pushed with the db and offset of `get_ProgrammableSwitchEvent`

![homebridge pic](doc/statelessswitch.png)
- `name`: unique name of the accessory
- `manufacturer`: (optional) description
- `db`: s7 data base number e.g. `4` for `DB4`
- `enablePolling`: (optional) when set to `true` the current state will be polled. It is mandatory as well to enable polling mode on platform level.
- `pollInterval` (optional) poll interval in seconds. Default value is `10` seconds.
- `isEvent` offset and bit that is polled when set to 1 by the PLC the event is read and the bit is set to 0 by homebridge S7 type `Bool` **PLC has to set to 0** e.g. `55.1` for `DB4DBX55.1`
- `get_ProgrammableSwitchEvent`: offset to red current event of the switch. This is reported towards home app S7 type `Byte` e.g. `3` for `DB4DBB3`
- `isEvent` offset and bit that is polled by homebridge-plc. **PLC has to set to `true`.** When set to 1 the event is read from `get_ProgrammableSwitchEvent` and the bit is `false` by homebirdge-plc to confirm that the event is handled. S7 type `Bool` e.g. `55.1` for `DB4DBX55.1` (only used for polling)
- `get_ProgrammableSwitchEvent`: offset to read current event of the switch. This is reported towards home app S7 type `Byte` e.g. `3` for `DB4DBB3`
- `0`: single press
- `1`: double press
- `2`: long press

### <a name='PLC_LockMechanism'></a>Lock mechanism as `PLC_LockMechanism`
### <a name='PLC_LockMechanism'></a>Lock mechanism as `PLC_LockMechanism`
Lock mechanism (not yet clear how to use changes are welcome)

![homebridge pic](doc/lock.png)
- `name`: unique name of the accessory
- `manufacturer`: (optional) description
- `db`: s7 data base number e.g. `4` for `DB4`
- `enablePolling`: (optional) when set to `true` the current state will be polled. It is mandatory as well to enable polling mode on platform level.
- `pollInterval` (optional) poll interval in seconds. Default value is `10` seconds.
- `forceCurrentState`: (optional) when set to `true` the position set by `set_LockTargetState` is directly used as current state. By this it seems in tha home app as the target state was directly reached. This is recommended when not using `enablePolling` or pushing the value from the plc.
- `get_LockCurrentState`: offset to read current state current state S7 type `Byte` e.g. `3` for `DB4DBB3`
- `0`: unsecured
- `1`: secured
- `2`: jammed
- `3`: unknown
- `name`: unique name of the accessory
- `manufacturer`: (optional) description
- `db`: s7 data base number e.g. `4` for `DB4`
- `enablePolling`: (optional) when set to `true` the current state will be polled. It is mandatory as well to enable polling mode on platform level.
- `pollInterval` (optional) poll interval in seconds. Default value is `10` seconds.
- `forceCurrentState`: (optional) when set to `true` the position set by `set_LockTargetState` is directly used as current state. By this it seems in tha home app as the target state was directly reached. This is recommended when not using `enablePolling` or pushing the value from the plc.
- `get_LockCurrentState`: offset to read current state current state S7 type `Byte` e.g. `3` for `DB4DBB3`
- `0`: unsecured
- `1`: secured
- `2`: jammed
- `3`: unknown
- `get_LockTargetState`: offset to read target state current state S7 type `Byte` e.g. `3` for `DB4DBB3`
- `0`: unsecured
- `1`: secured
- `0`: unsecured
- `1`: secured
- `set_LockTargetState`: offset to write target state current state S7 type `Byte` e.g. `3` for `DB4DBB3`
- `0`: unsecured
- `1`: secured
- `0`: unsecured
- `1`: secured

### <a name='PLC_LockMechanismBool'></a>Boolean lock mechanism as `PLC_LockMechanismBool`
Lock mechanism implemented as bool on the PLC. **NOTE: The convention `0`:closed/secured `1`:open/unsecured**
Expand All @@ -361,18 +361,18 @@ Lock mechanism implemented as bool on the PLC. **NOTE: The convention `0`:closed
- `pollInterval` (optional) poll interval in seconds. Default value is `10` seconds.
- `forceCurrentState`: (optional) when set to `true` the position set by set_LockTargetState` is directly used as current state. By this it seems in tha ome app as the target state was directly reached. This is recommended when not sing `enablePolling` or pushing the value from the plc.
- `get_LockCurrentState`: offset to read current state current state S7 type `Bool` .g. `3.1` for `DB4DBB3`
- `0`: secured
- `1`: unsecured
- `0`: secured
- `1`: unsecured
- `get_LockTargetState`: offset to read target state current state S7 type `Bool` e.. `3.1` for `DB4DBB3`
- `0`: secured
- `1`: unsecured
- Single Bit for secure/unsecured:
- `set_LockTargetState`: offset to write target state current state S7 type `Bool` e.g. `3.1` for `DB4DBB3`
- `0`: secured
- `1`: unsecured
- `set_LockTargetState`: offset to write target state current state S7 type `Bool` e.g. `3.1` for `DB4DBB3`
- `0`: secured
- `1`: unsecured
- Separate Bits for secure/unsecured:
- `set_Secured`: offset and bit set to 1 when switching to target state secured S7 type `Bool` **PLC has to set to 0** e.g. `3.3` for `DB4DBX55.1`
- `set_Unsecured`: offset and bit set to 1 when switching to target state unsecured S7 type `Bool` **PLC has to set to 0** e.g. `3.4` for `DB4DBX55.2`
- `set_Secured`: offset and bit set to 1 when switching to target state secured S7 type `Bool` **PLC has to set to 0** e.g. `3.3` for `DB4DBX55.1`
- `set_Unsecured`: offset and bit set to 1 when switching to target state unsecured S7 type `Bool` **PLC has to set to 0** e.g. `3.4` for `DB4DBX55.2`


### <a name='PLC_GarageDoorOpener'></a>Garage door as `PLC_GarageDoorOpener` (experimental)
Expand Down Expand Up @@ -413,14 +413,14 @@ Lock mechanism (not yet clear how to use changes are welcome)
#### config.json Example
Note: The example is just an example it contains also some optional settings. For testing purposes all accessories are set to one DB.

{
{
"bridge": {
"name": "Homebridge DEMO",
"username": "0E:54:47:36:82:26",
"port": 52609,
"pin": "031-55-155"
},
"accessories": [],
"accessories": [],
"platforms": [
{
"name": "Config",
Expand Down Expand Up @@ -610,7 +610,7 @@ Note: The example is just an example it contains also some optional settings. Fo
"enablePolling": true,
"ValveType": 2,
"get_Active": 28.1,
"set_Active": 29.1,
"set_Active": 28.1,
"get_SetDuration": 30,
"set_SetDuration": 30,
"get_RemainingDuration": 34
Expand All @@ -619,17 +619,16 @@ Note: The example is just an example it contains also some optional settings. Fo
"accessory": "PLC_StatelessProgrammableSwitch",
"name": "Stateless Switch",
"enablePolling": true,
"pollInterval": 30,
"pollInterval": 10,
"db": 12,
"isEvent": 38,
"get_ProgrammableSwitchEvent":
"isEvent": 29.2,
"get_ProgrammableSwitchEvent": 38
},
{
"accessory": "PLC_LockMechanism",
"name": "Lock",
"db": 12,
"enablePolling": true,
"isEvent": 0.1,
"get_LockCurrentState": 39,
"get_LockTargetState": 40,
"set_LockTargetState": 40
Expand All @@ -639,7 +638,6 @@ Note: The example is just an example it contains also some optional settings. Fo
"name": "LockBool",
"db": 12,
"enablePolling": true,
"isEvent": 0.1,
"get_LockCurrentState": 41.0,
"get_LockTargetState": 41.1,
"set_LockTargetState": 41.1
Expand Down Expand Up @@ -726,6 +724,8 @@ Example for byte values when trigger from browser

http://homebridgeIp:8080/?push&db=2&offset=3&value=255

**NOTE:** Chrome/Edge does at minimum two requests with different parameters resulting in some error messages. I recommend `Talend API Tester - Free Edition`

# <a name='control'></a>Control of PLC accessories

It´s also possible to control PLC accessories via HTTP `PUT` or `GET` operation. This might be useful for integration into other automation systems.
Expand All @@ -740,7 +740,7 @@ The Request has to be done as HTTP `PUT` or `GET` operation. There will be no lo

### Format
Example to switch a light bulb from browser. Lets say the light bulb has the following config:

"platforms": [
{
"platform": "PLC",
Expand All @@ -759,7 +759,7 @@ Example to switch a light bulb from browser. Lets say the light bulb has the fol
}
]
}
]
]

Use this to switch the light bulb on from browser:

Expand All @@ -769,6 +769,8 @@ Use this to switch the light bulb off from browser:

http://homebridgeIp:8080/?push&db=6096&offset=1.1&value=0

**NOTE:** Chrome/Edge does at minimum two requests with different parameters resulting in some error messages. I recommend `Talend API Tester - Free Edition`

# Test & Release

## Local test
Expand Down
Binary file modified doc/statelessswitch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 20 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,24 @@ PLC_Platform.prototype = {
}
else if(doLog)
{
this.log.error("Received HTTP Push must contain push or control, db, offset and value!");
this.log.error(url);
if (!this.config.enablePush && 'push' in url.query) {
this.log.error("[HTTP Push] enablePush is not set in platform config!");
}
else if (!this.config.enableControl && 'control' in url.query) {
this.log.error("[HTTP Control] enableControl is not set in platform config!");
}
else if (!('push' in url.query) && !('control' in url.query) ) {
this.log.error("[HTTP Push/Control] neither push or control!");
}
else if (!('db' in url.query)) {
this.log.error("[HTTP Push/Control] parameter db is missing!");
}
else if (!('offset' in url.query)) {
this.log.error("[HTTP Push/Control] parameter offset is missing!");
}
else if (!('value' in url.query)) {
this.log.error("[HTTP Push/Control] parameter value is missing!");
}
}
});
}
Expand Down Expand Up @@ -210,12 +226,12 @@ function GenericPLCAccessory(platform, config) {

if ('get_Brightness' in config) {
this.service.getCharacteristic(Characteristic.Brightness)
.on('get', function(callback) {this.getReal(callback,
.on('get', function(callback) {this.getByte(callback,
config.db,
config.get_Brightness,
'get Brightness'
)}.bind(this))
.on('set', function(value, callback) {this.setReal(value, callback,
.on('set', function(value, callback) {this.setByte(value, callback,
config.db,
config.set_Brightness,
'set Brightness'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-plc",
"version": "1.0.16",
"version": "1.0.17",
"description": "Homebridge plugin for Siemens Step7 and compatible PLCs. (https://github.com/homebridge)",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit 2aa02cd

Please sign in to comment.