0.9.13 • Published 5 years ago

pimatic-mqtt v0.9.13

Weekly downloads
26
License
AGPL-3.0
Repository
github
Last release
5 years ago

pimatic-mqtt

npm version

MQTT plugin for Pimatic

Screenshots

Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4 Screenshot 5

Status of implementation

This version supports the following

  • General sensor (numeric and text data from payload)
  • Switch
  • PresenceSensor
  • ContactSensor
  • Dimmer
  • Buttons
  • Shutter
  • Input

Sponsoring

Do you like this plugin? Then please consider a donation to support the development.

Getting Started

This section is still work in progress.

Plugin Configuration

While run MQTT broker on localhost and on a standard port, without autentification, you can load the plugin by editing your config.json to include the following in the plugins section.

{
  "plugin": "mqtt",
  "active": true,
  "brokers": [
    {
      "brokerId": "default"
    }
  ]
}

Configuration with two Brokers

{
  "plugin": "mqtt",
  "active": true,
  "brokers": [
    {
      "brokerId": "default"
      "host": "localhost"
    },
    {
      "brokerId": "eclipse",
      "host": "iot.eclipse.org"
    }
  ]
}

The configuration for a broker is an object comprising the following properties.

PropertyDefaultTypeDescription
brokerId"default"StringId of the broker
host"127.0.0.1"StringBroker hostname or IP
port1883IntegerBroker port
keepalive180IntegerKeepalive in seconds
clientIdpimatic*String*pimatic + random number or your own clientId
protocolId"MQTT"StringWith broker that supports only MQTT 3.1 (not 3.1.1 compliant), you should pass "MQIsdp"
protocolVer4IntegerWith broker that supports only MQTT 3.1 (not 3.1.1 compliant), you should pass 3
cleanSessiontrueBooleanSet to false to receive QoS 1 and 2 messages while offline
reconnect5000IntegerReconnect period in milliseconds
timeout30000IntegerConnect timeout in milliseconds
queueQoSZerotrueBooleanIf connection is broken, queue outgoing QoS zero messages
username-StringThe login name
password-StringThe Password
certPath-StringPath to the certificate of the client in PEM format, required for TLS connection
keyPath-StringPath to the key of the client in PEM format, required for TLS connection
rejectUnauthorizedtrueBooleanWhether to reject self signed certificates
ca-StringPath to the trusted CA list

Device Configuration

Devices must be added manually to the device section of your pimatic config.

Generic sensor

MqttSensor is based on the Sensor device class. Handles numeric and text data from the payload.

{
  "name": "Soil Hygrometer analog reading",
  "id": "wemosd1r2-2",
  "class": "MqttSensor",
  "attributes": [
    {
      "name": "soil-hygrometer",
      "topic": "wemosd1r2/moisture/humidity",
      "type": "number",
      "acronym": "rH"
    }
  ]
},
{
  "name": "ESP01 with battery",
  "id": "esp01",
  "class": "MqttSensor",
  "attributes": [
    {
      "name": "temperature",
      "topic": "myhome/firstfloor/office/esp01/dht11/temperature",
      "type": "number",
      "unit": "°C",
      "acronym": "DHT-11-Temperature"
    },
    {
      "name": "humidity",
      "topic": "myhome/firstfloor/office/esp01/dht11/humidity",
      "type": "number",
      "unit": "%",
      "acronym": "DHT-11-Humidity"
    }
  ]
},
{
  "name": "Mosquitto",
  "id": "mosquitto",
  "class": "MqttSensor",
  "attributes": [
    {
      "name": "connected-clients",
      "topic": "$SYS/broker/clients/connected",
      "type": "number",
      "acronym": "Clients",
      "discrete": true
    },
    {
      "name": "ram-usage",
      "topic": "$SYS/broker/heap/current",
      "type": "number",
      "unit": "B",
      "acronym": "RAM usage"
    }
  ],
  "xAttributeOptions": [
    {
      "name": "connected-clients",
      "displaySparkline": false
    },
    {
      "name": "ram-usage",
      "displaySparkline": false
    }
  ]
}

Supports lookup table to translate received message to another value.

{
  "name": "Sensor with lookup",
  "id": "sensor-with-lookup",
  "class": "MqttSensor",
  "attributes": [
    {
      "name": "state",
      "topic": "some/topic",
      "type": "string",
      "unit": "",
      "acronym": "",
      "messageMap": {
        "0": "Not ready",
        "1": "Ready",
        "2": "Completed"
      }
    }
  ]
}

Accepts flat JSON message

Sample mqtt message: {"rel_pressue": "30.5015", "wind_ave": "0.00", "rain": "0", "rainin": "0", "hum_in": "64", "temp_in_f": "66.4", "dailyrainin": "0", "wind_dir": "225", "temp_in_c": "19.1", "hum_out": "81", "dailyrain": "0", "wind_gust": "0.00", "idx": "2015-10-22 21:41:03", "temp_out_f": "49.6", "temp_out_c": "9.8"}

{
  "class": "MqttSensor",
  "id": "weatherstation",
  "name": "Weather Station",
  "attributes": [
    {
      "name": "temp_in_c",
      "topic": "weatherstation",
      "type": "number",
      "unit": "c",
      "acronym": "Inside Temperature"
    },
    {
      "name": "temp_out_c",
      "topic": "weatherstation",
      "type": "number",
      "unit": "c",
      "acronym": "Outside Temperature"
    }
  ]
}

Accepts JSON message with hierarchy

Sample mqtt message: {"kodi_details": {"title": "", "fanart": "", "label": "The.Victorias.Secret.Fashion.Show.2015.720p.HDTV.x264.mkv", "type": "unknown", "streamdetails": {"video": {"stereomode": "", "width": 1280, "codec": "h264", "aspect": 1.7777780294418335, "duration": 2537, "height": 720}, "audio": {"channels": 6, "codec": "ac3", "language": ""}, "subtitle": {"language": ""}}}, "val": ""}

{
  "name": "Kodi media info",
  "id": "kodi-media-info",
  "class": "MqttSensor",
  "attributes": [
    {
      "name": "kodi_details.label",
      "topic": "kodi/status/title",
      "type": "string",
      "acronym": "label"
    },
    {
      "name": "kodi_details.streamdetails.video.0.codec",
      "topic": "kodi/status/title",
      "type": "string",
      "acronym": "codec"
    }
  ]
}

It has the following configuration properties:

PropertyDefaultTypeDescription
brokerId"default"StringId of the broker
topic-StringTopic for device state
qos0NumberThe QoS level of the topic and stateTopic (if exist)
type"number"StringThe type of the variable(string or number)
unit-StringAttribute unit
acronym-StringAcronym to show as value label in the frontend
discretefalseBooleanShould be set to true if the value does not change continuously over time.
division-NumberConstants that will divide the value obtained
multiplier-NumberConstant that will multiply the value obtained
messageMap-ObjectEven Pimatic 9, you must manually configure this. We're working on it.

Switch Device

MqttSwitch is based on the PowerSwitch device class.

{
  "name": "MQTT Switch",
  "id": "switch",
  "class": "MqttSwitch",
  "topic": "wemosd1r2/gpio/2/set",
  "stateTopic": "wemosd1r2/gpio/2/state"
  "onMessage": "1",
  "offMessage": "0"
}

It has the following configuration properties:

PropertyDefaultTypeDescription
brokerId"default"StringId of the broker
topic-StringTopic for device state
onMessage"1"StringMessage to switch on
offMessage"0"StringMessage to switch off
stateTopic-StringTopic that communicates state, if exists
stateValueKey-StringThe key or path to the state value, given that the payload contains a JSON object
qos0NumberThe QoS level of the topic and stateTopic (if exist)
retainfalseBooleanIf the published message should have the retain flag on or not.

Device exhibits the following attributes:

PropertyUnitTypeAcronymDescription
state-Boolean-Switch State, true is on, false is off

The following predicates and actions are supported:

  • {device} is turned on|off
  • switch {device} on|off
  • toggle {device}

Presence Sensor

MqttPresenceSensor is a digital input device based on the PresenceSensor device class.

{
  "name": "MQTT PIR Sensor",
  "id": "mqtt-pir-sensor",
  "class": "MqttPresenceSensor",
  "topic": "wemosd1r2/pir/presence",
  "onMessage": "1",
  "offMessage": "0"
}

It has the following configuration properties:

PropertyDefaultTypeDescription
brokerId"default"StringId of the broker
topic-StringTopic for device state
stateValueKey-StringThe key or path to the state value, given that the payload contains a JSON object
onMessage"1"StringMessage that invokes positive status
offMessage"0"StringMessage that invokes negative status
qos0NumberThe QoS level of the topic and stateTopic (if exist)

The presence sensor exhibits the following attributes:

PropertyUnitTypeAcronymDescription
presence-Boolean-Presence State, true is present, false is absent

The following predicates are supported:

  • {device} is present|absent

Contact Sensor

MqttContactSensor is a digital input device based on the ContactSensor device class.

{
  "name": "MQTT Contact",
  "id": "mqtt-contact",
  "class": "MqttContactSensor",
  "topic": "wemosd1r2/contact/state",
  "onMessage": "1",
  "offMessage": "0"
}

It has the following configuration properties:

PropertyDefaultTypeDescription
brokerId"default"StringId of the broker
topic-StringTopic for device state
stateValueKey-StringThe key or path to the state value, given that the payload contains a JSON object
onMessage"1"StringMessage that invokes positive status
offMessage"0"StringMessage that invokes negative status
qos0NumberThe QoS level of the topic and stateTopic (if exist)

