Hi,
There is a temperature sensor. I would like to update their temperature value and battery level with separate MQTT commands. Is it possible?
When I type: {"idx": 123, "Battery": 50} an error appears.
When I enter the temperature without battery, the battery level disappears.
How to update only one value without erase other?
Tom
MQTT - battery percentage level without themperature update?
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: MQTT - battery percentage level without themperature update?
The only way to update a batteryLevel of a temperature sensor (besides poking directly in the database) is with the combined MQTT or JSON command.
Luckily dzVents can help here.
if you send one of these MQTT messages to domoticz/in
Code: Select all
{"command":"customevent","event":"separateValues","data": "{'"'idx'"':29, '"'temperature'"':25 }" } # for temperature only
{"command":"customevent","event":"separateValues","data": "{'"'idx'"':29, '"'batteryLevel'"':29 }" } # for batteryLevel only
Code: Select all
local scriptVar = 'separateValues'
return
{
on =
{
customEvents =
{
scriptVar,
},
httpResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
marker = scriptVar,
},
execute = function(dz, item)
lodash = dz.utils._
local function sendURL(idx, temperature, batteryLevel)
local url = dz.settings['Domoticz url'] ..
'/json.htm?type=command¶m=udevice&idx=' .. idx ..
'&nvalue=0&svalue=' .. temperature ..
'&battery=' .. batteryLevel
dz.openURL(
{
url = url,
callback = scriptVar,
})
end
if item.isCustomEvent then
local mqtt = item.data
local batteryLevel = mqtt.batteryLevel or dz.devices(mqtt.idx).batteryLevel or 255
local temperature = mqtt.temperature or dz.devices(mqtt.idx).temperature
sendURL(mqtt.idx, temperature, batteryLevel)
elseif not item.ok then
dz.log('Problem with sending the temperature / batteryLevel' .. lodash.str(item), dz.LOG_ERROR)
else
dz.log('All ok \n' .. lodash.str(item.data) .. '\n', dz.LOG_DEBUG)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 31
- Joined: Saturday 07 July 2018 22:08
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Poland
- Contact:
Re: MQTT - battery percentage level without themperature update?
Ok, thank You again. I`ll test it.
-
- Posts: 153
- Joined: Wednesday 02 October 2019 11:47
- Target OS: Linux
- Domoticz version: 2023.1
- Location: DE / BY / LT
- Contact:
Re: MQTT - battery percentage level without themperature update?
Hi,
since you're working already with MQTT, this is how I update the battery value with node-red. The sample is from a flood sensor. the "svalue" : "0" is required, otherwise it won't work.
since you're working already with MQTT, this is how I update the battery value with node-red. The sample is from a flood sensor. the "svalue" : "0" is required, otherwise it won't work.
Code: Select all
msg.payload = {
"idx" :290,
"svalue" : "0",
"Battery" :parseInt(msg.payload)
}
return msg;
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: MQTT - battery percentage level without themperature update?
if you send svalue 0 to a temperature sensor it will show a temperature of 0 degrees.thomasbaetge wrote: ↑Wednesday 22 April 2020 13:29 since you're working already with MQTT, this is how I update the battery value with node-red. The sample is from a flood sensor. the "svalue" : "0" is required, otherwise it won't work.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 153
- Joined: Wednesday 02 October 2019 11:47
- Target OS: Linux
- Domoticz version: 2023.1
- Location: DE / BY / LT
- Contact:
Re: MQTT - battery percentage level without themperature update?
Right...but I assume NVALUE=0 will do the trick too.
The point is, that just sending the Battery value doesn't seem to work.
The point is, that just sending the Battery value doesn't seem to work.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: MQTT - battery percentage level without themperature update?
That's why I proposed the dzVents approach which will preserve the current value for temperature when updating the battery-value and preserving the battery-value when updating the temperature.thomasbaetge wrote: ↑Wednesday 22 April 2020 17:28 Right...but I assume NVALUE=0 will do the trick too.
The point is, that just sending the Battery value doesn't seem to work.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: MQTT - battery percentage level without themperature update?
What I do is when a device only reports its battery level I store it in Node-Red and then when a temperature level is reported I also send the previously received battery reading (or latest if its available).
You can code a rule if you want to only send the battery reading with temperature if the battery reading was received within the last 2 days (so that its reasonably current, obviously depending on the power consumption of the device).
You can code a rule if you want to only send the battery reading with temperature if the battery reading was received within the last 2 days (so that its reasonably current, obviously depending on the power consumption of the device).
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Who is online
Users browsing this forum: No registered users and 1 guest