Extract value from mqtt report Topic is solved
Moderators: leecollings, remb0
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Extract value from mqtt report
Greetings!)
I want to ask about the output of data on mqtt with domoticz
There is a clock with the ability to display information on mqtt, but I do not know how to choose the correct format for the mqtt topic name ...
installed the mosquitto broker and by subscription to all the topics in PuTTY
mosquitto_sub -h 192.168.1.2 -v -t "#"
I see info from all sensors in the form
domoticz / out {
Battery: 255,
RSSI: 12,
"Description": "",
"Dtype": "Temp",
"Id": "24351",
"Idx": 102,
"Name": "Street temperature",
"Nvalue": 0,
"Stype": "LaCrosse TX3",
"Svalue1": "-3.2",
"Unit": 31
}
The clock is connected to the same network with domoticz, and if in the clock settings I indicate the domoticz / out topic on the clock I see all this info ...
And how to draw only Street temperature -3.2 .....?
Probably need a script that will convert these values for output on mqtt
I want to ask about the output of data on mqtt with domoticz
There is a clock with the ability to display information on mqtt, but I do not know how to choose the correct format for the mqtt topic name ...
installed the mosquitto broker and by subscription to all the topics in PuTTY
mosquitto_sub -h 192.168.1.2 -v -t "#"
I see info from all sensors in the form
domoticz / out {
Battery: 255,
RSSI: 12,
"Description": "",
"Dtype": "Temp",
"Id": "24351",
"Idx": 102,
"Name": "Street temperature",
"Nvalue": 0,
"Stype": "LaCrosse TX3",
"Svalue1": "-3.2",
"Unit": 31
}
The clock is connected to the same network with domoticz, and if in the clock settings I indicate the domoticz / out topic on the clock I see all this info ...
And how to draw only Street temperature -3.2 .....?
Probably need a script that will convert these values for output on mqtt
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Extract value from mqtt report
See the attached dzVents scriptamplituda wrote: ↑Saturday 16 February 2019 6:39 Greetings!)
I want to ask about the output of data on mqtt with domoticz
There is a clock with the ability to display information on mqtt, but I do not know how to choose the correct format for the mqtt topic name ...
And how to draw only Street temperature -3.2 .....?
Probably need a script that will convert these values for output on mqtt
Code: Select all
-- mqqt
return {
on = { devices = { 24 }}, -- idx of your temperature sensor
execute = function(dz, item)
local function osExecute(cmd)
local fileHandle = assert(io.popen(cmd, 'r'))
assert(fileHandle:read('*a'))
fileHandle:close()
end
local mqttCommand = "mosquitto_pub -t domoticz/out -m '" .. item.name ..": " .. dz.utils.round(item.temperature,2) .. "'"
osExecute(mqttCommand)
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
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Re: Extract value from mqtt report
Thank you for responding to my request)
I indicated this data in the script, now I see the following in the log:
Code: Select all
Status: dzVents: Info: Handling events for: "Street temperature", value: "0.9"
Status: dzVents: Info: ------ Start internal script: MQTT: Device: "Street temperature (RFLink)", Index: 102
Status: dzVents: Info: ------ Finished MQTT
please tell me more)
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Extract value from mqtt report
If you set the clock to listen to another topic, for instance clock/temperature and change the script to the attached, you should see something.
You can check on the command line with
Code: Select all
mosquitto_sub -F "%U - %t - %p" -v -t '#'
Code: Select all
-- mqqt
return {
on = { devices = { 24 }}, -- idx of your temperature command
execute = function(dz, item)
local function osExecute(cmd)
dz.log("Executing command: " .. cmd,dz.LOG_FORCE)
local fileHandle = assert(io.popen(cmd, 'r'))
assert(fileHandle:read('*a'))
fileHandle:close()
end
local clockTopic = "clock/temperature"
local mqttCommand = "mosquitto_pub -t " .. clockTopic .. " -m '" .. item.name ..": " .. dz.utils.round(item.temperature,2) .. "'"
osExecute(mqttCommand)
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
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Re: Extract value from mqtt report
Yes, with the new script and the title of the clock / temperature topic, everything works as it should! Thank you very much for your help! You can close the topic - the problem is solved!
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Extract value from mqtt report
You have to close it yourself as you started the topic.
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
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Re: Extract value from mqtt report
Hi waaren, and you will not tell me how to add more sensors?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Extract value from mqtt report
Is this a question or a statement ?
I am not aware of a question in that direction; please elaborate ?
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
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Re: Extract value from mqtt report
This is my bad English through a translator)
I ask for help on this script, can I add data from other sensors to it?
I ask for help on this script, can I add data from other sensors to it?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Extract value from mqtt report
Yes you can but for now limited to one topic and only for temperature devices.
You can do that by adding more temperature devices to line 4 like
Code: Select all
on = { devices = { 24, 37, 11 }}, -- idx of your temperature devices
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
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Re: Extract value from mqtt report
Thanks for your reply! I failed to do it correctly, now Hall temperature is constantly being transmitted, and the Street temperature is not visible, maybe this is because Hall temperature more often transmits sensor readings ...
Can it be possible to transmit both readings at the same time?
Code: Select all
Status: dzVents: Info: Handling events for: "Hall temperature", value: "22.2;39;1"
Status: dzVents: Info: ------ Start internal script: MQTT: Device: "Hall temperature (RFLink)", Index: 222
Status: dzVents: !Info: Executing command: mosquitto_pub -t clock/temperature -m 'Hall temperature: 22.2'
Status: dzVents: Info: ------ Finished MQTT
Status: dzVents: Info: Handling events for: "Street temperature ", value: "1.8"
Status: dzVents: Info: ------ Start internal script: MQTT: Device: "Street temperature (RFLink)", Index: 102
Status: dzVents: !Info: Executing command: mosquitto_pub -t clock/temperature -m 'Street temperature : 1.8'
Status: dzVents: Info: ------ Finished MQTT
Status: dzVents: Info: Handling events for: "Hall temperature", value: "22.2;39;1"
Status: dzVents: Info: ------ Start internal script: MQTT: Device: "Hall temperature (RFLink)", Index: 222
Status: dzVents: !Info: Executing command: mosquitto_pub -t clock/temperature -m 'Hall temperature: 22.2'
Status: dzVents: Info: ------ Finished MQTT
Status: dzVents: Info: Handling events for: "Hall temperature", value: "22.2;39;1"
Status: dzVents: Info: ------ Start internal script: MQTT: Device: "Hall temperature (RFLink)", Index: 222
Status: dzVents: !Info: Executing command: mosquitto_pub -t clock/temperature -m 'Hall temperature: 22.2'
Status: dzVents: Info: ------ Finished MQTT
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Extract value from mqtt report
Sure; but what should be the text ? Are you looking for something like Street temperature: 1.8, Hall temperature: 22.2 ? or do you want something else ?amplituda wrote: ↑Thursday 28 February 2019 12:54 Thanks for your reply! I failed to do it correctly, now Hall temperature is constantly being transmitted, and the Street temperature is not visible, maybe this is because Hall temperature more often transmits sensor readings ...
Would it be possible to transmit both readings at the same time?
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
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Re: Extract value from mqtt report
Yes, that's right, I want to get testimony at the same time Street temperature: 1.8, Hall temperature: 22.2
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Extract value from mqtt report
Try this
Code: Select all
-- mqqt
return {
on = {
devices =
{
24,433, 591 -- idx of your temperature Sensors
}
},
data = { temperatures = { initial = {} } },
execute = function(dz, item)
local function osExecute(cmd)
dz.log("Executing command: " .. cmd,dz.LOG_FORCE)
local fileHandle = assert(io.popen(cmd, 'r'))
assert(fileHandle:read('*a'))
fileHandle:close()
end
dz.data.temperatures[item.name] = dz.utils.round(item.temperature,2)
local clockTopic = "clock/temperature"
local payload = ""
helper = {}
for n in pairs(dz.data.temperatures) do table.insert(helper, n) end
table.sort(helper)
for key, sensorName in ipairs (helper) do
payload = payload .. sensorName .. ": " .. dz.data.temperatures[sensorName] .. ", "
end
local mqttCommand = "mosquitto_pub -t " .. clockTopic .. " -m '" .. payload:sub(1, -3) .. "'"
osExecute(mqttCommand)
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
- amplituda
- Posts: 24
- Joined: Thursday 23 August 2018 14:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Finland
- Contact:
Re: Extract value from mqtt report
Yes, now two sensors read at the same time! Thank you again!)
Who is online
Users browsing this forum: No registered users and 1 guest