LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
item.h File Reference

Item (virtual channel) system of LightHub. More...

#include "options.h"
#include "abstractout.h"
#include "itemCmd.h"
#include "aJSON.h"

Go to the source code of this file.

Classes

class  Item
 A single LightHub item (virtual channel). More...
class  driverFactory
 Creates and shares output drivers for items. More...
union  thermostatStore
 CH_THERMO runtime state packed into one int32 (stored in I_EXT). More...

Macros

#define S_NOTFOUND   0
#define S_CMD   1
#define S_SET   2
#define S_VAL   3
#define S_DELAYED   4
#define S_HSV   5
#define S_RGB   6
#define S_FAN   7
#define S_MODE   8
#define S_CTRL   9
#define S_HUE   10
#define S_SAT   11
#define S_TEMP   12
#define S_RAW   13
#define suffixNum   sizeof(suffix_P)/sizeof(suffixstr)
#define S_ADDITIONAL   13
#define CH_DIMMER   0
#define CH_RGBW   1
#define CH_RGB   2
#define CH_PWM   3
#define CH_MODBUS   4
#define CH_THERMO   5
#define CH_RELAY   6
#define CH_GROUP   7
#define CH_VCTEMP   8
#define CH_VC   9
#define CH_AC   10
#define CH_SPILED   11
#define CH_MOTOR   12
#define CH_PID   13
#define CH_MBUS   14
#define CH_UARTBRIDGE   15
#define CH_RELAYX   16
#define CH_RGBWW   17
#define CH_MULTIVENT   18
#define CH_ELEVATOR   19
#define CH_COUNTER   20
#define CH_HUMIDIFIER   21
#define CH_MERCURY   22
#define CH_SPRINKLER   23
#define CH_MAX   23
#define POLLING_SLOW   1
#define POLLING_FAST   2
#define POLLING_INT   3
#define POLLING_1S   4
#define CTRL_DISABLE_RECURSION   1
#define CTRL_DISABLE_NON_GRP   2
#define CTRL_SCHEDULED_CALL_RECURSION   (CTRL_DISABLE_RECURSION | CTRL_DISABLE_NON_GRP)
#define I_TYPE   0
#define I_ARG   1
#define I_VAL   2
#define I_CMD   3
#define I_EXT   4
#define I_TIMESTAMP   5
#define MODBUS_CMD_ARG_ADDR   0
#define MODBUS_CMD_ARG_REG   1
#define MODBUS_CMD_ARG_MASK   2
#define MODBUS_CMD_ARG_MAX_SCALE   3
#define MODBUS_CMD_ARG_REG_TYPE   4
#define MODBUS_COIL_REG_TYPE   0
#define MODBUS_DISCRETE_REG_TYPE   1
#define MODBUS_HOLDING_REG_TYPE   2
#define MODBUS_INPUT_REG_TYPE   3

Typedefs

typedef char suffixstr[5]

Functions

short thermoSetCurTemp (char *name, float t)
int txt2cmd (char *payload)
int txt2subItem (char *payload)

Variables

const suffixstr suffix_P[] PROGMEM
aJsonObject * items

Detailed Description

Item (virtual channel) system of LightHub.

LightHub models every controllable device, sensor or service as an "item" (virtual channel) stored as a JSON array inside the global items object: [type, arg, val, cmd, ext, timestamp] (element indexes I_TYPE..I_TIMESTAMP). The item name is the key of the array; the type (CH_*) selects the driver module (DMX dimmer, relay, Modbus, thermostat, AC, ...) that handles it.

An item can be a single channel (CH_DIMMER, CH_RELAY, ...) or a CH_GROUP pseudo-channel which fans commands out recursively to its members. Commands and values travel to/from items as itemCmd structures and are published to MQTT topics with the suffixes of suffix_P (cmd/set/val/del/HSV/RGB/fan/mode/ctrl/hue/sat/temp/raw).

Macro Definition Documentation

◆ CH_AC

#define CH_AC   10

◆ CH_COUNTER

#define CH_COUNTER   20

◆ CH_DIMMER

#define CH_DIMMER   0

