setting battery level with API/JSON and/or MQTT Topic is solved

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
edgarhildering
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

Post by edgarhildering »

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&param=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
User avatar
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

Post by waltervl »

Did you already try to add something as below in the update device command?

Code: Select all

 "Battery" : 100, "RSSI" : 12,
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?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
edgarhildering
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

Post by edgarhildering »

after sending:

Code: Select all

mosquitto_pub -h localhost -p 1883 -t "domoticz/in" -m "{\"idx\": 1402, \"BatteryLevel\":75}"
I get this response

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})
open for MQTT-suggestions!
RaspberryPi running Domoticz 2023.2
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
User avatar
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

Post by waltervl »

Try using

Code: Select all

mosquitto_pub -h localhost -p 1883 -t "domoticz/in" -m "{\"idx\": 1402, \"Battery\":75}"
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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
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

Post by FireWizard »

Hello @edgarhildering,

It is not "BatteryLevel", but just "Battery".

Try this one.

Regards
edgarhildering
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

Post by edgarhildering »

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})
That doesn't look better... I also tried:

Code: Select all

http://ge-domoticz/json.htm?type=command&param=udevice&idx=1402&batterylevel=75
http://ge-domoticz/json.htm?type=command&param=udevice&idx=1402&battery=75
respons in both cases:

Code: Select all

{
	"status" : "ERR"
}
RaspberryPi running Domoticz 2023.2
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
User avatar
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

Post by waltervl »

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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
edgarhildering
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

Post by edgarhildering »

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
RaspberryPi running Domoticz 2023.2
PIRs + lightswitches
thermometers + heating control
hygrometers + dehumifiers
TUYA switches
User avatar
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

Post by waltervl »

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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest