Page 1 of 1
Extract value from mqtt report
Posted: Saturday 16 February 2019 6:39
by amplituda
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
Re: Extract value from mqtt report
Posted: Saturday 16 February 2019 8:44
by waaren
amplituda 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
See the attached dzVents script
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
}
Re: Extract value from mqtt report
Posted: Saturday 16 February 2019 10:55
by amplituda
waaren wrote: ↑Saturday 16 February 2019 8:44
See the attached dzVents script
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
but I do not understand where to get the correct name of the mqtt topic, to indicate in the settings of the clock .... that is, what should i replace
domoticz / out to see
Street temperature 0.9
please tell me more)
Re: Extract value from mqtt report
Posted: Saturday 16 February 2019 11:36
by waaren
amplituda wrote: ↑Saturday 16 February 2019 10:55
please tell me more)
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
}
Re: Extract value from mqtt report
Posted: Saturday 16 February 2019 13:41
by amplituda
waaren wrote: ↑Saturday 16 February 2019 11:36
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
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!
Re: Extract value from mqtt report
Posted: Saturday 16 February 2019 14:14
by waaren
amplituda wrote: ↑Saturday 16 February 2019 13:41
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!
You have to close it yourself as you started the topic.
Re: Extract value from mqtt report
Posted: Wednesday 27 February 2019 8:52
by amplituda
Hi waaren, and you will not tell me how to add more sensors?
Re: Extract value from mqtt report
Posted: Thursday 28 February 2019 0:00
by waaren
amplituda wrote: ↑Wednesday 27 February 2019 8:52
Hi waaren, and you will not tell me how to add more sensors?
Is this a question or a statement ?
I am not aware of a question in that direction; please elaborate ?
Re: Extract value from mqtt report
Posted: Thursday 28 February 2019 6:00
by amplituda
This is my bad English through a translator)
I ask for help on this script, can I add data from other sensors to it?
Re: Extract value from mqtt report
Posted: Thursday 28 February 2019 11:42
by waaren
amplituda wrote: ↑Thursday 28 February 2019 6:00
This is my bad English through a translator)
I ask for help on this script, can I add data from other sensors to it?
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
if you need other types of information and other topics then please specify in detail what you want / need and I will try to help
Re: Extract value from mqtt report
Posted: Thursday 28 February 2019 12:54
by amplituda
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 ...
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
Can it be possible to transmit both readings at the same time?
Re: Extract value from mqtt report
Posted: Thursday 28 February 2019 16:30
by waaren
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?
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 ?
Re: Extract value from mqtt report
Posted: Thursday 28 February 2019 16:53
by amplituda
Yes, that's right, I want to get testimony at the same time Street temperature: 1.8, Hall temperature: 22.2
Re: Extract value from mqtt report
Posted: Thursday 28 February 2019 17:01
by waaren
amplituda wrote: ↑Thursday 28 February 2019 16:53
Yes, that's right, I want to get testimony at the same time
Street temperature: 1.8, Hall temperature: 22.2
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
}
Re: Extract value from mqtt report
Posted: Friday 01 March 2019 7:39
by amplituda
Yes, now two sensors read at the same time! Thank you again!)