Skip to content

openHAB 1

Vita edited this page Oct 1, 2020 · 2 revisions

Introduction

This is wiki for openHAB 1 binding. It has ability to connect Simatic PLC over Ethernet with isoTCP. So it is possible to connect to the Simatic PLC S7-200, S7-300, S7-400, S7-1200 and S7-1500 series. H-system is not supported.

Binding uses libnodave library to provide connection (https://sourceforge.net/projects/libnodave/).

Supported data types

Binding support openHAB data types listed in the table. Individual item type are converted to simple data types such as byte, word, double word, float, array, rgb. For same types may be converted type defined, others has it strictly defined. Supported data types

Item type Supported data type Notes
Number byte, word, dword, float Numbers are represent in signed form. Their maximum value depends on the used type.
Floating point number is represented by float type. Float is stored in 4 bytes formatted according to IEEE 754.
Color hsb, rgb, rgbw All color parts are transferred in one double word. Each color component corresponds to one byte. Assignment of bytes depending on the chosen data type is following:

HSB - byte 0 - Hue, 1 - Saturation , 2 - Brightness, 3 - Not used
RGB - byte 0 - Red, 1 - Green, 2 - Blue, 3 - Not used
RGBW - byte 0 - Red, 1 - Green, 2 - Blue, 3 - White
String array Array of bytes. Length of array is specified in square brackets behind type definition (e.g. array[32] defines byte array with length 32 bytes)
Contact byte 0 - off, 1 - on
Switch byte 0 - off, 1 - on
Dimmer byte
Rollershutter word Lower byte for position, upper byte for StopMove/UpDown command - 1-Move,2-Stop,4-Up,8-Down

Binding configuration

In openhab.cfg is binding configured this way:

################################### Simatic Binding ######################################
#
# plc - define tagret PLC by IP address, cpu rack and slot. Definition look IP:rack.slot (ex.: 192.168.254.36:0.2). 
# Above that communication type can be optionally specify at the end separate by semicolon.
# Supported communication types : PG, OP, S7 and 200 (S7-200 connection).
# It is possible defined more PLCs ex. plc, plc1, plc315,... 
# 
# refresh - check for new data interval - default 1000ms   
#
simatic:refresh=2000      
simatic:plc=192.168.254.36:0.2
simatic:plc1212=192.168.254.99:0.1:OP
simatic:plc1515=192.168.254.127:0.1
simatic:plc417=192.168.254.128:0.3
simatic:plc200=192.168.254.128:0.3:200

When communication type is not specified, S7 is selected as default.

Item configuration

Binding specify item configuration is located as usual in the brackets at the end of the configuration line. It consists of three compulsory and two optional parameters.

Configuration format:

simatic="plc name:simatic item address:[used data type]:[direction]"
Configuration parameter Description
plc name PLC name that is specified in binding configuration in openhab.cfg. For simatic:plc= plc name is plc. For simatic:plc1= plc name is plc1.
simatic item address It is the address under which the data is stored in the Simatic device (ex. DB1.DBX0.0, MW400, I5.4, QW80). Only Inputs(I), Outputs(Q), Flags(M) and Datablocks (DB) are supported.
used data type Optional. Allow define data type. See table Supported data types
direction Optional. Can be I - input, O - output or IO - both (default). It is used only for request data from connected devices. So if all device items are outputs only, there would be no requesting for data from device.

Example of binding configuration:

Dimmer    Item01    "Value[%d]"    { simatic="plc:MB0" }
Number    Item02    "Value[%d]"    { simatic="plc:MD10:dword:IO" }
Number    Item03    "Value[%f]"    { simatic="plc:MD24:float:O" }
Number    Item04    "Value[%f]"    { simatic="plc:DB10.DBD4:float:I" }
String    Item05    "Value[%s]"    { simatic="plc:DB10.DBB10:array[32]:O" }
Color     TestColor01              { simatic="plc:MD100:rgb:O" }

Items optimisation

For large project it is necessary to optimise transferred address space. For fastest response is ideal put all data into one data area (datablock, bit memory, inputs, outputs) one by one without any gaps. That's because data from PLC are read in blocks. If there is gap between 2 defined data greater than 32 bytes, new read transaction is established. Same if there are lot of variables or gaps smaller than 32 bytes and block size is over limit. Maximum block size is PDU size depended. Its size is by PLC:

PLC type Supported
PDU size [B]
Maximum data size
in read transaction [B]
S7-300
S7-1200
240 222
S7-400
S7-1500 over CP1543
480 462
S7-1500 960 942
Optimised address space = fewer blocks = fewer transactions = faster response

Diagnostic item configuration

Binding itself offers some diagnostic states. There are available statuses for connected devices. These statuses can be provided into openHAB if they are properly configured (by use configuration parameter info behind PLC name).

PLC diagnostic info configuration format:

simatic="plc_name:info:state"

Port statuses:

Status Description Returned values
state Return current port status. 0 - Unknown
1 - Listening (opened and ready)
2 - Closed
3 - Not exist
4 - Not available (probably used)
5 - Response error (connection lost)
previous_state Return previous port status Same as state
state_change_time Return time when status was changed DateTime value

Example of diagnostic item configuration:

Number    PortState            "PLC state [%s]"                 { simatic="plc:info:state" }
Number    PortPreviouState     "PLC previous state [%s]"        { simatic="plc:info:previous_state" }
DateTime  PortStateChangeTime  "PLC changed [%1$tA, %1$td.%1$tm.%1$tY %1$tT]"    { simatic="plc:info:state_change_time" }
Clone this wiki locally