# Mqtt value to domoticz

**URL:** <https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878>\
**Category:** General\
**Tags:** domoticz\
**Created:** [31 March 2024 12:11 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878 "2024-03-31T12:11:38Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nodouser](https://avatars.discourse-cdn.com/v4/letter/n/a9adbd/32.png) [@nodouser](https://discourse.nodered.org/u/nodouser)\
**Post date:** [31 March 2024 12:11 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/1 "2024-03-31T12:11:38Z")

</div>

I've been searching for a while too, but I can't figure it out.

I've checked the websites, but they have predefined values. I want to send a value from MQTT Node-RED using an HTTP rule or another way to Domoticz. The value comes from Node-RED.

I want this value to a counter in Domoticz.

![afbeelding](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/2/9257778ed0c49a2b1153b4400c00ed1b203a21f6.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 March 2024 12:30 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/2 "2024-03-31T12:30:40Z")

</div>

> [@nodouser](#):
>
> I want to send a value via MQTT Node-RED using an HTTP request or another way

Sorry, that doesn't make sense. If you want to send a value to MQTT you just use an MQTT Out node.

---

<div class="post-metadata">

**Author:** ![nodouser](https://avatars.discourse-cdn.com/v4/letter/n/a9adbd/32.png) [@nodouser](https://discourse.nodered.org/u/nodouser)\
**Post date:** [31 March 2024 12:55 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/3 "2024-03-31T12:55:07Z")

</div>

I want to send a value to a counter in Domoticz.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [31 March 2024 13:22 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/4 "2024-03-31T13:22:35Z")

</div>

You would use the http request node.  
Not knowing the Domoticz webhook url it is hard to say much more.  
This is a simple example, you would have to add the correct url for your Domoticz.  
You may find better help to find the correct the url on the Domoticz forum.

```auto
[{"id":"e97e8fc8c8bebf01","type":"http request","z":"d1395164b4eec73e","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://192.168.1.23?value={{payload}}","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":770,"y":7780,"wires":[["41f71d0cd684effc"]]},{"id":"ffb65c2b7dd50673","type":"inject","z":"d1395164b4eec73e","name":"mqtt in","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"12345","payloadType":"num","x":610,"y":7780,"wires":[["e97e8fc8c8bebf01"]]},{"id":"41f71d0cd684effc","type":"debug","z":"d1395164b4eec73e","name":"debug 2487","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":7780,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 March 2024 14:15 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/5 "2024-03-31T14:15:46Z")

</div>

This suggests that you can use MQTT with Domoticz. [MQTT - Domoticz](https://www.domoticz.com/wiki/MQTT)

---

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [31 March 2024 16:22 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/6 "2024-03-31T16:22:12Z")

</div>

Hello @nodouser,

What should that number value in your node represent?

It is just a number.  
Should it be displayed in a Domoticz "Text" widget?  
Or something else?  
You said a counter. What is it? Is it a Custom sensor?

Regards

---

<div class="post-metadata">

**Author:** ![nodouser](https://avatars.discourse-cdn.com/v4/letter/n/a9adbd/32.png) [@nodouser](https://discourse.nodered.org/u/nodouser)\
**Post date:** [31 March 2024 19:25 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/7 "2024-03-31T19:25:12Z")

</div>

I have a water meter that sends consumption data to Node-RED. Using Node-RED, I've created an incremental counter so that I can track how much water has passed through the water softener. This helps me know when salt needs to be filled.

Once I refill the salt, I reset the counter so that I always know there's enough salt in the water softener. Everything works within Node-RED, but I want to see the water consumption in Domoticz. The value is visible in the Debug. So, I need to add a line in the function node that forwards the value to domoticz, or perhaps there's a better way?  
So far it works.

I do use often a function node for sending a state of a switch to domoticz, but sending a value is new for me.

 ![afbeelding](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cf4b59daa3aa0c2e6dd8a4b6d691537919bfa6ff.png)

In domoticz i think this is the best way,

![afbeelding](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7bd45dfff68aff52019104084c6e33c5c15b3ee2.png)

Hopefully, it's clear now.

---

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [1 April 2024 10:15 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/8 "2024-04-01T10:15:29Z")

</div>

Hello @nodouser,

Yes, it is almost clear. I do understand the objective of your flow.

What is important to know, is what does the number value represent?  
For now, I assume, that it is a number in Liters (L).

The "RFX Counter" in Domoticz could be seen as a sensor.  
Another Domoticz user has created a nice list of the various sensors possible in Domoticz.

See: [MQTT out for Domoticz – PI and more](https://piandmore.wordpress.com/2019/02/04/mqtt-out-for-domoticz/)  
Unfortunately the information, written for a water counter is wrong. You should use the information at: [Domoticz API/JSON URL's - Domoticz](https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Counter)

To send the data to Domoticz you can use a "Function" node in front of the MQTT out node to Domoticz, with the following content:

```auto
const idx = 12345 // Replace 12345 with the Domoticz IDX number of your sensor.

msg.payload = { "command": "udevice", "idx": idx, "nvalue": 0, "svalue": msg.payload.toString() };

return msg;

```

"command": "udevice" is default, but I included it for completeness.  
Also "nvalue": 0, you may omit, as it is not needed in this case.  
Do not forget to replace the number 12345 in the first line with your idx number.

In order to configure the right dividers for the water counter, see the discussion on the Domoticz forum (this is about the HomeWizard water device, but is applicable in your case, as well):  
[https://www.domoticz.com/forum/viewtopic.php?t=39178&hilit=water](https://www.domoticz.com/forum/viewtopic.php?t=39178&hilit=water)

Regards

---

<div class="post-metadata">

**Author:** ![nodouser](https://avatars.discourse-cdn.com/v4/letter/n/a9adbd/32.png) [@nodouser](https://discourse.nodered.org/u/nodouser)\
**Post date:** [1 April 2024 11:52 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/9 "2024-04-01T11:52:33Z")

</div>

Yes, that was the solution, and indeed liters.  
When 30,000 liters have passed through the water softener, I need to refill the salt.  
It's a bit of a learning curve with Node-RED, but it's great once you have it working.

Thanks for the support!

---

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [1 April 2024 12:17 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/10 "2024-04-01T12:17:50Z")

</div>

Keep the following in mind:

1. The Counter in the upper right corner displays in liters and is a daily counter (CounterToday) and will be reset to zero at midnight.
2. The Counter in the middle of the widget displays in m3 (cubic\_meter) and will not be reset.
3. In order to reset that counter you have to send the negative counter value.

I do not know how you reset the counter, but I would implement a virtual switch and configure it as a "On" button. and send a status update by MQTT to Node RED.

In Node-RED, when I receive the reset command, I would request status information from the widget (node) and send that negative value to MQTT.

See an example below. Replace the IDX (rid) and the IP address:

```auto
[
    {
        "id": "6685db4105e29da0",
        "type": "http request",
        "z": "65711f41c50e0302",
        "name": "",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "http://192.168.10.50:8080/json.htm?type=command&param=getdevices&rid=532",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 410,
        "y": 220,
        "wires": [
            [
                "b3edbc0b5e951831",
                "39c685e36ccae3c6"
            ]
        ]
    },
    {
        "id": "4b08b480637677b1",
        "type": "inject",
        "z": "65711f41c50e0302",
        "name": "Reset Counter",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 200,
        "y": 220,
        "wires": [
            [
                "6685db4105e29da0"
            ]
        ]
    },
    {
        "id": "b3edbc0b5e951831",
        "type": "debug",
        "z": "65711f41c50e0302",
        "name": "debug 231",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 610,
        "y": 220,
        "wires": []
    },
    {
        "id": "39c685e36ccae3c6",
        "type": "function",
        "z": "65711f41c50e0302",
        "name": "function 20",
        "func": "msg.payload = { \"command\": \"udevice\", \"idx\": msg.payload.result[0].idx, \"nvalue\": 0, \"svalue\": (-(parseFloat(msg.payload.result[0].Counter))).toString() };\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 610,
        "y": 280,
        "wires": [
            [
                "8b5327b71eb073bb"
            ]
        ]
    },
    {
        "id": "8b5327b71eb073bb",
        "type": "debug",
        "z": "65711f41c50e0302",
        "name": "debug 232",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 810,
        "y": 280,
        "wires": []
    }
]

```

Regards

---

<div class="post-metadata">

**Author:** ![nodouser](https://avatars.discourse-cdn.com/v4/letter/n/a9adbd/32.png) [@nodouser](https://discourse.nodered.org/u/nodouser)\
**Post date:** [1 April 2024 12:48 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/11 "2024-04-01T12:48:26Z")

</div>

Thanks!  
I do have a rest button, it sets the value to 30.000 liter, when refill of the salt is done. The counter will decrement.

Maybe better not to use a meter that gets a reset during the night. I will test it for a few days, lets see how it works.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 April 2024 12:49 UTC](https://discourse.nodered.org/t/mqtt-value-to-domoticz/86878/12 "2024-04-15T12:49:24Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
