Extract value from mqtt report Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

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

Post 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
User avatar
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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
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

Post 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)
User avatar
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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
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

Post 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!
User avatar
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

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
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

Post by amplituda »

Hi waaren, and you will not tell me how to add more sensors?
User avatar
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

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
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

Post 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?
User avatar
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

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
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

Post 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?
User avatar
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

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
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

Post by amplituda »

Yes, that's right, I want to get testimony at the same time Street temperature: 1.8, Hall temperature: 22.2
User avatar
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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
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

Post by amplituda »

Yes, now two sensors read at the same time! Thank you again!)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest