Hey Folks,
For some reason sending battery level to a switch or selector switch in Domoticz via MQTT does not work.
In the below example (link) I am able to control the device but the battery level is simply ignored.
viewtopic.php?f=68&t=23607&start=20#p188171
I am sending it as: msg.payload.Battery
Any help would be appreciated, with Zigbee2MQTT it will be necessary for many devices to have battery levels via MQTT.
Cheers
MQTT Battery Level Not Working
Moderator: leecollings
-
ben53252642
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
MQTT Battery Level Not Working
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
-
ben53252642
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: MQTT Battery Level Not Working
Anyone?
I've spent about 5 hours trying to get a battery level entered into a device via MQTT without success, it IS possible with JSON.
Seems to me MQTT is lagging behind the JSON interface.
I've spent about 5 hours trying to get a battery level entered into a device via MQTT without success, it IS possible with JSON.
Seems to me MQTT is lagging behind the JSON interface.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
- jvdz
- Posts: 2445
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: MQTT Battery Level Not Working
Replied to your github post, but I am pretty sure the "switchlight" mqtt command doesn't interpret the battery variable and you need to change it to "udevice" command as shown in my answer in github.
Jos
Jos
-
ben53252642
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: MQTT Battery Level Not Working
Problem solved thanks to jvdz example.
https://github.com/domoticz/domoticz/issues/2618
What to send via MQTT to Domoticz (in this case to a selector switch).
Tested example in Node-Red for Xiaomi WXKG01LM Button
Selector switch levels:
10 single
20 double
30 long
https://github.com/domoticz/domoticz/issues/2618
What to send via MQTT to Domoticz (in this case to a selector switch).
Code: Select all
msg.payload.idx = 1213 ;
msg.payload.nvalue = 2 ;
msg.payload.level = level;
msg.payload.svalue = level.toString();
msg.payload.Battery = batt;
Code: Select all
[{"id":"2419ca7a.aa80e6","type":"mqtt in","z":"f962b96d.7044c8","name":"zigbee2mqtt/out","topic":"zigbee2mqtt/xiaomitestbutton","qos":"2","broker":"7e7eab95.c38d54","x":340,"y":440,"wires":[["9c57d2e1.13bc1"]]},{"id":"9c57d2e1.13bc1","type":"json","z":"f962b96d.7044c8","name":"","property":"payload","action":"","pretty":false,"x":490,"y":440,"wires":[["b3d3900.fbcbf7"]]},{"id":"26f6b6a1.ff999a","type":"mqtt out","z":"f962b96d.7044c8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"5e06ebd0.e4e9d4","x":790,"y":440,"wires":[]},{"id":"b3d3900.fbcbf7","type":"function","z":"f962b96d.7044c8","name":"Format Data","func":"// Xiaomi WXKG01LM Button\nvar click = msg.payload.click.toString();\nvar batt = Math.round(msg.payload.battery);\nmsg.payload.idx = 1217 ;\nif(click == 'single') {\n var level = 10\n} else if (click == 'double') {\n var level = 20\n// Action holding button before release (not used)\n//} else if (click == 'long') {\n// var level = 20\n} else if (click == 'long_release') {\n var level = 30\n}\nmsg.payload.nvalue = 2 ;\nmsg.payload.level = level;\nmsg.payload.svalue = level.toString();\nmsg.payload.Battery = batt;\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":440,"wires":[["26f6b6a1.ff999a","5fa57f09.6d0fe"]]},{"id":"7e7eab95.c38d54","type":"mqtt-broker","z":"","name":"Zigbee","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"domoticz/bridge/state","birthQos":"0","birthPayload":"online","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"5e06ebd0.e4e9d4","type":"mqtt-broker","z":"","name":"Domoticz","broker":"192.168.0.5","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]10 single
20 double
30 long
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Re: MQTT Battery Level Not Working
Tnx.
It works for me too now.
It's strange that "Battery" seems to be case-sensitive, everything else is lowercase.
It's strange that "Battery" seems to be case-sensitive, everything else is lowercase.
- sincze
- Posts: 1302
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: MQTT Battery Level Not Working
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Who is online
Users browsing this forum: No registered users and 1 guest