Channel (item) types, indexes CH_DIMMER(0)..CH_SPRINKLER(23)=CH_MAX. The type is stored in the I_TYPE element of the item array and selects the output driver module that handles the item.

  • CH_DIMMER = 0 - DMX dimmer, 1-4 channels
  • CH_RGBW = 1 - DMX 4-channel RGB+W
  • CH_RGB = 2 - DMX 3-channel RGB
  • CH_PWM = 3 - PWM output directly to PIN, 1-4 CH
  • CH_MODBUS = 4 - Modbus AC dimmer
  • CH_THERMO = 5 - simple ON/OFF thermostat
  • CH_RELAY = 6 - ON/OFF relay output
  • CH_GROUP = 7 - group pseudo-channel (fan-out to members)
  • CH_VCTEMP = 8 - Vacom PID temperature regulator
  • CH_VC = 9 - Vacom Modbus fan (motor) regulator
  • CH_AC = 10 - Haier AC
  • CH_SPILED = 11 - SPI LED strip
  • CH_MOTOR = 12 - motorized gate with feedback resistor
  • CH_PID = 13 - generic PID regulator
  • CH_MBUS = 14 - universal Modbus master channel
  • CH_UARTBRIDGE = 15 - bridge between 2 UARTs (PDU reporting via UDP)
  • CH_RELAYX = 16 - slow PWM relay for objects with inertia
  • CH_RGBWW = 17 - DMX RGBWW (warm and cold white)
  • CH_MULTIVENT = 18 - multichannel ventilation
  • CH_ELEVATOR = 19 - elevator controller
  • CH_COUNTER = 20 - generic counter
  • CH_HUMIDIFIER = 21 - humidifier
  • CH_MERCURY = 22 - Mercury energy meter / RS485 interface
  • CH_SPRINKLER = 23 - sprinkler controller

◆ CH_ELEVATOR

#define CH_ELEVATOR   19

◆ CH_GROUP

#define CH_GROUP   7

◆ CH_HUMIDIFIER

#define CH_HUMIDIFIER   21

◆ CH_MAX

#define CH_MAX   23

◆ CH_MBUS

#define CH_MBUS   14

◆ CH_MERCURY

#define CH_MERCURY   22

◆ CH_MODBUS

#define CH_MODBUS   4

◆ CH_MOTOR

#define CH_MOTOR   12

◆ CH_MULTIVENT

#define CH_MULTIVENT   18

◆ CH_PID

#define CH_PID   13

◆ CH_PWM

#define CH_PWM   3

◆ CH_RELAY

#define CH_RELAY   6

◆ CH_RELAYX

#define CH_RELAYX   16

◆ CH_RGB

#define CH_RGB   2

◆ CH_RGBW

#define CH_RGBW   1

◆ CH_RGBWW

#define CH_RGBWW   17

◆ CH_SPILED

#define CH_SPILED   11

◆ CH_SPRINKLER

#define CH_SPRINKLER   23

◆ CH_THERMO

#define CH_THERMO   5

◆ CH_UARTBRIDGE

#define CH_UARTBRIDGE   15

◆ CH_VC

#define CH_VC   9

◆ CH_VCTEMP

#define CH_VCTEMP   8

◆ CTRL_DISABLE_NON_GRP

#define CTRL_DISABLE_NON_GRP   2

◆ CTRL_DISABLE_RECURSION

#define CTRL_DISABLE_RECURSION   1

Group execution flags passed to Item::Ctrl(itemCmd, ...):

  • CTRL_DISABLE_RECURSION - do not recurse into group members
  • CTRL_DISABLE_NON_GRP - skip non-group items
  • CTRL_SCHEDULED_CALL_RECURSION - both; used when a scheduled (delayed) group command fires back

◆ CTRL_SCHEDULED_CALL_RECURSION

#define CTRL_SCHEDULED_CALL_RECURSION   (CTRL_DISABLE_RECURSION | CTRL_DISABLE_NON_GRP)

◆ I_ARG

#define I_ARG   1

◆ I_CMD

#define I_CMD   3

◆ I_EXT

#define I_EXT   4

◆ I_TIMESTAMP

#define I_TIMESTAMP   5

◆ I_TYPE

#define I_TYPE   0

Element indexes of the item JSON array:

  • I_TYPE - channel type (CH_*)
  • I_ARG - channel-type depended argument (pin, address or argument array)
  • I_VAL - latest preset value (int, float or array of presets)
  • I_CMD - latest command received (CMD_* packed with FLAG_* bits)
  • I_EXT - channel-depended extension data
  • I_TIMESTAMP - armed delayed command (ms timestamp, subtype = CMD_*)

◆ I_VAL

#define I_VAL   2

◆ MODBUS_CMD_ARG_ADDR

#define MODBUS_CMD_ARG_ADDR   0

Argument array indexes of a CH_MODBUS item: I_ARG = [addr, reg, mask, maxScale, regType].

◆ MODBUS_CMD_ARG_MASK

#define MODBUS_CMD_ARG_MASK   2

◆ MODBUS_CMD_ARG_MAX_SCALE

#define MODBUS_CMD_ARG_MAX_SCALE   3

◆ MODBUS_CMD_ARG_REG

#define MODBUS_CMD_ARG_REG   1

◆ MODBUS_CMD_ARG_REG_TYPE

#define MODBUS_CMD_ARG_REG_TYPE   4

◆ MODBUS_COIL_REG_TYPE

#define MODBUS_COIL_REG_TYPE   0

Modbus register types: 0 - coils, 1 - discrete inputs, 2 - holding, 3 - input.

◆ MODBUS_DISCRETE_REG_TYPE

#define MODBUS_DISCRETE_REG_TYPE   1

◆ MODBUS_HOLDING_REG_TYPE

#define MODBUS_HOLDING_REG_TYPE   2

◆ MODBUS_INPUT_REG_TYPE

#define MODBUS_INPUT_REG_TYPE   3

◆ POLLING_1S

#define POLLING_1S   4

◆ POLLING_FAST

#define POLLING_FAST   2

◆ POLLING_INT

#define POLLING_INT   3

◆ POLLING_SLOW

#define POLLING_SLOW   1

Polling rates/causes passed to Item::Poll() and driver Poll():

  • POLLING_SLOW - periodic slow poll cycle
  • POLLING_FAST - fast poll loop
  • POLLING_INT - called from an interrupt context (ISR-safe actions only)
  • POLLING_1S - once per second tick

◆ S_ADDITIONAL

#define S_ADDITIONAL   13

◆ S_CMD

#define S_CMD   1

◆ S_CTRL

#define S_CTRL   9

◆ S_DELAYED

#define S_DELAYED   4

◆ S_FAN

#define S_FAN   7

◆ S_HSV

#define S_HSV   5

◆ S_HUE

#define S_HUE   10

◆ S_MODE

#define S_MODE   8

◆ S_NOTFOUND

#define S_NOTFOUND   0

Suffix (subtopic) codes - indexes of the suffix_P table below. S_NOTFOUND means "no suffix given" (universal/empty OpenHAB topic).

◆ S_RAW

#define S_RAW   13

◆ S_RGB

#define S_RGB   6

◆ S_SAT

#define S_SAT   11

◆ S_SET

#define S_SET   2

◆ S_TEMP

#define S_TEMP   12

◆ S_VAL

#define S_VAL   3

◆ suffixNum

#define suffixNum   sizeof(suffix_P)/sizeof(suffixstr)

Typedef Documentation

◆ suffixstr

typedef char suffixstr[5]

MQTT topic suffixes (subtopics) used per item:

  • "" - base item topic
  • "cmd" - current command (ON/OFF/...)
  • "set" - setpoint / target value
  • "val" - actual measured value
  • "del" - delayed (timed) command status, remaining time
  • "HSV" - HSV color notation for color channels
  • "RGB" - RGB color notation for color channels
  • "fan" - fan speed subchannel (AC/vent)
  • "mode" - device mode (AC modes)
  • "ctrl" - control flags (ENABLE/DISABLE/FREEZE)
  • "hue" - hue component only
  • "sat" - saturation component only
  • "temp" - color temperature component only
  • "raw" - raw (unparsed) payload passthrough

Function Documentation

◆ thermoSetCurTemp()

short thermoSetCurTemp ( char * name,
float t )
extern

Store the current measured temperature of a CH_THERMO item by name.

◆ txt2cmd()

int txt2cmd ( char * payload)

Translate a text payload to a command code.

Parameters
payload- text command word ("ON", "HALT", ...), number or color
Returns
CMD_* code; CMD_VOID for plain numbers, CMD_UNKNOWN if unrecognized

◆ txt2subItem()

int txt2subItem ( char * payload)

Translate a subtopic text to a suffix code (index of suffix_P).

Parameters
payload- suffix text ("cmd", "set", "val", ...)
Returns
suffix code (S_*) or S_NOTFOUND

Variable Documentation

◆ items

aJsonObject* items
extern

Global JSON object with all items (virtual channels) of this device.

◆ PROGMEM

const suffixstr suffix_P [] PROGMEM
Initial value:
=
{"","cmd","set","val","del","HSV","RGB","fan","mode","ctrl","hue","sat","temp","raw"}