Mqtt publish value of device

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
calania
Posts: 20
Joined: Friday 17 April 2020 21:02
Target OS: Windows
Domoticz version:
Contact:

Mqtt publish value of device

Post 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!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Mqtt publish value of device

Post 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?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
calania
Posts: 20
Joined: Friday 17 April 2020 21:02
Target OS: Windows
Domoticz version:
Contact:

Re: Mqtt publish value of device

Post by calania »

I am currently still using version 4.10717 of Domoticz
Last edited by calania on Friday 14 May 2021 22:25, edited 2 times in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Mqtt publish value of device

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
calania
Posts: 20
Joined: Friday 17 April 2020 21:02
Target OS: Windows
Domoticz version:
Contact:

Re: Mqtt publish value of device

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Mqtt publish value of device

Post 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 836 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
calania
Posts: 20
Joined: Friday 17 April 2020 21:02
Target OS: Windows
Domoticz version:
Contact:

Re: Mqtt publish value of device

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

Who is online

Users browsing this forum: No registered users and 1 guest