Cant get MQTT output into domoticz Topic is solved

Moderator: leecollings

User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Cant get MQTT output into domoticz

Post by FireWizard »

hello @MikeyMan,

You wrote:
Thing is, when I enter the topic manually in the mqtt output node, it is working.
Yes I understand. As said, that should work.
When I replace the msg.topic in the change node, it doesn't. So might be I wasn't using that in the right way, although the output looked correct in mqtt explorer.
I understand too.

You did not show the screenshot of MQTT Explorer, so I can't say anything about that.

If you look carefully to your change node you will see that you set msg.topic as a JSONata expression as follows:

Code: Select all

"domoticz/in/"
Do you see the last forward slash after "in"? That is wrong and should not be there.

So it should be

Code: Select all

"domoticz/in"
Actually you are the first forum member that uses JSONata in order to set the topic.
I never did that.
It could be a simple string, but mostly I set the topic in the MQTT Out node or, if I need a dynamic topic, I set it in a Function node.

Try this and you will see that this works as well.

Have a nice evening.
Last edited by FireWizard on Tuesday 06 September 2022 18:07, edited 1 time in total.
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Cant get MQTT output into domoticz

Post by MikeyMan »

Tried and worked.

The reason I started trying the change node was to mimic the domoticz output. Here the messages are neatly stored with a topic containing the device name. As per the settings in domoticz itself.

Thought this would be a convenient way to make mqtt more readable. But I now understand it cannot use this same format as input.

It's been a steep learning experience so far! Now let's crack on :)
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Cant get MQTT output into domoticz

Post by FireWizard »

Hi, @MikeyMan

If you need more support, I need the results of debug 9

Regards
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Cant get MQTT output into domoticz

Post by MikeyMan »

Back from holidays, and back to fiddling around with this...

Nu next step was to add a Lux meter as a dummy value:
lux meter.png
lux meter.png (7.79 KiB) Viewed 2423 times
and changing the code in NodeRed:
lux meter NR`1.png
lux meter NR`1.png (5 KiB) Viewed 2423 times
which results in the following MQTT:
lux meter MQTT.png
lux meter MQTT.png (3.71 KiB) Viewed 2423 times
as seen in MQTT explorer:
lux meter MQTT.png
lux meter MQTT.png (3.71 KiB) Viewed 2423 times
The manual JSON call is working. However, this is not doing anything. Any thoughts?
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Cant get MQTT output into domoticz

Post by FireWizard »

Hello @MikeyMan,

Yes, I see something.


- Your IDX 397 is a virtual Lux sensor.and it expects:

{"command":"udevice", "idx":1234, "svalue":"3.45"}

The "command":"udevice" is optional as Domoticz defaults to "udevice".

You also see that the value for "svalue" should be a string. So between " ".
svalue needs always a string value (nvalue needs a numerical value).

If I look to your screenshots from MQTT Explorer, I see a number (82180) without quotes.
Probably your variable msg.payload.states[3].value represents a number.
You should convert it to a string as follows:

Code: Select all

msg.payload = { "idx": 397, "svalue": msg.payload.states[3].value.toString()}
Try this and let me know.

Regards
Last edited by FireWizard on Sunday 07 May 2023 23:08, edited 1 time in total.
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Cant get MQTT output into domoticz

Post by MikeyMan »

FireWizard wrote: Monday 26 September 2022 18:07 Hello @MikeyMan,

Yes, I see something.


- Your IDX 397 is a virtual Lux sensor.and it expects:

{"command":"udevice", "idx":1234, "svalue":"3.45"}

The "command":"udevice" is optional as Domoticz defaults to "udevice".

You also see that the value for "svalue" should be a string. So between " ".
svalue needs always a string value (nvalue needs a numerical value).

If I look to your screenshots from MQTT Explorer, I seea number (82180) without quotes.
Probably your variable msg.payload.states[3].value represents a number.
You should convert it to a string as follows:

Code: Select all

msg.payload = { "idx": 397, "svalue": msg.payload.states[3].value.toString()}
Try this and let me know.

Regards
Thanks I'll give that a try.

Does it make sense that a lux value, that is by default a number, should be a string? Won't that pose issues when you want to use it in a function or test later on?

I tried nvalue as well to no luck btw.
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Cant get MQTT output into domoticz

Post by FireWizard »

Hello @MikeyMan,

You asked:
Does it make sense that a lux value, that is by default a number, should be a string?
Yes, because Domoticz only accepts the lux value, as svalue (and not nvalue). This should be a string.
Won't that pose issues when you want to use it in a function or test later on?
No idea why that should be the case. Never heard of any issues.
I tried nvalue as well to no luck btw.
I would have been surprised, if that has solved the issue. In that case we had to rewrite the documentation.
Thanks I'll give that a try.
Let me know the result.

