Python Plugin: Shelly MQTT
Moderator: leecollings
-
- Posts: 47
- Joined: Tuesday 24 November 2020 17:57
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
I tried installing mqtt explorer on my laptop. In the connection settings I entered the address of the rpi on which the mosquitto broker is installed. Hope that is the correct way to set it up. And I get the error "Connection refused, identifier rejected".
-
- Posts: 47
- Joined: Tuesday 24 November 2020 17:57
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
Never mind, I uninstalled mqtt broker completely from raspbian. I have a concurrent Home Assistant install on the pi. Installed MQTT on that, which is almost a 1-click install, and that is broking the domoticz messages too.
-
- Posts: 6
- Joined: Thursday 22 August 2019 7:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
When i add the shelly mqtt plugin and add it on the hardware page in Domoticz, the plugin first causes Domoticz to run very slow and after half a minute it crashes domoticz.
I am running Domoticz version 2022.1 on a new raspberry pi 4b 4GB and a clean install with all the latest versions.
Does anyone has an idea how to solve this issue?
Crash log:
I am running Domoticz version 2022.1 on a new raspberry pi 4b 4GB and a clean install with all the latest versions.
Does anyone has an idea how to solve this issue?
Crash log:
Code: Select all
20 Thread 0xaeaff200 (LWP 31794) "Shellymqtt" 0xb68ba4d4 in __GI___wait4 (pid=31806, stat_loc=0x196d7c0, options=0, usage=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
Thread 20 (Thread 0xaeaff200 (LWP 31794) "Shellymqtt"):
#0 0xb68ba4d4 in __GI___wait4 (pid=31806, stat_loc=0x196d7c0, options=0, usage=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
#1 0x0029121c in dumpstack_gdb(bool) ()
#2 0x002917e8 in signal_handler(int, siginfo_t*, void*) ()
#3 <signal handler called>
#4 raise (sig=11) at ../sysdeps/unix/sysv/linux/raise.c:50
#5 <signal handler called>
#6 0x0000000c in ?? ()
#7 0xb593247c in _PyEval_EvalFrameDefault () from /lib/arm-linux-gnueabihf/libpython3.9.so
#8 0xaec82bc4 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Python Plugin: Shelly MQTT
RPi running on Bullseye OS have a general issue with stable 2022.1 and python plugins.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 6
- Joined: Thursday 22 August 2019 7:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
Now that i got it working under Raspian Buster, i found i didn't got any energy read from my Shelly plug s devices even the option to do so was set under hardware. Digging in to the code of the plugin and logging the output i found that the folowing:
In the Domoticz log:
And in plugin.py:
As seen in the log, the power message and the energy message are received one right after the other with just a few milliseconds between them, but the second message with the energy information was not processed (no update: line).
In plugin.py (line 551) there is an extra check to only process the new message if there is more then 10 seconds (?) passed since the previous message. But because the two messages are send right after each other, that check blocks the upload to Domoticz. Removing the check made it work, but was it the right fix?
One other minor issue i found is a rounding error in the calculation from watts per minute to watts per hour on line 527:
Which i changed to:
Dividing 1/60 gives 0.01666666666666666, rounding it to 0.017 loses some significant precision.
In the Domoticz log:
Code: Select all
2022-03-27 10:50:11.756 Shelly Mqtt: MQTT message: shellies/shellyplug-s-C6E8BC/relay/0/power 30.62
2022-03-27 10:50:11.756 Shelly Mqtt: >>> Looking for device: shellyplug-s-C6E8BC-0-energy
2022-03-27 10:50:11.756 Shelly Mqtt: OnlyPower
2022-03-27 10:50:11.756 Shelly Mqtt: Device data: shellyplug-s-C6E8BC-0-energy value: 30.62;0 lastupdate: 2022-03-27 10:49:41
2022-03-27 10:50:11.769 Shelly Mqtt: Device update timedelta: 30
2022-03-27 10:50:11.769 Shelly Mqtt: update: shellyplug-s-C6E8BC-0-energy value: 30.62;0 lastupdate: 2022-03-27 10:49:41
2022-03-27 10:50:11.772 Shelly Mqtt: MQTT message: shellies/shellyplug-s-C6E8BC/relay/0/energy 12633
2022-03-27 10:50:11.772 Shelly Mqtt: >>> Looking for device: shellyplug-s-C6E8BC-0-energy
2022-03-27 10:50:11.773 Shelly Mqtt: Device data: shellyplug-s-C6E8BC-0-energy value: 30.62;210.55 lastupdate: 2022-03-27 10:50:11
2022-03-27 10:50:11.773 Shelly Mqtt: Device update timedelta: 0
Code: Select all
if( updated > 10 ):
Domoticz.Debug( "update: " + str(unitname) + " value: " + str( sval ) + " lastupdate: " + str( Devices[iUnit].LastUpdate ) );
Devices[iUnit].Update(nValue=0,sValue=str(sval))
In plugin.py (line 551) there is an extra check to only process the new message if there is more then 10 seconds (?) passed since the previous message. But because the two messages are send right after each other, that check blocks the upload to Domoticz. Removing the check made it work, but was it the right fix?
One other minor issue i found is a rounding error in the calculation from watts per minute to watts per hour on line 527:
Code: Select all
mval2 = round((mval*0.017),4) # 10*Wh? or Watt-min??
Code: Select all
mval2 = round((mval/60.0),4) # Watt-min
-
- Posts: 11
- Joined: Saturday 23 April 2022 22:47
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
Finally I made it to get shelly plugin working on bullseye. Installing the newest beta version of domoticz did the trick.
Now im trying to set up the shelly plus 1 relays into domoticz, but it seems that they are quite different to shelly 1 open source.
Has anyone managed to get shelly plus1 running yet ?
Now im trying to set up the shelly plus 1 relays into domoticz, but it seems that they are quite different to shelly 1 open source.
Has anyone managed to get shelly plus1 running yet ?
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Re: Python Plugin: Shelly MQTT
Shelly Plus line uses a lot different topics and messages on MQTT.
First of all i have to subscribe every shellyID/online topic (without knowing the shellyid... super) to see new ShellyGen2 devices (no generic announce anymore) with wildcard: '+/online' its possible.
After that i have a clue about the device shellyID, which has to be used to send "Shelly.GetConfig command to ShellyID/rpc topic which gives me the information needed.
But for some reason when switching Relay status on the Shelly+ device own web page, it did not send _anything_ to the MQTT server... so it has to be polled to make sure about its status. (I hope it can be better, tried with firmware version 0.10, and it seems pretty unusable to me.)
Polling means= sending Shelly.GetStatus through ShellyID/rpc on every second ... looks like a step back.
I've tried to use HA Discovery plugin by bieniu with Domoticz MQTT Autodiscovery plugin:
https://github.com/bieniu/ha-shellies-discovery-gen2
After several hours of trying, i can run it and created devices on Domoticz, but absolutely do nothing: unable to sync status, or change it.
If anyone wants to try, this config has to be sent to Autodiscovery: (change shellyplus1-a8032abcf5f0 according your own device)
TOPIC:
homeassistant/switch/shellyplus1-a8032abcf5f0-0/config
PAYLOAD:
{"name": "Shelly Plus 1 Relay 0", "cmd_t": "~rpc", "pl_off": "{\"id\":1,\"src\":\"shellyplus1-a8032abcf5f0\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":false}}", "pl_on": "{\"id\":1,\"src\":\"shellyplus1-a8032abcf5f0\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":true}}", "stat_t": "~status/switch:0", "val_tpl": "{%if value_json.output%}on{%else%}off{%endif%}", "stat_off": "off", "stat_on": "on", "avty": [{"topic": "~online", "payload_available": "true", "payload_not_available": "false"}, {"topic": "~status/rpc", "value_template": "{%if value_json.result.mqtt.connected%}online{%else%}offline{%endif%}"}], "uniq_id": "shellyplus1-a8032abcf5f0-0", "qos": 0, "dev": {"cns": [["mac", "A8:03:2A:BC:F5:F0"]], "name": "Shelly Plus 1", "mdl": "Shelly Plus 1", "sw": "20220617-112651/0.10.3-g7c89a05", "mf": "Allterco Robotics", "cu": "http://shellyplus1-a8032abcf5f0.local/"}, "~": "shellyplus1-a8032abcf5f0/"}
First of all i have to subscribe every shellyID/online topic (without knowing the shellyid... super) to see new ShellyGen2 devices (no generic announce anymore) with wildcard: '+/online' its possible.
After that i have a clue about the device shellyID, which has to be used to send "Shelly.GetConfig command to ShellyID/rpc topic which gives me the information needed.
But for some reason when switching Relay status on the Shelly+ device own web page, it did not send _anything_ to the MQTT server... so it has to be polled to make sure about its status. (I hope it can be better, tried with firmware version 0.10, and it seems pretty unusable to me.)
Polling means= sending Shelly.GetStatus through ShellyID/rpc on every second ... looks like a step back.
I've tried to use HA Discovery plugin by bieniu with Domoticz MQTT Autodiscovery plugin:
https://github.com/bieniu/ha-shellies-discovery-gen2
After several hours of trying, i can run it and created devices on Domoticz, but absolutely do nothing: unable to sync status, or change it.
If anyone wants to try, this config has to be sent to Autodiscovery: (change shellyplus1-a8032abcf5f0 according your own device)
TOPIC:
homeassistant/switch/shellyplus1-a8032abcf5f0-0/config
PAYLOAD:
{"name": "Shelly Plus 1 Relay 0", "cmd_t": "~rpc", "pl_off": "{\"id\":1,\"src\":\"shellyplus1-a8032abcf5f0\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":false}}", "pl_on": "{\"id\":1,\"src\":\"shellyplus1-a8032abcf5f0\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":true}}", "stat_t": "~status/switch:0", "val_tpl": "{%if value_json.output%}on{%else%}off{%endif%}", "stat_off": "off", "stat_on": "on", "avty": [{"topic": "~online", "payload_available": "true", "payload_not_available": "false"}, {"topic": "~status/rpc", "value_template": "{%if value_json.result.mqtt.connected%}online{%else%}offline{%endif%}"}], "uniq_id": "shellyplus1-a8032abcf5f0-0", "qos": 0, "dev": {"cns": [["mac", "A8:03:2A:BC:F5:F0"]], "name": "Shelly Plus 1", "mdl": "Shelly Plus 1", "sw": "20220617-112651/0.10.3-g7c89a05", "mf": "Allterco Robotics", "cu": "http://shellyplus1-a8032abcf5f0.local/"}, "~": "shellyplus1-a8032abcf5f0/"}
-
- Posts: 216
- Joined: Saturday 10 November 2018 18:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Hungary
- Contact:
Re: Python Plugin: Shelly MQTT
I've found a discovery script on Allterco github.
It needs some modification, see the code below. After adding and executing it on the Shelly1 Plus "Scripts" menu, it will be discovered by Domoticz
"MQTT Auto Discovery Client Gateway" hardware, no plugin needed at all.
Next version of this script with Gen1 paths (relay/0) and autodiscovery capability uploaded to github.
It needs some modification, see the code below. After adding and executing it on the Shelly1 Plus "Scripts" menu, it will be discovered by Domoticz
"MQTT Auto Discovery Client Gateway" hardware, no plugin needed at all.
Code: Select all
/**
* @typedef {"switch" | "binary_sensor"} HADeviceType
* @typedef {"config"|"stat"|"cmd"} HATopicType
*/
let CONFIG = {
shelly_id: null,
shelly_mac: null,
shelly_fw_id: null,
shelly_model: null,
ha_mqtt_ad: "homeassistant",
device_name: "VIRTUAL_SWITCH",
payloads: {
on: "on",
off: "off"
}
};
Shelly.call(
"Shelly.GetDeviceInfo",
{},
function (result) {
CONFIG.shelly_id = result.id;
CONFIG.shelly_mac = result.mac;
CONFIG.shelly_fw_id = result.fw_id;
CONFIG.device_name = result.id;
CONFIG.shelly_model = result.model;
initMQTT();
}
)
/**
* @param {HADeviceType} hatype HA device type
* @returns {string} topic - ha_mqtt_auto_discovery_prefix/device_type/device_id/config
*/
function buildMQTTConfigTopic(hatype) {
return CONFIG.ha_mqtt_ad + "/" + hatype + "/" + CONFIG.shelly_id + "/config";
}
/**
* @param {HADeviceType} hatype HA device type
* @param {HATopicType} topic HA topic
* @returns {string}
*/
function buildMQTTStateCmdTopics(hatype, topic) {
let _t = topic || "";
if (_t.length) {
_t = "/" + _t
}
return CONFIG.shelly_id + "/" + hatype + _t;
}
/**
* @param {boolean} sw_state
*/
function switchActivate(sw_state) {
Shelly.call(
"Switch.Set",
{
id: 0,
on: sw_state
}
);
}
/**
* @param {string} topic
* @param {string} message
*/
function MQTTCmdListener(topic, message) {
let _sw_state = message === "on" ? true : false;
switchActivate(_sw_state);
}
Shelly.addStatusHandler(function (notification) {
if (notification.component !== "switch:0") return;
if (typeof notification.delta.output === "undefined") return;
let _state_str = notification.delta.output ? "on" : "off";
MQTT.publish(buildMQTTStateCmdTopics("switch", "state"), _state_str);
});
function initMQTT() {
MQTT.subscribe(buildMQTTStateCmdTopics("switch", "cmd"), MQTTCmdListener);
MQTT.publish(
buildMQTTConfigTopic("switch"),
JSON.stringify({
name: CONFIG.device_name,
"device": {
"name": CONFIG.device_name,
"ids": [CONFIG.device_name],
"mdl": CONFIG.shelly_model,
"mf": "Allterco",
"sw_version": CONFIG.shelly_fw_id
},
"unique_id": CONFIG.shelly_mac + ":" + CONFIG.device_name,
"pl_on": CONFIG.payloads.on,
"pl_off": CONFIG.payloads.off,
"cmd_t": "~/cmd",
"stat_t": "~/state",
"~": buildMQTTStateCmdTopics("switch")
}),
0,
true
)
}
Re: Python Plugin: Shelly MQTT
Hello there!
@lwolf, I saw your hard work put on the scripts to get work the Shelly Devices. Really appreciate it.
Almost all devices working fine, but new Shelly Pro 4PM doesn't. I tried to do some modifications inside https://github.com/enesbcs/Shelly_MQTT/ ... /plugin.py but without effect.
I know about new communication method on Shelly new gen devices.
What I need for my solution is get the data from Pro 4PM about Energy usage and cost calculation for each "switch id [0-3]". No need for now to control the relays.
Via MQTT I'm getting messages in this format:
Also you're able to get same data via curl request to the device:
Get SWITCH status ID0:Room1:
Get SWITCH status ID0:Room2:
LEGEND:
id: number, id of the Switch component instance
source: string, source of the last command, for example: init, WS_in, http, ...
output: boolean, true if the output channel is currently on, false otherwise
apower: number, last measured instantaneous power (in Watts) delivered to the attached load (shown if applicable)
voltage: number, last measured voltage in Volts (shown if applicable)
current: number, last measured current in Amperes (shown if applicable)
pf: number, last measured power factor (shown if applicable)
aenergy: JSON object, information about the energy counter (shown if applicable)
total: number, total energy consumed in Watt-hours
by_minute: array of numbers, energy consumption by minute (in Milliwatt-hours) for the last three minutes (the lower the index of the element in the array, the closer to the current moment the minute)
minute_ts: number, unix timestamp of the first second of the last minute (in UTC)
It will be very good if you could give some advice or even if you have time to look on this if it's possible to get power usage calculations and graphs over Domoticz.
Dave
@lwolf, I saw your hard work put on the scripts to get work the Shelly Devices. Really appreciate it.
Almost all devices working fine, but new Shelly Pro 4PM doesn't. I tried to do some modifications inside https://github.com/enesbcs/Shelly_MQTT/ ... /plugin.py but without effect.
I know about new communication method on Shelly new gen devices.
What I need for my solution is get the data from Pro 4PM about Energy usage and cost calculation for each "switch id [0-3]". No need for now to control the relays.
Via MQTT I'm getting messages in this format:
Code: Select all
pi@raspberrypi:~$ mosquitto_sub -h localhost -t "#" -v
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440039.21,"switch:0":{"id":0,"apower":31.9}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440040.20,"switch:0":{"id":0,"aenergy":{"by_minute":[597.673,587.033,586.901],"minute_ts":1656440039,"total":1484.366}}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440040.21,"switch:1":{"id":1,"aenergy":{"by_minute":[734.940,805.348,791.949],"minute_ts":1656440039,"total":7441.695}}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440040.33,"switch:2":{"id":2,"aenergy":{"by_minute":[769.093,773.691,782.623],"minute_ts":1656440039,"total":7162.738}}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440040.34,"switch:3":{"id":3,"aenergy":{"by_minute":[229.611,227.116,227.247],"minute_ts":1656440039,"total":1983.964}}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440041.19,"switch:0":{"id":0,"pf":0.57}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440041.19,"switch:1":{"id":1,"apower":40.0}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440041.19,"switch:1":{"id":1,"current":0.286}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440042.18,"switch:0":{"id":0,"pf":-0.70}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440042.18,"switch:1":{"id":1,"apower":44.7}}}
shellypro4pm-083af27cb654/events/rpc {"src":"shellypro4pm-083af27cb654","dst":"shellypro4pm-083af27cb654/events","method":"NotifyStatus","params":{"ts":1656440042.18,"switch:1":{"id":1,"current":0.310}}}
Get SWITCH status ID0:Room1:
Code: Select all
$ curl -X POST -d '{"id": 1, "method": "Switch.GetStatus", "params": {"id": 0}}' http://192.168.0.5/rpc
{"id":1,"src":"shellypro4pm-083af27cb654","result":{"id":0, "source":"init", "output":true, "apower":0.0, "voltage":238.0, "current":0.042, "pf":0.00, "aenergy":{"total":406.313,"by_minute":[0.000,0.000,0.000],"minute_ts":1656150937},"temperature":{"tC":57.2, "tF":135.0}}}
Code: Select all
$ curl -X POST -d '{"id": 1, "method": "Switch.GetStatus", "params": {"id": 1}}' http://192.168.0.5/rpc
{"id":1,"src":"shellypro4pm-083af27cb654","result":{"id":1, "source":"init", "output":true, "apower":44.6, "voltage":237.8, "current":0.314, "pf":-0.72, "aenergy":{"total":2844.338,"by_minute":[261.925,749.784,743.873],"minute_ts":1656150979},"temperature":{"tC":57.1, "tF":134.8}}}
id: number, id of the Switch component instance
source: string, source of the last command, for example: init, WS_in, http, ...
output: boolean, true if the output channel is currently on, false otherwise
apower: number, last measured instantaneous power (in Watts) delivered to the attached load (shown if applicable)
voltage: number, last measured voltage in Volts (shown if applicable)
current: number, last measured current in Amperes (shown if applicable)
pf: number, last measured power factor (shown if applicable)
aenergy: JSON object, information about the energy counter (shown if applicable)
total: number, total energy consumed in Watt-hours
by_minute: array of numbers, energy consumption by minute (in Milliwatt-hours) for the last three minutes (the lower the index of the element in the array, the closer to the current moment the minute)
minute_ts: number, unix timestamp of the first second of the last minute (in UTC)
It will be very good if you could give some advice or even if you have time to look on this if it's possible to get power usage calculations and graphs over Domoticz.
Dave
Re: Python Plugin: Shelly MQTT
dear all
I've a lot of shelly devices, works like a charm with Shelly MQTT.
When I now try add new devices (Shelly Bulb DUO, Shelly Bulb RGBW, Shelly 1PM), I get the error:
2022-07-04 08:45:44.244 Error: MQTT: 'onMessage' failed 'KeyError':'(-1,)'.
2022-07-04 08:45:44.244 Error: MQTT: Exception traceback:
2022-07-04 08:45:44.244 Error: MQTT: ----> Line 1351 in '/home/user/domoticz/plugins/Shelly_MQTT/plugin.py', function onMessage
2022-07-04 08:45:44.244 Error: MQTT: ----> Line 326 in '/home/user/domoticz/plugins/Shelly_MQTT/plugin.py', function onMessage
2022-07-04 08:45:44.244 Error: MQTT: ----> Line 176 in '/home/user/domoticz/plugins/Shelly_MQTT/mqtt.py', function onMessage
2022-07-04 08:45:44.244 Error: MQTT: ----> Line 1231 in '/home/user/domoticz/plugins/Shelly_MQTT/plugin.py', function onMQTTPublish
The old existing devices still working fine.
On MQTT Explorer the new devices also looks good.
Version: 2022.1
What could be the reason?
Thanks for your suggestions
Michi
I've a lot of shelly devices, works like a charm with Shelly MQTT.
When I now try add new devices (Shelly Bulb DUO, Shelly Bulb RGBW, Shelly 1PM), I get the error:
2022-07-04 08:45:44.244 Error: MQTT: 'onMessage' failed 'KeyError':'(-1,)'.
2022-07-04 08:45:44.244 Error: MQTT: Exception traceback:
2022-07-04 08:45:44.244 Error: MQTT: ----> Line 1351 in '/home/user/domoticz/plugins/Shelly_MQTT/plugin.py', function onMessage
2022-07-04 08:45:44.244 Error: MQTT: ----> Line 326 in '/home/user/domoticz/plugins/Shelly_MQTT/plugin.py', function onMessage
2022-07-04 08:45:44.244 Error: MQTT: ----> Line 176 in '/home/user/domoticz/plugins/Shelly_MQTT/mqtt.py', function onMessage
2022-07-04 08:45:44.244 Error: MQTT: ----> Line 1231 in '/home/user/domoticz/plugins/Shelly_MQTT/plugin.py', function onMQTTPublish
The old existing devices still working fine.
On MQTT Explorer the new devices also looks good.
Version: 2022.1
What could be the reason?
Thanks for your suggestions
Michi
Re: Python Plugin: Shelly MQTT
now it works
I think i did nothing,
is there a differece between "allow for 5 minutes" and always allow?
I think i did nothing,
is there a differece between "allow for 5 minutes" and always allow?
-
- Posts: 374
- Joined: Friday 23 May 2014 7:55
- Target OS: Linux
- Domoticz version: 2022.1
- Location: Saint Pierre de Jards
- Contact:
Re: Python Plugin: Shelly MQTT
I can’t get it added. What options have you selected on Mqtt Shelly side? Thank you. I’m running Domoticz stable 2022.1
Debian buster on NUC and three RPi with buster.
Re: Python Plugin: Shelly MQTT
I get my first Shelly Plus device. I think it is a good time now to look at Gen2 now for me, because there is not really any Active development on the Shelly_MQTT plugin.,.lwolf wrote: ↑Sunday 26 June 2022 17:43 I've found a discovery script on Allterco github.
It needs some modification, see the code below. After adding and executing it on the Shelly1 Plus "Scripts" menu, it will be discovered by Domoticz
"MQTT Auto Discovery Client Gateway" hardware, no plugin needed at all.
Next version of this script with Gen1 paths (relay/0) and autodiscovery capability uploaded to github.Code: Select all
/** * @typedef {"switch" | "binary_sensor"} HADeviceType * @typedef {"config"|"stat"|"cmd"} HATopicType */ let CONFIG = { shelly_id: null, shelly_mac: null, shelly_fw_id: null, shelly_model: null, ha_mqtt_ad: "homeassistant", device_name: "VIRTUAL_SWITCH", payloads: { on: "on", off: "off" } }; Shelly.call( "Shelly.GetDeviceInfo", {}, function (result) { CONFIG.shelly_id = result.id; CONFIG.shelly_mac = result.mac; CONFIG.shelly_fw_id = result.fw_id; CONFIG.device_name = result.id; CONFIG.shelly_model = result.model; initMQTT(); } ) /** * @param {HADeviceType} hatype HA device type * @returns {string} topic - ha_mqtt_auto_discovery_prefix/device_type/device_id/config */ function buildMQTTConfigTopic(hatype) { return CONFIG.ha_mqtt_ad + "/" + hatype + "/" + CONFIG.shelly_id + "/config"; } /** * @param {HADeviceType} hatype HA device type * @param {HATopicType} topic HA topic * @returns {string} */ function buildMQTTStateCmdTopics(hatype, topic) { let _t = topic || ""; if (_t.length) { _t = "/" + _t } return CONFIG.shelly_id + "/" + hatype + _t; } /** * @param {boolean} sw_state */ function switchActivate(sw_state) { Shelly.call( "Switch.Set", { id: 0, on: sw_state } ); } /** * @param {string} topic * @param {string} message */ function MQTTCmdListener(topic, message) { let _sw_state = message === "on" ? true : false; switchActivate(_sw_state); } Shelly.addStatusHandler(function (notification) { if (notification.component !== "switch:0") return; if (typeof notification.delta.output === "undefined") return; let _state_str = notification.delta.output ? "on" : "off"; MQTT.publish(buildMQTTStateCmdTopics("switch", "state"), _state_str); }); function initMQTT() { MQTT.subscribe(buildMQTTStateCmdTopics("switch", "cmd"), MQTTCmdListener); MQTT.publish( buildMQTTConfigTopic("switch"), JSON.stringify({ name: CONFIG.device_name, "device": { "name": CONFIG.device_name, "ids": [CONFIG.device_name], "mdl": CONFIG.shelly_model, "mf": "Allterco", "sw_version": CONFIG.shelly_fw_id }, "unique_id": CONFIG.shelly_mac + ":" + CONFIG.device_name, "pl_on": CONFIG.payloads.on, "pl_off": CONFIG.payloads.off, "cmd_t": "~/cmd", "stat_t": "~/state", "~": buildMQTTStateCmdTopics("switch") }), 0, true ) }
But.. I try to pre-configure my Domoticz now, but some basic questions.
- The plugin "MQTT AutoDiscover Client Gateway with LAN Interface". Must I set this up to the Shelly Plus later on or to the Mosquitto broker?
- Do I need to do modifications in the Script before I execute this on the Shelly Plus. I saw these items in the script:
shelly_id: null,
shelly_mac: null,
shelly_fw_id: null,
shelly_model: null, setup
- Will this method work aside the current Shelly_MQTT plugin? This because I still have allot of Shelly devices depended on the old plugin.
Thanks!
-
- Posts: 177
- Joined: Sunday 13 November 2016 10:43
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Germany
- Contact:
Re: Python Plugin: Shelly MQTT
Does anybody know, if a shelly pro 1 works with this plugin. Thanks.
Re: Python Plugin: Shelly MQTT
The discovery scripts with Shelly Plus 1 worked great.. First try. and it was simple to setup. Also I like that I can control the Shellies by cloud and Domoticz MQTT, I always saw that as a flaw with the older versions.
But, one question though.. Is this script only for the Shelly1 plus? There are also new devices besides the ShellyPlus 1 like the ShellyPlus1PM and the newly released Shelly Plus 2PM. is it suspected that this script also are usable with other devices then Shelly1plus.. because on Github I don't see anything else then the ShellyPlus1
But, one question though.. Is this script only for the Shelly1 plus? There are also new devices besides the ShellyPlus 1 like the ShellyPlus1PM and the newly released Shelly Plus 2PM. is it suspected that this script also are usable with other devices then Shelly1plus.. because on Github I don't see anything else then the ShellyPlus1
-
- Posts: 97
- Joined: Saturday 14 March 2020 13:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
I have a lot of shelly devices of 1st generation integrated with the "Shelly MQTT" plugin. Now I have my first Shelly Plus device of the 2nd generation and want to start activating "MQTT Auto Discovery Client Gateway". Can both plugins work in parallel? If yes: Will all existing devices be discoverd again so they are doubled?
-
- Posts: 31
- Joined: Sunday 23 November 2014 16:18
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: France
- Contact:
Re: Python Plugin: Shelly MQTT
Hi all,
Thanks to iwolf, I use this plugin for my Shelly devices since 1 or 2 years.
Unfortunately, some new Shelly devices like the brand new Shelly Plus H&T and the Shelly Pro 4PM are not working.
It looks like the MQTT frames have changed :
examples :
Old Shelly 1PM :
New Shelly Pls H&T :
Do you think that you will update your script for the new Shelly devices ?
Regards,
Manu
Thanks to iwolf, I use this plugin for my Shelly devices since 1 or 2 years.
Unfortunately, some new Shelly devices like the brand new Shelly Plus H&T and the Shelly Pro 4PM are not working.
It looks like the MQTT frames have changed :
examples :
Old Shelly 1PM :
Code: Select all
hellies/shelly1pm-8CAAB5060882/relay/0 off
shellies/shelly1pm-8CAAB5060882/input/0 0
shellies/shelly1pm-8CAAB5060882/relay/0/power 0.00
shellies/shelly1pm-8CAAB5060882/relay/0/energy 1165
shellies/shelly1pm-8CAAB5060882/temperature 34.79
shellies/shelly1pm-8CAAB5060882/temperature_f 94.63
Code: Select all
shellyplusht-c049ef88de78/status/sys {"mac":"C049EF88DE78","restart_required":false,"time":null,"unixtime":null,"uptime":1,"ram_size":235564,"ram_free":164032,"fs_size":458752,"fs_free":172032,"cfg_rev":14,"kvs_rev":0,"webhook_rev":0,"available_updates":{},"wakeup_reason":{"boot":"software_restart","cause":"undefined"},"wakeup_period":43200}
shellyplusht-c049ef88de78/status/temperature:0 {"id": 0,"tC":28.6, "tF":83.4}
Regards,
Manu
Rapberry PI B+ (RaspBian), RFXtrx433E USB 433.92MHz Transceiver, AEON LABS Controler Z-Wave, Aeon Labs Z-Stick S2, Everspring ST814 Temperature Sensor, Everspring SF812 Smoke Detector, 2x Fibaro Wallplug, Aeon Zwave Miniremote , Xbee Teleinfo USB
-
- Posts: 97
- Joined: Saturday 14 March 2020 13:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: Shelly MQTT
Hi manuloup,
I (as most likely everyone using Shellies of the 2nd generation) have the same Problem. In my posting above yours I was asking if the general plugin for MQTT devices could be used. I als got no reply. It seems as if this only works if you include a certain script into the Shelly device and this is individual for every kind of device .
So I do hope that anyone here can help us how to proceed with 2nd generation Shellies.
I (as most likely everyone using Shellies of the 2nd generation) have the same Problem. In my posting above yours I was asking if the general plugin for MQTT devices could be used. I als got no reply. It seems as if this only works if you include a certain script into the Shelly device and this is individual for every kind of device .
So I do hope that anyone here can help us how to proceed with 2nd generation Shellies.
Who is online
Users browsing this forum: No registered users and 1 guest