geeks-r-us / mqtt-panel

Simple Grafana panel that allows to communicate with a mqtt server
Apache License 2.0
54 stars 11 forks source link

Switch with ON/OFF not working - text and button OK #23

Closed alexhk closed 3 years ago

alexhk commented 3 years ago

Hi @geeks-r-us , I've been looking forward to using your plugin for a long time and just now finally found the time.

I don't have any MQTT device where I could test with true and false, but I am trying to create a switch with ON and OFFvalues which doesn't seem to work. However, when I setup a panel next to it with TEXT, it does indeed show ON/OFF is received without problems from mosquitto, also I can use a Button which also works well so as a workaround I can use Text with a additional button.

2021-01-05_12h56_36

And since Github now supports video, here's a 84kb MP4.

https://user-images.githubusercontent.com/1495412/103644030-f8ce0d80-4f55-11eb-89c9-5ba86a12fb02.mp4

Left (text) reflects changes when I switch externally. Right doesn't show anything and flipping the switch seems to send a message to mosquitto but nothing happens. I suspect the ON/OFF strings somehow don't work?

They are setup in the same way:

2021-01-05_12h30_01

2021-01-05_12h34_22

Buttons work but I am not sure why there is a subscribe topic in the settings:

2021-01-05_12h54_29

-- // --

I also noticed there are lots of different mqttjs_dd0be95a clients connected. And to make sure it's not one of my browser plugins on Firefox, I tried on a virgin Edge browser with the same result.

Here's a log where I switch externally and the result is shown in the Text type, and once I try to switch with the switch type panel.

2021-01-05T12:36:04: Received PUBLISH from Sonoff-ZbBridge-1 (d0, q0, r0, m0, 'cmnd/Gosund-8/power', ... (6 bytes))
2021-01-05T12:36:04: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'cmnd/Gosund-8/power', ... (6 bytes))
2021-01-05T12:36:04: Sending PUBLISH to Gosund-8 (d0, q0, r0, m0, 'cmnd/Gosund-8/power', ... (6 bytes))
2021-01-05T12:36:04: Received PUBLISH from Gosund-8 (d0, q0, r0, m0, 'stat/Gosund-8/RESULT', ... (14 bytes))
2021-01-05T12:36:04: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'stat/Gosund-8/RESULT', ... (14 bytes))
2021-01-05T12:36:04: Received PUBLISH from Gosund-8 (d0, q0, r1, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_77f91985 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_3a69a90a (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_f8491201 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_78994aaf (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_dd0be95a (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_9d2e6fe4 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_4e72cb2e (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_0b16046f (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_c146d288 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_4fba5745 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_a3086c4b (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_aeb8262a (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to mqttjs_effddb66 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:04: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (2 bytes))
2021-01-05T12:36:14: Received PUBLISH from Sonoff-ZbBridge-1 (d0, q0, r0, m0, 'cmnd/Gosund-8/power', ... (6 bytes))
2021-01-05T12:36:14: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'cmnd/Gosund-8/power', ... (6 bytes))
2021-01-05T12:36:14: Sending PUBLISH to Gosund-8 (d0, q0, r0, m0, 'cmnd/Gosund-8/power', ... (6 bytes))
2021-01-05T12:36:14: Received PUBLISH from Gosund-8 (d0, q0, r0, m0, 'stat/Gosund-8/RESULT', ... (15 bytes))
2021-01-05T12:36:14: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'stat/Gosund-8/RESULT', ... (15 bytes))
2021-01-05T12:36:14: Received PUBLISH from Gosund-8 (d0, q0, r1, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_77f91985 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_3a69a90a (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_f8491201 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_78994aaf (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_dd0be95a (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_9d2e6fe4 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_4e72cb2e (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_0b16046f (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_c146d288 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_4fba5745 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_a3086c4b (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_aeb8262a (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to mqttjs_effddb66 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:14: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Received PUBLISH from mqttjs_0b16046f (d0, q0, r0, m0, 'cmnd/Gosund-8/POWER', ... (9 bytes))
2021-01-05T12:36:17: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'cmnd/Gosund-8/POWER', ... (9 bytes))
2021-01-05T12:36:17: Sending PUBLISH to Gosund-8 (d0, q0, r0, m0, 'cmnd/Gosund-8/POWER', ... (9 bytes))
2021-01-05T12:36:17: Received PUBLISH from Gosund-8 (d0, q0, r0, m0, 'stat/Gosund-8/RESULT', ... (15 bytes))
2021-01-05T12:36:17: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'stat/Gosund-8/RESULT', ... (15 bytes))
2021-01-05T12:36:17: Received PUBLISH from Gosund-8 (d0, q0, r1, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_77f91985 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_3a69a90a (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_f8491201 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_78994aaf (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_dd0be95a (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_9d2e6fe4 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_4e72cb2e (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_0b16046f (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_c146d288 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_4fba5745 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_a3086c4b (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_aeb8262a (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to mqttjs_effddb66 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:17: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'stat/Gosund-8/POWER', ... (3 bytes))
2021-01-05T12:36:18: Received PUBLISH from Gosund-8 (d0, q0, r0, m0, 'tele/Gosund-8/STATE', ... (297 bytes))
2021-01-05T12:36:18: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'tele/Gosund-8/STATE', ... (297 bytes))
2021-01-05T12:36:18: Received PUBLISH from Gosund-8 (d0, q0, r0, m0, 'tele/Gosund-8/SENSOR', ... (226 bytes))
2021-01-05T12:36:18: Sending PUBLISH to iobroker_mqtt_0 (d0, q0, r0, m0, 'tele/Gosund-8/SENSOR', ... (226 bytes))
geeks-r-us commented 3 years ago

Thx for this very detailed bug report. I found the issue. I was introduced by the parsing of variable which worked fine for true and false but not for other strings like ON and OFF.
I'll try to release a fixed version the next days.

alexhk commented 3 years ago

Thanks for the quick update. It works, but please note only if I use 'ON' and 'OFF', not if it's lowercase 'on' or 'off' etc.

geeks-r-us commented 3 years ago

Do you have an example where this would be useful? The casing of the values shouldn't change during the usage?

alexhk commented 3 years ago

It was more a FYI and a surprise to myself that it is case sensitive.

Hmm, examples. I am not the MQTT specialist, but at least for checking the result of the subscription I would lowercase both the received value and the entered value first before the comparison and setting the switch state in the javascript. So if we get back "On", "ON" or "on" it's all the same. I am using a variety of Tasmota devices (stock and modified firmwares), they are configurable, sometimes it could be ON, sometimes On. A long time ago (early versions) it was also true/false if I remember correctly. But on the other hand, don't bother wasting your time!

Having a Go MQTT running in the backend would be much more useful :)

Again, thanks for providing this useful plugin!