Regards
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Cant get MQTT output into domoticz

Post by FireWizard »

Hi @MikeyMan,

I created a very simple test flow, where you could see the result of sending the correct data to Domoticz

1. Node Red:

Screenshot_Inject_Lux.png
Screenshot_Inject_Lux.png (39.83 KiB) Viewed 2402 times

What you see, is a simple "Inject" node, that injects both the msg.payload.svalue and the msg.payload.idx (in my case 23, in your case 397).
You see, that I injected a string. In the debug pane you will see that it is a string (red with quotes, while a number is blue)

2. In Domoticz:

Screenshot_Widget Lux.png
Screenshot_Widget Lux.png (43.97 KiB) Viewed 2402 times
The topic is domoticz/in (Set in the MQTT out node)

Regards
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Cant get MQTT output into domoticz

Post by MikeyMan »

getting somewehere
This is working:
NR Lux 1.png
NR Lux 1.png (3.68 KiB) Viewed 2391 times
This isn't:
NR Lux 2.png
NR Lux 2.png (5.85 KiB) Viewed 2391 times
Trying to find out how to fix this.

Thanks again for your patient help ;)

Flow is:

Code: Select all

[{"id":"fc6d9990e9735efe","type":"http request","z":"743a62898f598be4","name":"Get Devices","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://10.0.0.161:8443/enduser-mobile-web/1/enduserAPI/setup/devices","tls":"d141c56ce52dcd5d","persist":true,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":430,"y":420,"wires":[["792793a85f7af9e3","0f5c255927c3a287"]]},{"id":"0d0b145a46d08eb6","type":"inject","z":"743a62898f598be4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":420,"wires":[["fc6d9990e9735efe"]]},{"id":"27bcb8ebe2e66553","type":"mqtt out","z":"743a62898f598be4","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"92e5b2c.00a8b5","x":1350,"y":420,"wires":[]},{"id":"14b2125b610f82a3","type":"debug","z":"743a62898f598be4","name":"debug 8","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":500,"wires":[]},{"id":"792793a85f7af9e3","type":"debug","z":"743a62898f598be4","name":"debug 9","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":500,"y":500,"wires":[]},{"id":"0d414e1eda85b389","type":"debug","z":"743a62898f598be4","name":"debug 10","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":500,"wires":[]},{"id":"0f5c255927c3a287","type":"split","z":"743a62898f598be4","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":690,"y":420,"wires":[["14b2125b610f82a3","bfff67f1ca427a4b"]]},{"id":"164e4e3ca1fddfca","type":"function","z":"743a62898f598be4","name":"function 1","func":"//if(msg.payload.deviceURL === \"io://2017-8871-5701/3196925\")\n//{\n//    return msg;\n//}\n\nif (msg.payload.deviceURL === \"io://2017-8871-5701/14384853\") \n    {\n  msg.payload = { \"idx\": 397, \"svalue\": Number(msg.payload.states[3].value)}\n  //  msg.topic = { \"domoticz/in\" }\n    return msg;\n    }\n\n\n//{ \"command\": \"udevice\", \"idx\" : 7, \"nvalue\" : 0, \"svalue\" : \"90;2975.00\" }\n//{ \"idx\" : 7, \"nvalue\" : 0, \"svalue\" : \"90;2975.00\" }\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":420,"wires":[["27bcb8ebe2e66553","5569758a44d2d493"]]},{"id":"5569758a44d2d493","type":"debug","z":"743a62898f598be4","name":"debug 11","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1200,"y":500,"wires":[]},{"id":"bfff67f1ca427a4b","type":"change","z":"743a62898f598be4","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"domoticz/in","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":420,"wires":[["164e4e3ca1fddfca","0d414e1eda85b389"]]},{"id":"d141c56ce52dcd5d","type":"tls-config","name":"TLS","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false,"alpnprotocol":""},{"id":"92e5b2c.00a8b5","type":"mqtt-broker","name":"MQTT (NAS)","broker":"10.0.0.4","port":"1883","clientid":"Node_Red_Client","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]
edit: doh... I'm rather stupid... String() instead of Number() is working... :lol:
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Cant get MQTT output into domoticz

Post by FireWizard »

HI, @MikeyMan,

Can we consider this issue as solved now?
Maybe, you want to have a look at: https://www.w3schools.com/js/js_number_methods.asp
Or is there any other issue, you need support?

Regards
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Cant get MQTT output into domoticz

Post by MikeyMan »

Yes, this is resolved now, thanks! :)

Now struggling along to get a post api working. And thinking of some logic not to hard code the hardware coming in from the API. But that's not realy a Domoticz think yet.

Thanks again for your help! :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest