TB w/ Shelly EM Integration
Shelly Gen 1 設備,感測端回傳數值分別有各自相對應 topic,連同感測數值,不符合 TB telemetry JSON 格式 (key: value)。
When configured for MQTT Shelly EM reports data on:
shellies/shellyem-<deviceid>/emeter/<i>/pf power factor
shellies/shellyem-<deviceid>/emeter/<i>/power instantaneous active power in Watts
shellies/shellyem-<deviceid>/emeter/<i>/reactive_power instantaneous reactive power in Watts
shellies/shellyem-<deviceid>/emeter/<i>/total total energy in Wh (accumulated in device's non-volatile memory)
shellies/shellyem-<deviceid>/emeter/<i>/total_returned total energy returned to the grid in Wh (accumulated in device's non-volatile memory)
shellies/shellyem-<deviceid>/emeter/<i>/voltage grid voltage in Volts
要讓 Shelly EM,透過 MQTT,回傳感測數值至 TB,其一解法詳見本文。
TB <> TB IoT Gateway (ShellyEMMqttUplinkConverter) <> Mosquitto Broker <> Device: Shelly EM
ThingsBoard
- Dashbaords > Gateways > Add device
- Devices > Shelly-GW > Copy access token
ThingsBoard IoT Gateway w/ Mosquitto Mqtt Broker
Mosquitto mqtt broker
Package Installation
Config and Debug
- Config files: /etc/mosquitto/mosquitto.conf (/etc/mosquitto/cond.d/local.conf)
more
- Log files: /var/log/mosquitto/mosquitto.log
ThingsBoard IoT Gateway
Package Installation
- Download the deb file
wget https://github.com/thingsboard/thingsboard-gateway/releases/latest/download/python3-thingsboard-gateway.deb
- Install the gateway using apt
- Check gateway status
- Failed to start ThingsBoard Gateway
- Check and upgrade protobuf version Active: active (running)
terminal details
- Configure the gateway
- /etc/thingsboard-gateway/config/tb_gateway.yaml
more
- /etc/thingsboard-gateway/config/mqtt.json
more
{
"broker": {
"name": "Default Local Broker",
"host": "127.0.0.1",
"port": 1883,
"clientId": "ThingsBoard_gateway",
"maxMessageNumberPerWorker": 20,
"maxNumberOfWorkers": 100,
"security": {
"type": "anonymous"
}
},
"mapping": [
{
"topicFilter": "shellies/+/emeter/0/power",
"converter": {
"type": "custom",
"extension": "ShellyEMMqttUplinkConverter"
}
},
{
"topicFilter": "shellies/+/emeter/0/reactive_power",
"converter": {
"type": "custom",
"extension": "ShellyEMMqttUplinkConverter"
}
},
{
"topicFilter": "shellies/+/emeter/0/pf",
"converter": {
"type": "custom",
"extension": "ShellyEMMqttUplinkConverter"
}
},
{
"topicFilter": "shellies/+/emeter/0/voltage",
"converter": {
"type": "custom",
"extension": "ShellyEMMqttUplinkConverter"
}
},
{
"topicFilter": "shellies/+/emeter/0/total",
"converter": {
"type": "custom",
"extension": "ShellyEMMqttUplinkConverter"
}
},
{
"topicFilter": "shellies/+/emeter/0/total_returned",
"converter": {
"type": "custom",
"extension": "ShellyEMMqttUplinkConverter"
}
}
],
"connectRequests": [
{
"topicFilter": "sensor/connect",
"deviceNameJsonExpression": "${SerialNumber}"
},
{
"topicFilter": "sensor/+/connect",
"deviceNameTopicExpression": "(?<=sensor\/)(.*?)(?=\/connect)"
}
],
"disconnectRequests": [
{
"topicFilter": "sensor/disconnect",
"deviceNameJsonExpression": "${SerialNumber}"
},
{
"topicFilter": "sensor/+/disconnect",
"deviceNameTopicExpression": "(?<=sensor\/)(.*?)(?=\/disconnect)"
}
],
"attributeRequests": [
{
"retain": false,
"topicFilter": "v1/devices/me/attributes/request",
"deviceNameTopicExpression": "${SerialNumber}",
"attributeNameJsonExpression": "${sensorModel}"
}
],
"attributeUpdates": [
{
"retain": true,
"deviceNameFilter": "SmartMeter.*",
"attributeFilter": "uploadFrequency",
"topicExpression": "sensor/${deviceName}/${attributeKey}",
"valueExpression": "{\"${attributeKey}\":\"${attributeValue}\"}"
}
],
"serverSideRpc": [
{
"deviceNameFilter": ".*",
"methodFilter": "echo",
"requestTopicExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
"responseTopicExpression": "sensor/${deviceName}/response/${methodName}/${requestId}",
"responseTimeout": 10000,
"valueExpression": "${params}"
},
{
"deviceNameFilter": ".*",
"methodFilter": "no-reply",
"requestTopicExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
"valueExpression": "${params}"
}
]
}
- /var/lib/thingsboard_gateway/extensions/mqtt/shellyem_mqtt_uplink_converter.py
more
Config and Debug
- Config files: /etc/thingsboard-gateway/config/*
- connected_devices.json
- grpc_connector_1.json
- logs.conf
- mqtt.json
- request.json
- tb-cloud-chain.pem
- rest.json
- tb_gateway.yaml
- Log files: /var/log/thingsboard-gateway/*
- connector.log
- converter.log
- extension.log
- service.log
- storage.log
- tb_connection.log
Shellies
Shelly EM
- shellies/+/emter/0/+ (or shellies/+/emter/1/+)
or if we configured a custom prefix in the device settings: shellies/(custom_prefix)/(device_name)/#
- Try using software such as mqtt explorer to listen in on your mqtt broker.
It helps you determine which messages are being sent, and the topics on which they are broadcasted.
- Connect Shelly EM to Mosquitto Broker (allow_anonymous true)
Validations
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →