setting battery level with API/JSON and/or MQTT Topic is solved
Moderators: leecollings, remb0
-
- Posts: 31
- Joined: Thursday 11 June 2015 22:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Contact:
setting battery level with API/JSON and/or MQTT
My request is simple: I would like to set the battery level with an MQTT message. Example:
topic= Domoticz/in
message = { "idx" : <idx>, "BatteryLevel" : <blevel> }
with 0 <= blevel <= 100
a comparable JSON approach would be:
/json.htm?type=command¶m=udevice&idx=IDX&batterylevel=<BATTERLYLEVEL>
Furthermore it is not desirable that updates of a device that do not have battery level data force the battery level to 255. Initially this is fine, but don't touch it if there is no data.
thanks in advance, --Edgar
topic= Domoticz/in
message = { "idx" : <idx>, "BatteryLevel" : <blevel> }
with 0 <= blevel <= 100
a comparable JSON approach would be:
/json.htm?type=command¶m=udevice&idx=IDX&batterylevel=<BATTERLYLEVEL>
Furthermore it is not desirable that updates of a device that do not have battery level data force the battery level to 255. Initially this is fine, but don't touch it if there is no data.
thanks in advance, --Edgar
RaspberryPi running Domoticz 2023.2
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: setting battery level with API/JSON and/or MQTT
Did you already try to add something as below in the update device command?
see also
https://www.domoticz.com/wiki/MQTT#MQTT_to_Domoticz
API commands are already there: https://www.domoticz.com/wiki/Domoticz_ ... y_level.29
So what exactly are you missing?
Code: Select all
"Battery" : 100, "RSSI" : 12,
https://www.domoticz.com/wiki/MQTT#MQTT_to_Domoticz
API commands are already there: https://www.domoticz.com/wiki/Domoticz_ ... y_level.29
So what exactly are you missing?
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: 31
- Joined: Thursday 11 June 2015 22:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Contact:
Re: setting battery level with API/JSON and/or MQTT
after sending:
I get this response
open for MQTT-suggestions!
Code: Select all
mosquitto_pub -h localhost -p 1883 -t "domoticz/in" -m "{\"idx\": 1402, \"BatteryLevel\":75}"
Code: Select all
2023-10-03 18:43:57.259 Error: ge-MQTT: Invalid/Unhandled data received! (Topic: domoticz/in, Message: {"idx": 1402, "BatteryLevel":75})
RaspberryPi running Domoticz 2023.2
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: setting battery level with API/JSON and/or MQTT
Try using
But as like the API Battery and RSSI are optional parameters for an device update command you perhaps have to add a current nvalue or svalue to it.
Code: Select all
mosquitto_pub -h localhost -p 1883 -t "domoticz/in" -m "{\"idx\": 1402, \"Battery\":75}"
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
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: setting battery level with API/JSON and/or MQTT
Hello @edgarhildering,
It is not "BatteryLevel", but just "Battery".
Try this one.
Regards
It is not "BatteryLevel", but just "Battery".
Try this one.
Regards
-
- Posts: 31
- Joined: Thursday 11 June 2015 22:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Contact:
Re: setting battery level with API/JSON and/or MQTT
Code: Select all
2023-10-03 19:27:35.669 Error: ge-MQTT: Invalid/Unhandled data received! (Topic: domoticz/in, Message: {"idx": 1402, "Battery":75})
Code: Select all
http://ge-domoticz/json.htm?type=command¶m=udevice&idx=1402&batterylevel=75
http://ge-domoticz/json.htm?type=command¶m=udevice&idx=1402&battery=75
Code: Select all
{
"status" : "ERR"
}
RaspberryPi running Domoticz 2023.2
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: setting battery level with API/JSON and/or MQTT
As mentioned before, like on the api Battery is an additional parameter so you cannot set the battery level only. You have to update the sensor with a valid value AND update the battery level.
So while updating your sensor, add the battery parameter to the statement where you normally update your sensor value with. And "BatteryLevel" will never work so forget it please.
So while updating your sensor, add the battery parameter to the statement where you normally update your sensor value with. And "BatteryLevel" will never work so forget it please.
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: 31
- Joined: Thursday 11 June 2015 22:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Contact:
Re: setting battery level with API/JSON and/or MQTT
Hi @waltervl, thanks for the explanation. This works like charm when sending a message with MQTT with all other parameters present.
Then there is no need to add this feature.
I must have overlooked the remark on additional parameters. Maybe the header of that section in the wiki needs 'some improvement'. Furthermore, some explanation of the term 'the above commands' is not an unnecessary luxury, as is an example of an update of a sensor. I'll see what I can do about that.
Thanks & greetings, --Edgar
Then there is no need to add this feature.
I must have overlooked the remark on additional parameters. Maybe the header of that section in the wiki needs 'some improvement'. Furthermore, some explanation of the term 'the above commands' is not an unnecessary luxury, as is an example of an update of a sensor. I'll see what I can do about that.
Thanks & greetings, --Edgar
RaspberryPi running Domoticz 2023.2
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: setting battery level with API/JSON and/or MQTT
Glad it works, I will add it too to the mqtt wiki.
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
Who is online
Users browsing this forum: No registered users and 1 guest