Closed davidw3591 closed 2 years ago
It's completny normal behavior of MQTT entities restored from registry after HA start. Correct state will show up after first state update on topics shellypro2-30c6f784b9b8/status/switch:0
and shellypro2-30c6f784b9b8/status/switch:1
. The device sends those topics every minute.
Hi, I've been watching the MQTT topics with MQTT.fx and saw that the Pro2 is not sending periodical updates. The Pro4PM is updating every minute.
The Pro2 is only updating when the light is toggled.
Any thoughts on how to turn on periodical updates every minute on the Pro2? Can't find related settings in the Shelly UI.
Did you check MQTT configuration?
Yes both are enabled. As far as I can tell the configs off both Pro4PM and Pro2 are identical.
I use Pro 1PM and Plus 1PM at home and both send state every minute. Tomorrow I will check Pro 2.
Yes, you're right, Pro 2 and Pro 1 don't send switch state every minute. I think only devices with power meterig do this. There is nothing I can do about it, we need to ask Shelly support to change this behavior in the next firmware version.
Thanks for checking. I've posted this to the Shelly FB support group.
I've put togheter a small script that runs on the Pro2 that updates the status of the switch topics every minute. Works fine for now, hopefully Shelly will make some adjustments to the firmware in the future.
// Based on: https://github.com/ALLTERCO/shelly-script-examples/blob/main/mqtt-announce-control.js
// The Shelly Gen2 non-PM devices don't send periodic updates to the switch topics.
// Causing an unknown state in HomeAssistant after a reboot until the output is operated.
// This scripts updates to the switch topics every minute as a workaround.
let CONFIG = {
device_id: "",
device_mac: "",
device_model: "",
fw_ver: "",
topic_prefix: "",
wifi_ip: "",
};
// Read MQTT topic prefix
Shelly.call("MQTT.GetConfig", null, function (config) {
CONFIG.topic_prefix = config.topic_prefix;
});
// Announce function to send MQTT update for the switches
function updateSwitchTopics() {
// Switch ID 0
Shelly.call("Switch.GetStatus", { id: 0 }, function (status) {
MQTT.publish(CONFIG.topic_prefix + "/status/switch:0", JSON.stringify(status));
//print(CONFIG.topic_prefix + "/status/switch:0", JSON.stringify(status));
});
// Switch ID 1
Shelly.call("Switch.GetStatus", { id: 1 }, function (status) {
MQTT.publish(CONFIG.topic_prefix + "/status/switch:1", JSON.stringify(status));
//print(CONFIG.topic_prefix + "/status/switch:1", JSON.stringify(status));
});
}
// Publih every minute (60000ms)
let updateTimer = Timer.set(
60000,
true,
updateSwitchTopics
);
Describe the bug I have a Shelly Pro4PM and a Shelly Pro2 in my house. After a HomeAssistant reboot the Shelly Pro2 entities are unknown while the Pro4PM are updated.
The light entities of the Pro2 have the state 'unavailable' under /developer-tools/state. But they are available.
When I click the "off lightning bolt" in HASS, it does nothing. When clicking the "on lightning bolt" the light turns on and HASS shows a toggle button instead of the lightning bolts. Then everything works normal.
When turning the lights on in the Shelly device UI, the lightning bolts also changes to a toggle button with the right feedback.
Expected behavior Shelly Pro2 entity state gets updated after Shelly Discovery script has run.
Versions:
Shellies Discovery GEN2 automation:
Debug log: hass_log.txt