NEWS
Enhancements to Script Messaging System (Blockly)
-
Hi everyone,
I’ve been using ioBroker’s script messaging system (Blockly) and find it super helpful for inter-script communication. However, I’ve identified a few missing features that could make it even more powerful. Here’s my wishlist:
1. Missing
resultVariable in "Event: Received Message" TriggerThe "Event: Received message" block in the Trigger menu provides the
datavariable but lacks theresultvariable. This forces users to either:- Convert the script to JavaScript (losing Blockly’s simplicity), or
- Use a hack like embedding the logic in a "JavaScript function" block (my current workaround).
The
resultvariable would be very interesting feature for returning values between scripts cleanly. Adding it to Blockly would maintain consistency with JavaScript while keeping the visual scripting experience intact.
2. Missing
resultVariable in "Send Message" BlockIn the SendTo menu, the "messages to other script" block doesn’t allow passing the
resultvariable. This limits bidirectional communication, as scripts can’t easily return processed data or acknowledgments.Without
result, scripts must rely on separate messages or global variables, complicating logic and reducing efficiency.
3. Broadcast Messages to All Scripts
Currently, messages must target specific script IDs, creating tight coupling. A broadcast mechanism would excellent:
- Decoupled architecture: Scripts listen for events without knowing the sender’s ID.
- Dynamic systems: New scripts can be added without modifying existing ones (e.g., plugins).
- Event-driven workflows: Example: A "system shutdown" event notifies all relevant scripts without hardcoding dependencies.
Let me know what you think ;)
-
Hi everyone,
I’ve been using ioBroker’s script messaging system (Blockly) and find it super helpful for inter-script communication. However, I’ve identified a few missing features that could make it even more powerful. Here’s my wishlist:
1. Missing
resultVariable in "Event: Received Message" TriggerThe "Event: Received message" block in the Trigger menu provides the
datavariable but lacks theresultvariable. This forces users to either:- Convert the script to JavaScript (losing Blockly’s simplicity), or
- Use a hack like embedding the logic in a "JavaScript function" block (my current workaround).
The
resultvariable would be very interesting feature for returning values between scripts cleanly. Adding it to Blockly would maintain consistency with JavaScript while keeping the visual scripting experience intact.
2. Missing
resultVariable in "Send Message" BlockIn the SendTo menu, the "messages to other script" block doesn’t allow passing the
resultvariable. This limits bidirectional communication, as scripts can’t easily return processed data or acknowledgments.Without
result, scripts must rely on separate messages or global variables, complicating logic and reducing efficiency.
3. Broadcast Messages to All Scripts
Currently, messages must target specific script IDs, creating tight coupling. A broadcast mechanism would excellent:
- Decoupled architecture: Scripts listen for events without knowing the sender’s ID.
- Dynamic systems: New scripts can be added without modifying existing ones (e.g., plugins).
- Event-driven workflows: Example: A "system shutdown" event notifies all relevant scripts without hardcoding dependencies.
Let me know what you think ;)
for interscript communication you can use sendTo/onMessage Funtions/Events.
https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#onmessage
To Broadcast you can use a datapoint and the various scripts that should listening, can trigger on this datapoint
-
for interscript communication you can use sendTo/onMessage Funtions/Events.
https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#onmessage
To Broadcast you can use a datapoint and the various scripts that should listening, can trigger on this datapoint
@OliverIO Thanks for the quick reply.
The intent of the post is to enrich Blockly's feature, not to migrate to Javascript.
The datapoint approach works for simple cases, but it breaks down when you need to pass data, return value and deal with thread isolation (concurrent script reading/writing at same time).
For basic case, why not but it is not elegant and manager datapoint could quickly become a nightmare to manage for little bit more complex scenario.While native broadcast support would be ideal, another way to reduce coupling between scripts is to implement a centralized message-delivery script that acts as a message router.
How It Works:
- All messages are sent to a single script (e.g.,
javascript.0.message-delivery). - This script maintains a mapping of message types to target scripts (e.g.,
"temperature_update" → ["script1", "script2"]). - When a message arrives, the message-delivery forwards it to the correct listeners based on the mapping.
Pros:
- Decouples publishers from subscribers: Scripts only need to know the message-delivery's ID, not each other.
- Controlled message flow: You can log, filter, or modify messages in transit.
- Easier maintenance: Changes to routing logic happen in one place (the postman).
Cons:
- Manual mapping updates: Adding a new listener requires updating the message-delivery's configuration ... which could be considered as a pro if you prefer to keep control of the mapping.
- All messages are sent to a single script (e.g.,
-
@OliverIO Thanks for the quick reply.
The intent of the post is to enrich Blockly's feature, not to migrate to Javascript.
The datapoint approach works for simple cases, but it breaks down when you need to pass data, return value and deal with thread isolation (concurrent script reading/writing at same time).
For basic case, why not but it is not elegant and manager datapoint could quickly become a nightmare to manage for little bit more complex scenario.While native broadcast support would be ideal, another way to reduce coupling between scripts is to implement a centralized message-delivery script that acts as a message router.
How It Works:
- All messages are sent to a single script (e.g.,
javascript.0.message-delivery). - This script maintains a mapping of message types to target scripts (e.g.,
"temperature_update" → ["script1", "script2"]). - When a message arrives, the message-delivery forwards it to the correct listeners based on the mapping.
Pros:
- Decouples publishers from subscribers: Scripts only need to know the message-delivery's ID, not each other.
- Controlled message flow: You can log, filter, or modify messages in transit.
- Easier maintenance: Changes to routing logic happen in one place (the postman).
Cons:
- Manual mapping updates: Adding a new listener requires updating the message-delivery's configuration ... which could be considered as a pro if you prefer to keep control of the mapping.
Yes, I understand that. Additional blocks would certainly be useful.
However, Blockly doesn't support some other features of JavaScript and ioBroker, or only supports them partially.
If desired, one could of course build custom JavaScript function blocks in Blockly to support such features.
This thread could certainly be used to conduct a survey on this. But definitely also create a feature request on GitHub.
- All messages are sent to a single script (e.g.,
-
I have identified two interesting pieces of code.
For the missing result variable in "Event: Received Message":
https://github.com/ioBroker/ioBroker.javascript/blob/dba68e9eb91f79035f62a2df584fd1f7474462fe/admin/google-blockly/own/blocks_trigger.js#L1241-L1368And for the missing result variable in "Send Message" block:
https://github.com/ioBroker/ioBroker.javascript/blob/dba68e9eb91f79035f62a2df584fd1f7474462fe/admin/google-blockly/own/blocks_sendto.js#L365-L549Now, I have to better understand Blockly framework and see how the code can be adapted.