Shelly IoT device integration via MQTT #
Step 1 - Requirements #
- Connect Shelly devices to the same network as LM
- Updgrade Shelly devices firmware to the latest stable version. Several upgrade operations might be required.
- Install MQTT broker application on LM
- Install MQTT client application on LM
Step 2 - MQTT broker configuration #
- Enable MQTT broker without encryption
- Enable MQTT broker with encryption
- Disable Allow anonymous connections (no username/password)
- Create two users - lm and shelly, save passwords for later
- Optional you can also create a separate user per each Shelly device
Step 3 - Shelly configuration #
Shelly Gen1 devices #
- Go to Advanced - developer settings
- Disable CoIoT
- Enable MQTT
- Username: shelly
- Password: saved password from step 2
- Server address: LM_IP:1883
- Click Use custom MQTT prefix and save the value for later
- Click Save
Shelly Plus/Gen3 devices #
- Go to Settings - MQTT
- Enable MQTT
- Connection type - TLS no validation
- Enable MQTT Control
- Enable RPC over MQTT
- Enable Generic status update over MQTT
- Server address: LM_IP:8883
- Username: shelly
- Password: saved password from step 2
- Copy MQTT prefix and save the value for later
- Click Save settings
Step 4 - MQTT client configuration #
- Click the configuration icon (gear/cog)
- Enable MQTT connection
- Broker IP - 127.0.0.1
- Port - 1883
- Protocol version - 5
- Disable Encrypted connection
- Username: lm
- Password: saved password from step 2
- Client ID: lm
- Keep-alive interval: 30
Step 5 - Topic configuration #
By default all Shelly devices include MAC address as a part of the MQTT topic. Replace XXXXXXXXXXXX with the 12-character MAC from Step 3.
Shelly Flood #
Flood detection #
- LM object data type - 01. 1 bit (boolean)
- Direction - In
- Topic - shellies/shellyflood-XXXXXXXXXXXX/sensor/flood
Battery level #
- LM object data type - 05.001 scale
- Direction - In
- Topic - shellies/shellyflood-XXXXXXXXXXXX/sensor/battery
Temperature sensor value #
- LM object data type - 09.001 Temperature
- Direction - In
- Topic - shellies/shellyflood-XXXXXXXXXXXX/sensor/temperature
Shelly Plus H&T #
Temperature sensor value #
- LM object data type - 09.001 Temperature
- Direction - In
- Topic - shellyplusht-XXXXXXXXXXXX/status/temperature:0
- JSON value path - tC
Humidity sensor value #
- LM object data type - 05.001 scale
- Direction - In
- Topic - shellyplusht-XXXXXXXXXXXX/status/humidity:0
- JSON value path - rh
Battery level #
- LM object data type - 05.001 scale
- Direction - In
- Topic - shellyplusht-XXXXXXXXXXXX/status/devicepower:0
- JSON value path - battery.percent
Shelly Plus Smoke Alarm #
Smoke alarm #
- LM object data type - 01. 1 bit (boolean)
- Direction - In
- Topic - shellyplussmoke-XXXXXXXXXXXX/status/smoke:0
- JSON value path - alarm
Battery level #
- LM object data type - 05.001 scale
- Direction - In
- Topic - shellyplussmoke-XXXXXXXXXXXX/status/devicepower:0
- JSON value path - battery.percent
Shelly Plus 1PM #
Relay output control #
- LM object data type - 01. 1 bit (boolean)
- Direction - Out
- Topic - shellyplus1pm-XXXXXXXXXXXX/command/switch:0
- ON string - on
- OFF string - off
Relay output status #
- LM object data type - 01. 1 bit (boolean)
- Direction - In
- Topic - shellyplus1pm-XXXXXXXXXXXX/status/switch:0
- JSON value path - battery.output
The above configuration can be used for any Shelly device containing the Switch component. Make sure to change the topic prefix accordingly to match your device.
Power measurement #
- LM object data type - 14. 4 byte floating point
- Direction - In
- Topic - shellyplus1pm-XXXXXXXXXXXX/status/switch:0
- JSON value path - apower
Shelly Plus i4 #
Switch input status #
- LM object data type - 01. 1 bit (boolean)
- Direction - In
- Topics
- Switch 1 - shellyplusi4-XXXXXXXXXXXX/status/input:0
- Switch 2 - shellyplusi4-XXXXXXXXXXXX/status/input:1
- Switch 3 - shellyplusi4-XXXXXXXXXXXX/status/input:2
- Switch 4 - shellyplusi4-XXXXXXXXXXXX/status/input:3
- JSON value path - state
The above configuration can be used for any Shelly device containing the Input component. Make sure to change the topic prefix accordingly to match your device.
Shelly Plus 0-10V Dimmer #
Light control #
- LM object data type - 05.001 scale
- Direction - Out
- Topic - shellyplus010v-XXXXXXXXXXXX/rpc
- Script
return json.encode({
id = 0,
src = 'lm',
method = 'Light.Set',
params = {
id = 0,
on = value > 0,
brightness = value
}
})
Light on/off status #
- LM object data type - 01. 1 bit (boolean)
- Direction - In
- Topic - shellyplus010v-XXXXXXXXXXXX/status/light:0
- JSON value path - output
Light brightness status #
- LM object data type - 05.001 scale
- Direction - In
- Topic - shellyplus010v-XXXXXXXXXXXX/status/light:0
- JSON value path - brightness
The above configuration can be used for any Shelly device containing the Light component. Make sure to change the topic prefix accordingly to match your device.
Switch input status #
- LM object data type - 01. 1 bit (boolean)
- Direction - In
- Topics
- Switch 1 - shellyplus010v-XXXXXXXXXXXX/status/input:0
- Switch 2 - shellyplus010v-XXXXXXXXXXXX/status/input:1
- JSON value path - state
Inputs must be enabled in Input/Output settings. Set mode to Toggle switch.
Other Shelly devices #
Connect to LM using MQTT Explorer to discover topic structure and data format.
Visit LogicMachine Forum if you have any questions.