Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ioBroker node and MQTT format does not work as expected #325

Open
thohoj opened this issue Aug 21, 2022 · 5 comments
Open

ioBroker node and MQTT format does not work as expected #325

thohoj opened this issue Aug 21, 2022 · 5 comments

Comments

@thohoj
Copy link

thohoj commented Aug 21, 2022

I created an ioBroker in node with

topic: 'shelly/0/SHBDUO-1#483FDA928A8B#1/lights/Switch'
topic format: MQTT (with '/') (the default!)

But the node never outputs a message. This is confusing.

If I change

topic: 'shelly.0.SHBDUO-1#483FDA928A8B#1.lights.Switch'

The node outputs messages and re-formats the messages topic to MQTT (with '/'). Now it makes sense.

Later on such a MQTT-topic-formatted messages arrives at an ioBroker out node and an error message is shown:

"ioBroker out" Cannot set state of non-existing object "node-red.0.shelly.0.SHBDUO-1#483FDA928A8B#1.lights.Switch"

Seems that the ioBroker out node tries to reformat the MQTT style topic into an ioBroker style topic but prefixes it with the node-red instance name.

As a node-red user I want to work with a consistent style of topic without converting it every time from one format into another. This keeps my flows clean and reduces bolierplate code. The step to MQTT topics was good, but all ioBroker nodes should be able to handle it uniformly.

@Apollon77
Copy link
Contributor

Please provide a debug log (set instance of node-red to debug loglevel) of that above and tell exactly what you expect to be changed. From your words I'm (as the "not using node-red nor MQTT-in-node-red" developer) have no real idea what your issue exactly is :-) Give me more details (like your speak to a node-red/mqtt dau) ;-)

@thohoj
Copy link
Author

thohoj commented Aug 21, 2022

First of all: the in node seems to work with MQTT formatted topics.

topic: 'shelly/0/SHBDUO-1#483FDA928A8B#1/lights/Switch'
topic format: MQTT (with '/') (the default!)

This worked afer reloading the node-red page. Apparrently my browser dropped some of the logs.

--
The issue with the out node left. I have reduced this to a simple flow:

image

If the switched was pressed on the brightness should be changed. Here is the code of the function node:

if (msg.payload === false) return null;

const path = msg.topic.split('/');
msg.topic = path.pop();
path.push('brightness');
msg.topic = path.join('/');
msg.payload = 30;

return msg;

Here is the debug log after switching off:

image

The catch apparently did not work, but from the ioBroker log:

7b5e078317b38286: Automatic objects creation is not enabled. You can enable it in the node configuration
7b5e078317b38286: "ioBroker out" Cannot set state of non-existing object "node-red.0.shelly.0.SHBDUO-1#483FDA928A8B#1.lights.brightness".

@Apollon77
Copy link
Contributor

Thank you, that helped, will look into it soon

@thohoj
Copy link
Author

thohoj commented Aug 27, 2022

Seems the problem is, that the "ioBroker out node" replaces '/' with '.' after checking the adapter prefix of the ID on node input. So the node does not recognize an adapter namespace and prefixes it with 'node-red.0.'.

I have done some changes in my forked repo and would test these in my ioBroker instance. But I dont' know how. Is there a tutorial / documentation / howto?

@Apollon77
Copy link
Contributor

I have done some changes in my forked repo and would test these in my ioBroker instance. But I dont' know how. Is there a tutorial / documentation / howto?

In fact change the same files the same way locally in /opt/iobroekr/node_modules/iobroker.node-red ... and restart the adapter ... should have immediate effect. Thats easiest to test for you I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants