Page 1 of 1

Mqtt publish value of device

Posted: Friday 14 May 2021 21:00
by calania
Hello, I am currently using the following script...

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'Ute Entre',
            'Ute Zigbee',
        },
    },

    logging =
    {
        level = domoticz.LOG_ERROR,  -- Change to domoticz.LOG_ERROR when script is OK
        --level = domoticz.LOG_DEBUG,  -- Change to domoticz.LOG_ERROR when script is OK

        marker = 'get min temperature',
    },

    execute = function(dz)
        local ute1 = dz.devices('Ute Entre').temperature
        local ute2 = dz.devices('Ute Zigbee').temperature
        local minCombined = dz.devices('UTE_KOMBINERAD')

        minCombined.updateTemperature(dz.utils.round(math.min(ute1,ute2), 1))
        end
}
It works very well but now I want to use this "UTE_KOMBINERAD" device in node red but for some reason, domoticz doesn't send its value to the domoticz/out mqtt topic like it does for every other device. Is there a way to make it so that this script also publishes the value of UTE_KOMBINERAD to an mqtt topic when it updates? It doesn't have to send it to domoticz/out, it could be any topic. If it matters I am running domoticz on a windows machine. Thanks!

Re: Mqtt publish value of device

Posted: Friday 14 May 2021 21:58
by waaren
calania wrote: Friday 14 May 2021 21:00 I want to use this "UTE_KOMBINERAD" device in node red but for some reason, domoticz doesn't send its value to the domoticz/out mqtt topic like it does for every other device. Is there a way to make it so that this script also publishes the value of UTE_KOMBINERAD to an mqtt topic when it updates?
Yes there is but the method to be used depends on your domoticz version. So what version do you use?

Re: Mqtt publish value of device

Posted: Friday 14 May 2021 22:13
by calania
I am currently still using version 4.10717 of Domoticz

Re: Mqtt publish value of device

Posted: Friday 14 May 2021 22:24
by waaren
calania wrote: Friday 14 May 2021 22:13 I am currently still using version 4.10717 of Domoticz
Sorry but that version is a bit too outdated for me. Chance that something I create for that version and especially on windows that does not work are too high and I cannot test it.
Could even be that it works without modification on a recent version.

Re: Mqtt publish value of device

Posted: Friday 14 May 2021 22:29
by calania
Thank you. I am pretty certain that you helped me create the original script so I think you have helped me enough ;) . I have postponed updating for quite a while since I don't really want to break anything but I guess the time has come.

But just as a side question do you know why it dosen't publish the value of this device to the domoticz/out topic by default like it does with every other device I have?

Re: Mqtt publish value of device

Posted: Friday 14 May 2021 22:42
by waaren
calania wrote: Friday 14 May 2021 22:29 Do you know why it dosen't publish the value of this device to the domoticz/out topic by default like it does with every other device I have?
The only reason I can think of is that it's a virtual device. Do you see anything unexpected in the domoticz log?

If I test this from my Windows system (V2021.1 build 13256) with MQTT hardware setting configured to my MQTT broker on a Linux system it just works fine

Config on windows system
MQTT.png
MQTT.png (67.15 KiB) Viewed 834 times



Command on MQTT broker

Code: Select all

mosquitto_sub -F "%U - %t - %p" -v -p 1883 -t "#"
result

Code: Select all

1621024584.154060426 - domoticz/out/test Temperature - {
        "Battery" : 255,
        "LastUpdate" : "2021-05-14 22:36:24",
        "RSSI" : 12,
        "description" : "",
        "dtype" : "Temp",
        "hwid" : "2",
        "id" : "14052",
        "idx" : 2,
        "name" : "test Temperature",
        "nvalue" : 0,
        "stype" : "LaCrosse TX3",
        "svalue1" : "12.00",
        "unit" : 1
}

Re: Mqtt publish value of device

Posted: Friday 14 May 2021 23:01
by calania
The settings page for mqtt appears to have changed a bit. This is how it looks for me
Image

I am getting no weird message in the log either

I don't think it's due to it being a virtual sensor since I have other virtual sensors that send their value without problems. However this is the only virtual device I have that is controlled with a dzVents so maybe thats the issue?

I will try to update Domoticz tomorrow and see if that fixes it. Thanks for the help anyhow!

Edit: These are my settings https://imgur.com/FcY8njO