GekoCH
(Andy)
May 16, 2022, 8:13am
21
I have two Shelly PM that somehow crashed my openhab.
They publish at 1s interval this topic:
{"id":0, "source":"init", "output":true, "apower":151.5, "voltage":222.5, "current":0.710, "aenergy":{"total":15764.484,"by_minute":[1936.493,2420.843,2402.431],"minute_ts":1652688287},"temperature":{"tC":62.1, "tF":143.8}}
label: Shelly Server PM
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mosquittoDebianBroker
channels:
- id: power
channelTypeUID: mqtt:number
label: Power
description: null
configuration:
stateTopic: shellies/server-pm/status
transformationPattern: JSONPATH:$.apower
- id: powerSwitch
channelTypeUID: mqtt:switch
label: Power Switch
description: null
configuration:
commandTopic: shellies/server-pm/rpc
postCommand: false
stateTopic: shellies/server-pm/status/switch:0
transformationPattern: JS:shelly1plus.js
off: '{"id":0, "src":"switch", "method":"Switch.Set",
"params":{"id":0,"on":false}}'
on: '{"id":0, "src":"switch", "method":"Switch.Set",
"params":{"id":0,"on":true}}'
GekoCH:
helly1plus.js
Can you share this script too?
And this topic is what the JSON extract is published to? With the colon?
GekoCH
(Andy)
May 16, 2022, 8:45am
23
(function(i){
var obj = JSON.parse(i);
var end = obj.output
if (end == false){
return "OFF";
}
if (end == true){
return "ON";
}
})(input)
yes
Thanks. I’ll try set something up tonight using the power data. I won’t copy the switch Channel, as I can’t quite tell what it’s doing, but I guess that’s not the one receiving all the updates?
GekoCH
(Andy)
May 16, 2022, 9:41am
25
the powerSwitch is not important it’s just to switch the power source on or off. And this topic does only update when there is a switch happening. The important one is the shellies/server-pm/status topic
So far everything is still up and running. I’m using the script below to publish data every 0.5 seconds.
import paho.mqtt.client as mqtt
import random
from time import sleep
#SETUP MQTT
mqtt_client = mqtt.Client("rate_test")
mqtt_client.connect("192.168.1.151")
run_time_hrs = 24
publish_interval = 0.5
steps = int(run_time_hrs*60*60/publish_interval)
for i in range(steps):
apower = random.randrange(0, 300)
message = '{"id":0, "source":"init", "output"
:true, "apower":'+str(apower)+', "voltage":222.5,
"current":0.710, "aenergy":{"total":15764.484,"b
y_minute":[1936.493,2420.843,2402.431],"minute_ts
":1652688287},"temperature":{"tC":62.1, "tF":143.
8}}'
print("{}/{}: Power: {}".format(i,steps,apowe
r))
mqtt_client.publish("shellies/server-pm/statu
s",message)
sleep(publish_interval)
mqtt_client.disconnect()
It’s been running for ~12hrs so far, and the openHAB Item is still updating.
EDIT:
Test Thing
Thing mqtt:topic:mqtt_rate_test "MQTT Rate Test" (mqtt:broker:MosquittoMqttBroker) {
Channels:
Type number : power [
stateTopic="shellies/server-pm/status",
transformationPattern="JSONPATH:$.apower"
]
}
or
UID: mqtt:topic:mqtt_rate_test
label: MQTT Rate Test
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:MosquittoMqttBroker
channels:
- id: power
channelTypeUID: mqtt:number
label: Number Value
description: null
configuration:
retained: false
postCommand: false
step: 1
formatBeforePublish: "%s"
stateTopic: shellies/server-pm/status
transformationPattern: JSONPATH:$.apower
Test Items
Number nMQTTRateTestPower "Power" {channel="mqtt:topic:mqtt_rate_test:power"}
DateTime dtMQTTRateTestPower "Last power" { channel="mqtt:topic:mqtt_rate_test:power" [profile="timestamp-update"] }
GekoCH
(Andy)
May 17, 2022, 6:39am
27
interesting mine failed after around 3 hours.
I will use your script and test if it won’t fail on my side as well
After 24hrs the Item is still actively updating, and the only thing that I can see which is different to ‘normal’ is increased Disk IO for the openHAB container:
(The first continuously high levels where during script testing, the second during this last period).
I have MapDB enabled with default config - perhaps the cause for this.
CPU usage was higher too during the testing periods, but only rising from 0.5% to 2%:
But the MQTT Binding didn’t seem to break a sweat.
GekoCH
(Andy)
May 18, 2022, 8:05am
29
ok I had running your script for more then 4 hours and no fail as well. I will now try to reproduce the mentioned error in the beginning of the thread with the Shelly PM device. lets see…