Msg.topic in ui-switch node

I use native NodeRed (4.0) on a Raspberry PI 4.0b. I'm converting my flows from dashboard 1 to dashboard 2 (1.12.2).
I've seen that on a node ui-switch, I cannot use the "topic" writing a string that must reach MQTT. The string is "cmnd/tasmota_cucina/POWER".
If I write a string on that field I get the "Error: invalid topic".
Is it a my mistake?

Have you selected string as the type input for topic field. Show us how it is configured.
[edit]
I have just checked and this seems to be a bug, can you raise a issue on the nodes github page.

Yes, of course

Just tried this myself, and it seems to be okay:


Where are you seeing the error flag?

p.s. welcome to the NR forums :slightly_smiling_face:

I am seeing the issue too Joe.

[{"id":"d4daef38e3602a9b","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":4860,"wires":[["bfb4f9cb103bcd4c"]]},{"id":"bfb4f9cb103bcd4c","type":"ui-switch","z":"d1395164b4eec73e","name":"","label":"switch","group":"ff7cbf009b7b3034","order":1,"width":0,"height":0,"passthru":true,"topic":"cmnd/tasmota_cucina/POWER","topicType":"str","style":"","className":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":250,"y":4920,"wires":[["24a9b94fdad4092e","ab4c02fbdf85c8fd"]]},{"id":"24a9b94fdad4092e","type":"mqtt out","z":"d1395164b4eec73e","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"e8ba3ef5.22f4a8","x":430,"y":4920,"wires":[]},{"id":"ab4c02fbdf85c8fd","type":"debug","z":"d1395164b4eec73e","name":"debug 2557","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":370,"y":4860,"wires":[]},{"id":"ff7cbf009b7b3034","type":"ui-group","name":"Form","page":"3bceecc44f91d26b","width":"6","height":"1","order":1,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"e8ba3ef5.22f4a8","type":"mqtt-broker","name":"testb","broker":"192.168.1.25","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"3bceecc44f91d26b","type":"ui-page","name":"Custom Form Submission","ui":"1805777f90e92057","path":"/form-submission","icon":"home","layout":"grid","theme":"35ee7753b5b3599b","order":1,"className":"","visible":true,"disabled":"false"},{"id":"1805777f90e92057","type":"ui-base","name":"dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false},{"id":"35ee7753b5b3599b","type":"ui-theme","name":"Theme Name","colors":{"surface":"#16234b","primary":"#1d44b9","bgPage":"#ecf2f8","groupBg":"#ffffff","groupOutline":"#cccccc"}}]

On latest update

I reported that back in December last year. The topic does not get sent unless a message is first sent to the switch.

Ah, okay, thanks Colin - I'll bump this up the priority list and address asap. Will need to be early next week now.

Thanks Joe.
I see the error on "Debug" of NR.
This string is correct because I use it on DB1 nodes. It works correctly if you insert the string directly on topic of MQTT-OUT node.
But I didn't understand if it works for you by putting the string in the ui-switch node and then sending the output to mqtt-out.
In other words, is it my problem?

It would appear I tested on a ui-switch where I'd previously injected a msg. As Colin and @E1cid mentione above, it seems to happen before any messages are injected into the switch - definitely an us problem to fix :slightly_smiling_face: sorry for the inconvenience

It is not your fault, the switch does not send the topic unless it is first sent a message, so the MQTT node throws the error. As a matter of good practice it is best to always give nodes names, then if they throw an error like this you will see which node it is, rather than having to click in the debug pane to get it to highlight the node. As a workaround configure the inject node to send it a valid message on startup. You can remove that when the bug has been fixed.

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