The presence sensor exhibits the following attributes:

PropertyUnitTypeAcronymDescription
contact-Boolean-Contact State, true is opened, false is closed

The following predicates are supported:

  • {device} is opened|closed

Dimmer Device

MqttDimmer is based on the Dimmer device class.

{
  "name": "MQTT Dimmer",
  "id": "mqtt-dimmer",
  "class": "MqttDimmer",
  "topic": "wemosd1r2/pcapwm/5/brightness",
  "stateTopic": "wemosd1r2/pcapwm/5/state",
  "resolution": 4096
},
    {
  "topic": "dimmer/cmd",
  "resolution": 1024,
  "id": "dimmer",
  "name": "Dimmer",
  "class": "MqttDimmer",
  "message": "pwm,15,value,2000"
}

It has the following configuration properties:

PropertyDefaultTypeDescription
brokerId"default"StringId of the broker
topic-StringTopic for control dimmer brightness.
resolution256IntegerResolution of this dimmer. For percent set 101.
message"value"StringFormat for outgoing message.
stateTopic-StringTopic that communicates state, if exists
stateValueKey-StringThe key or path to the state value, given that the payload contains a JSON object
qos0NumberThe QoS level of the topic and stateTopic (if exist)
retainfalseBooleanIf the published message should have the retain flag on or not.

The Dimmer Action Provider:

  • dim the device to value%

Buttons Device

MqttButtons is based on the ButtonsDevice device class.

{
  "name": "Buttons",
  "id": "buttons-demo",
  "class": "MqttButtons",
  "buttons": [
    {
      "id": "button1",
      "text": "Press me",
      "topic": "some/topic",
      "message": "1"
    }
  ]
}

It has the following configuration properties for each button:

PropertyDefaultTypeDescription
brokerId"default"StringId of the broker
id-StringButton id
text-StringButton text
topic-StringTopic for device state
message-StringPublish message when pressed
stateTopic-StringTopic that communicates state, if exists
stateValueKey-StringThe key or path to the state value, given that the payload contains a JSON object
qos0NumberThe QoS level of the topic and stateTopic (if exist)
confirmfalseBooleanAsk the user to confirm the button press

The Button Action Provider

  • press the device

Rules

You can publish mqtt messages in rules with the action:

publish mqtt message "<string with variables>" on topic "<string with variables>" [on broker ListOfBrokers] [qos: 0|1|2] [retain: true|false]

"rules": [
  {
    "id": "my-rule",
    "rule": "when every 3 seconds then publish mqtt message \"msg\" on topic \"topic\" on broker default qos: 1 retain: true",
    "active": true,
    "logging": false,
    "name": "Publish mqtt"
  }
]

You can trigger rules by mqtt messages with the predicate:

mqtt received "<message>" on topic "<topic>" [via broker ListOfBrokers] [qos: 0|1|2]

"rules": [
  {
    "id": "my-rule-2",
    "name": "Receive mqtt",
    "rule": "when mqtt received \"1\" on topic \"topic\" via broker default qos: 0 then log \"Yeah!\"",
    "active": true,
    "logging": true
  }
]

To Do

'x' marks done To Do items

  • Add RGB device
  • Reflecting external condition for dimmer
  • Reflecting external condition for buttons
  • QoS and retain flag
  • Processing JSON-encoded object
  • Make payload configurable for all device
  • Buttons Device
  • Configurable PWM range for Dimmer
  • Configurable CIE1931 correction for Dimmer
  • Support for more then one Broker
  • Sending all variables from Pimatic to Broker/s
  • Control Pimatic over MQTT :)
  • Integration with ActionProvider
  • TLS support
  • Add shutter device
  • Add text and numeric input device
  • JSON filtering for state values

Credits

sweet pi for his work on best automatization software Pimatic and all guys from the pimatic community.

Andre Miller for for his module pimatic-mqtt-simple from which it comes also part of the code.

Marcus Wittig for his nice module pimatic-johnny-five which was a big inspiration.

0.9.13

5 years ago

0.9.12

5 years ago

0.9.11

5 years ago

0.9.10

6 years ago

0.9.9

7 years ago

0.9.8

7 years ago

0.9.7

7 years ago

0.9.6

7 years ago

0.9.5

7 years ago

0.9.4

7 years ago

0.9.3

8 years ago

0.9.2

8 years ago

0.9.1

8 years ago

0.9.0

8 years ago

0.8.15

8 years ago

0.8.13

8 years ago

0.8.14

8 years ago

0.8.12

8 years ago

0.8.11

8 years ago

0.8.10

8 years ago

0.8.9

8 years ago

0.8.8

8 years ago

0.8.7

8 years ago

0.8.6

8 years ago

0.8.5

8 years ago

0.8.4

8 years ago

0.8.3

8 years ago

0.8.2

8 years ago