Help with splitting a payload

#1

I am a new Node red and java user.
I am a bit lost and confused when trying to use the function node to split a payload into seperate variables.

I am sucsessful in using nodered to send light commands from openhab to HDL buspro using the node-red-contrib-hdl node.
But when the light state is changed from the wall switch i want the slider in openhab to update.

The HDL out node sends messages from everything that is hapening on the bus i want to filter out this message:

Using type: "Brodcast", sender.type :617, sender.id: 60, payload.channel: 1, payload.success: true.
But the msg.payload contains "{ channel: 2, success: true, level: 60 }" which i havent been successfull in using.
If all of above are met i want to simply make a new message containg a msg.payload of the level as a number to be injected to the openhab item.

Se the above screenshot of what i am trying to do.

Here are the node`s exported:

Blockquote

[{"id":"70b3a5c9.e03b9c","type":"openhab2-out","z":"1de3ad0b.acd123","name":"","controller":"a268b93f.2493d8","itemname":"60_2_Gang_Downlights","topic":"ItemUpdate","payload":"","x":370,"y":300,"wires":[]},{"id":"f140d9ec.3d79a8","type":"hdl-in","z":"1de3ad0b.acd123","name":"","controller":"5c872a92.04e414","x":70,"y":300,"wires":[["e5821038.6efe1"]]},{"id":"e5821038.6efe1","type":"function","z":"1de3ad0b.acd123","name":"","func":"if (msg.type = "broadcast")\nif (Number(msg.sender.id = 60))\nif (Number(msg.sender.type = 617))\nif (msg.payload.channel = 1)\nif (msg.payload.success = true)\nset msg.payload = msg.payload.level\nreturn msg;","outputs":1,"noerr":5,"x":190,"y":300,"wires":[["70b3a5c9.e03b9c"]]},{"id":"a268b93f.2493d8","type":"openhab2-controller","z":"","name":"Openhab2","protocol":"http","host":"localhost","port":"8080","path":"","username":"","password":""},{"id":"5c872a92.04e414","type":"hdl-controller","z":"","name":"","host":"192.168.10.250","port":"6000","subnet":"1","devid":"99","mode":"tunnel/unicast"}]

Blockquote

Have searched and tried using some examples for splitting the payload but not had any success.
Is anybody able to help me do what i want?

Thanks in advance.

0 Likes

#2

First off you have an error in your function, The if statements actions need to be in {} so for examp

if (msg.payload = "broadcast") {
   if (number(msg.sender.is = 60)) {
      set msg.payload = msg.payload.level;
}}
1 Like

#3

You need to check the syntax you have used in your decison blocks.

For example...
if (msg.payload = "broadcast") should be.... if (msg.payload == "broadcast")

Likewise, comparing something to an integer needs two equal signs ==

And lastly, comparing something to a boolean (true or false) (as on line 5 of your function) needs THREE equal signs ===

1 Like

#4

It’s javascript

0 Likes

#5

Thanks zenofmud and dynamicdave for quick response.
With your help i managed to get it working as expected.

final code became like this:

if (msg.type == "broadcast") {
    if (Number(msg.sender.id == 60)) {
        if (Number(msg.sender.type = 617)) {
            var a = msg.payload.split(" ");
            if (a[3] == "success:"){
                if (a[4] == "true,"){
                    if (a[2] == "2,"){
                        Number(msg.payload = a[6]);
                        return msg;
}}}}}}
0 Likes

#6

Phew - that still looks complicated.
You could use the AND operator (&&) in JavaScript to join some of the tests together (and make it easier to read/understand).

if ( (msg.type == "broadcast") && (Number(msg.sender.id == 60)) && (Number(msg.sender.type == 617))  )
{
  var a = msg.payload.split(" ");
    if ( (a[3] == "success") && (a[4] === true) && (a[2] == "2")  )
    {
      Number(msg.payload = a[6]);
      return msg;
    }
}

Note: I've not tried it, so there might be some 'typos'.

1 Like

#7

Complicated but works.
Your version with && worked just as good once i fixed the typos on line 4.
I agree that your version is less confusing and understand it mutch bether, thanks i did not know about the && function. Will use it.

Is there a practical use for changing the code? Thinking about CPU usage and so on.
Bus outputs about 1 message per second and i have 30 function nodes containing this script just for updating the dimmer channels. With reading relays, temprature and universal switches i will proberly exeed 100 nodes checking every message exited on the bus once per second.

PS. It runs on a raspberry pi 3. Is this the best way of doing it or is it not a problem at all?

Image of how it is now:

Thanks again.

0 Likes

#8

It turns out that your use case is very interesting.

In regards to performance it is true that each and every msg out of the HDL node will need to be cloned and afterward dissected by a function node. I may be wrong but my guess is that you will NOT face performance issues even when going above 100 function nodes.

However you may want to change the code for another reason, that is maintainability. It is hard to update code for one hundred different nodes. Also your code is very sensitive to white spaces within msg.payload. A single typo may compromise the routing.

Every programmer in the face of the Earth would produce a different code for this use case. My first attempt would be building a hash key with the relevant properties and then use a single JavaScript switch case or a Node-RED switch for doing the switching. I wanted to give it a try, for my own learning and enlightment. However, I would need a copy of the object as it is generated in the output of the HDL node. Would it be possible for you to add a dbug node in the output of the HDL and then copy the object from the debug panel and share it here in the text format ?

0 Likes

#9

Oops - sorry I missed the comma on Line-4.

This just goes to reinforce what Andrei said about "maintainability".

What sort of thing are you sensing/controlling?
Do you really need to update it every second?

0 Likes

#10

No idea about how to do hash key and so on and think that is way above what i will ever understand about java.

Dont know how i can copy all of the data comming out but have included some of the messages comming.

Here is the answerback from one of my dimmers which has adresse id 60 and channel 2 when it is dimmed to 80%

{"topic":"255.255","payload":"{ channel: 2, success: true, level: 80 }","sender":{"id":60,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":46,"device":"[Circular ~.sender]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":100,"device":"[Circular ~.sender]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":100,"device":"[Circular ~.sender]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":100,"device":"[Circular ~.sender]","number":5,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":80,"device":"[Circular ~.sender]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":{"id":99,"type":65534,"subnet":1,"address":[0,0,0,0],"port":6000,"gateway":"192.168.10.250","socket":"[internal]","devices":{"1.23":{"id":23,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":3047,"domain":null,"_events":{},"_eventsCount":1},"255.255":{"id":255,"subnet":255,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.60":"[Circular ~.sender]","1.62":{"id":62,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":2,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":4,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":100,"device":"[Circular ~.sender.bus.devices.1.62]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":621,"domain":null,"_events":{},"_eventsCount":1},"1.61":{"id":61,"subnet":1,"channels":{"1":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":67,"device":"[Circular ~.sender.bus.devices.1.61]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":5,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":617,"domain":null,"_events":{},"_eventsCount":1},"1.22":{"id":22,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":1109,"domain":null,"_events":{},"_eventsCount":1},"1.142":{"id":142,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.102":{"id":102,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":162,"domain":null,"_events":{},"_eventsCount":1},"1.80":{"id":80,"subnet":1,"channels":{"8":{"level":0,"device":"[Circular ~.sender.bus.devices.1.80]","number":8,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1},"1.144":{"id":144,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":321,"domain":null,"_events":{},"_eventsCount":1},"1.141":{"id":141,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.56":{"id":56,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.70":{"id":70,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":854,"domain":null,"_events":{},"_eventsCount":1},"1.140":{"id":140,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":323,"domain":null,"_events":{},"_eventsCount":1},"1.100":{"id":100,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":167,"domain":null,"_events":{},"_eventsCount":1},"1.1":{"id":1,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.55":{"id":55,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.81":{"id":81,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.81]","number":1,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1}},"domain":null,"_events":{"command":[null,null],"broadcast":[null,null]},"_eventsCount":2},"type":600,"domain":null,"_events":{},"_eventsCount":1},"type":"broadcast","_msgid":"4a22c7dc.637ab8"}

Here is a answerback from the relaymodule with adresse 80. Here you can se that channel 8 is set to on.

{"topic":"255.255","payload":"{ channel: 8, success: true, level: 100 }","sender":{"id":80,"subnet":1,"channels":{"8":{"level":0,"device":"[Circular ~.sender]","number":8,"domain":null,"_events":{},"_eventsCount":0}},"bus":{"id":99,"type":65534,"subnet":1,"address":[0,0,0,0],"port":6000,"gateway":"192.168.10.250","socket":"[internal]","devices":{"1.23":{"id":23,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":3047,"domain":null,"_events":{},"_eventsCount":1},"255.255":{"id":255,"subnet":255,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.60":{"id":60,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.60]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":80,"device":"[Circular ~.sender.bus.devices.1.60]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":5,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":80,"device":"[Circular ~.sender.bus.devices.1.60]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":600,"domain":null,"_events":{},"_eventsCount":1},"1.62":{"id":62,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":2,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":4,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":100,"device":"[Circular ~.sender.bus.devices.1.62]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":621,"domain":null,"_events":{},"_eventsCount":1},"1.61":{"id":61,"subnet":1,"channels":{"1":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":67,"device":"[Circular ~.sender.bus.devices.1.61]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":5,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":617,"domain":null,"_events":{},"_eventsCount":1},"1.22":{"id":22,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":1109,"domain":null,"_events":{},"_eventsCount":1},"1.142":{"id":142,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.102":{"id":102,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":162,"domain":null,"_events":{},"_eventsCount":1},"1.80":"[Circular ~.sender]","1.144":{"id":144,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":321,"domain":null,"_events":{},"_eventsCount":1},"1.141":{"id":141,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.56":{"id":56,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.70":{"id":70,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":854,"domain":null,"_events":{},"_eventsCount":1},"1.140":{"id":140,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":323,"domain":null,"_events":{},"_eventsCount":1},"1.100":{"id":100,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":167,"domain":null,"_events":{},"_eventsCount":1},"1.1":{"id":1,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.55":{"id":55,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.81":{"id":81,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.81]","number":1,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1}},"domain":null,"_events":{"command":[null,null],"broadcast":[null,null]},"_eventsCount":2},"type":430,"domain":null,"_events":{},"_eventsCount":1},"type":"command","_msgid":"6ee071c6.4ce47"}

Here is a temprature broadcast from my 12in1 sensor adresse 142. Dont know how to se the temprature from that payload or message but know its suposed to be 26 deg celsius from other software.

{"topic":"255.255","payload":"2e0000000001010000","sender":{"id":142,"subnet":1,"channels":{},"bus":{"id":99,"type":65534,"subnet":1,"address":[0,0,0,0],"port":6000,"gateway":"192.168.10.250","socket":"[internal]","devices":{"1.23":{"id":23,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":3047,"domain":null,"_events":{},"_eventsCount":1},"255.255":{"id":255,"subnet":255,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.60":{"id":60,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.60]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":80,"device":"[Circular ~.sender.bus.devices.1.60]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":5,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":80,"device":"[Circular ~.sender.bus.devices.1.60]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":600,"domain":null,"_events":{},"_eventsCount":1},"1.62":{"id":62,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":2,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":4,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":100,"device":"[Circular ~.sender.bus.devices.1.62]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":621,"domain":null,"_events":{},"_eventsCount":1},"1.61":{"id":61,"subnet":1,"channels":{"1":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":67,"device":"[Circular ~.sender.bus.devices.1.61]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":5,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":617,"domain":null,"_events":{},"_eventsCount":1},"1.22":{"id":22,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":1109,"domain":null,"_events":{},"_eventsCount":1},"1.142":"[Circular ~.sender]","1.102":{"id":102,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":162,"domain":null,"_events":{},"_eventsCount":1},"1.80":{"id":80,"subnet":1,"channels":{"8":{"level":0,"device":"[Circular ~.sender.bus.devices.1.80]","number":8,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1},"1.144":{"id":144,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":321,"domain":null,"_events":{},"_eventsCount":1},"1.141":{"id":141,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.56":{"id":56,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.70":{"id":70,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":854,"domain":null,"_events":{},"_eventsCount":1},"1.140":{"id":140,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":323,"domain":null,"_events":{},"_eventsCount":1},"1.100":{"id":100,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":167,"domain":null,"_events":{},"_eventsCount":1},"1.1":{"id":1,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.55":{"id":55,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.81":{"id":81,"subnet":1,"channels":{"1":{"level":100,"device":"[Circular ~.sender.bus.devices.1.81]","number":1,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1}},"domain":null,"_events":{"command":[null,null],"broadcast":[null,null]},"_eventsCount":2},"type":308,"domain":null,"_events":{},"_eventsCount":1},"type":"command","_msgid":"79151dfc.6229f4"}

Here is a command message switching of the Universal switch 64 of my logic module with adresse 22.

{"topic":"255.255","payload":"{ switch: 64, status: false }","sender":{"id":22,"subnet":1,"channels":{},"bus":{"id":99,"type":65534,"subnet":1,"address":[0,0,0,0],"port":6000,"gateway":"192.168.10.250","socket":"[internal]","devices":{"1.23":{"id":23,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":3047,"domain":null,"_events":{},"_eventsCount":1},"255.255":{"id":255,"subnet":255,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.60":{"id":60,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.60]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":80,"device":"[Circular ~.sender.bus.devices.1.60]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":5,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":80,"device":"[Circular ~.sender.bus.devices.1.60]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":600,"domain":null,"_events":{},"_eventsCount":1},"1.62":{"id":62,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":2,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":4,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":100,"device":"[Circular ~.sender.bus.devices.1.62]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":621,"domain":null,"_events":{},"_eventsCount":1},"1.61":{"id":61,"subnet":1,"channels":{"1":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":67,"device":"[Circular ~.sender.bus.devices.1.61]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":5,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":617,"domain":null,"_events":{},"_eventsCount":1},"1.22":"[Circular ~.sender]","1.142":{"id":142,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.102":{"id":102,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":162,"domain":null,"_events":{},"_eventsCount":1},"1.80":{"id":80,"subnet":1,"channels":{"8":{"level":100,"device":"[Circular ~.sender.bus.devices.1.80]","number":8,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1},"1.144":{"id":144,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":321,"domain":null,"_events":{},"_eventsCount":1},"1.141":{"id":141,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.56":{"id":56,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.70":{"id":70,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":854,"domain":null,"_events":{},"_eventsCount":1},"1.140":{"id":140,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":323,"domain":null,"_events":{},"_eventsCount":1},"1.100":{"id":100,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":167,"domain":null,"_events":{},"_eventsCount":1},"1.1":{"id":1,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.55":{"id":55,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.81":{"id":81,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.81]","number":1,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1}},"domain":null,"_events":{"command":[null,null],"broadcast":[null,null]},"_eventsCount":2},"type":1109,"domain":null,"_events":{},"_eventsCount":1},"type":"command","_msgid":"8c922cd9.0aa94"}

and the logic module answering back that universal switch 64 is off

{"topic":"255.255","payload":"{ switch: 64, status: false }","sender":{"id":22,"subnet":1,"channels":{},"bus":{"id":99,"type":65534,"subnet":1,"address":[0,0,0,0],"port":6000,"gateway":"192.168.10.250","socket":"[internal]","devices":{"1.23":{"id":23,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":3047,"domain":null,"_events":{},"_eventsCount":1},"255.255":{"id":255,"subnet":255,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.141":{"id":141,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.60":{"id":60,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.60]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":0,"device":"[Circular ~.sender.bus.devices.1.60]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":0,"device":"[Circular ~.sender.bus.devices.1.60]","number":5,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":80,"device":"[Circular ~.sender.bus.devices.1.60]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":600,"domain":null,"_events":{},"_eventsCount":1},"1.62":{"id":62,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":2,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":4,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":100,"device":"[Circular ~.sender.bus.devices.1.62]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":621,"domain":null,"_events":{},"_eventsCount":1},"1.61":{"id":61,"subnet":1,"channels":{"1":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":70,"device":"[Circular ~.sender.bus.devices.1.61]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":5,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":617,"domain":null,"_events":{},"_eventsCount":1},"1.144":{"id":144,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":321,"domain":null,"_events":{},"_eventsCount":1},"1.70":{"id":70,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":854,"domain":null,"_events":{},"_eventsCount":1},"1.81":{"id":81,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1},"1.80":{"id":80,"subnet":1,"channels":{"8":{"level":0,"device":"[Circular ~.sender.bus.devices.1.80]","number":8,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1},"1.102":{"id":102,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":162,"domain":null,"_events":{},"_eventsCount":1},"1.22":"[Circular ~.sender]","1.100":{"id":100,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":167,"domain":null,"_events":{},"_eventsCount":1},"1.1":{"id":1,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.56":{"id":56,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.142":{"id":142,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.55":{"id":55,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1}},"domain":null,"_events":{"command":[null,null],"broadcast":[null,null]},"_eventsCount":2},"type":1109,"domain":null,"_events":{},"_eventsCount":1},"type":"broadcast","_msgid":"ab665501.edc808"}

Here is a typical message that needs to be filtered out that comes alot witch i dont know what is but the id number is for my security module.

{"topic":"255.255","payload":"0100","sender":{"id":23,"subnet":1,"channels":{},"bus":{"id":99,"type":65534,"subnet":1,"address":[0,0,0,0],"port":6000,"gateway":"192.168.10.250","socket":"[internal]","devices":{"1.23":"[Circular ~.sender]","255.255":{"id":255,"subnet":255,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.60":{"id":60,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.60]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":46,"device":"[Circular ~.sender.bus.devices.1.60]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":100,"device":"[Circular ~.sender.bus.devices.1.60]","number":5,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":80,"device":"[Circular ~.sender.bus.devices.1.60]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":600,"domain":null,"_events":{},"_eventsCount":1},"1.62":{"id":62,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":2,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.62]","number":4,"domain":null,"_events":{},"_eventsCount":0},"6":{"level":100,"device":"[Circular ~.sender.bus.devices.1.62]","number":6,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":621,"domain":null,"_events":{},"_eventsCount":1},"1.61":{"id":61,"subnet":1,"channels":{"1":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":1,"domain":null,"_events":{},"_eventsCount":0},"2":{"level":67,"device":"[Circular ~.sender.bus.devices.1.61]","number":2,"domain":null,"_events":{},"_eventsCount":0},"3":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":3,"domain":null,"_events":{},"_eventsCount":0},"4":{"level":0,"device":"[Circular ~.sender.bus.devices.1.61]","number":4,"domain":null,"_events":{},"_eventsCount":0},"5":{"level":100,"device":"[Circular ~.sender.bus.devices.1.61]","number":5,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":617,"domain":null,"_events":{},"_eventsCount":1},"1.22":{"id":22,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":1109,"domain":null,"_events":{},"_eventsCount":1},"1.142":{"id":142,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.102":{"id":102,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":162,"domain":null,"_events":{},"_eventsCount":1},"1.80":{"id":80,"subnet":1,"channels":{"8":{"level":0,"device":"[Circular ~.sender.bus.devices.1.80]","number":8,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1},"1.144":{"id":144,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":321,"domain":null,"_events":{},"_eventsCount":1},"1.141":{"id":141,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":308,"domain":null,"_events":{},"_eventsCount":1},"1.56":{"id":56,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.70":{"id":70,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":854,"domain":null,"_events":{},"_eventsCount":1},"1.140":{"id":140,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":323,"domain":null,"_events":{},"_eventsCount":1},"1.100":{"id":100,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":167,"domain":null,"_events":{},"_eventsCount":1},"1.1":{"id":1,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":null,"domain":null,"_events":{},"_eventsCount":1},"1.55":{"id":55,"subnet":1,"channels":{},"bus":"[Circular ~.sender.bus]","type":134,"domain":null,"_events":{},"_eventsCount":1},"1.81":{"id":81,"subnet":1,"channels":{"1":{"level":0,"device":"[Circular ~.sender.bus.devices.1.81]","number":1,"domain":null,"_events":{},"_eventsCount":0}},"bus":"[Circular ~.sender.bus]","type":430,"domain":null,"_events":{},"_eventsCount":1}},"domain":null,"_events":{"command":[null,null],"broadcast":[null,null]},"_eventsCount":2},"type":3047,"domain":null,"_events":{},"_eventsCount":1},"type":"broadcast","_msgid":"1430655f.812c8b"}

Hope this helps you in some way.

0 Likes

#11

I will check those messages you just shared. Copying a full message is easy. Find it in the debug panel and then click in the small icon indicated. Afterward, you can paste to a text editor.

r-01

0 Likes

#12

It is commands for turning on and of relays, dimmers, Universal switches, tempratures, motion detectors and so on.
No need to uptate every second but the way the HDL buspro works is that it is to my understanding a rs485 bus where everyting talks to each other by the rs485 and the HDL ip module sends everything on the bus to UDP port 6000 witch is the port used for control from external devices and also for programing the devices.

The way the node-red-contrib-hdl node. works is that everything sendt on the port comes out as messages (i think). To reduce the amount of messages the output node would have to be changed but i dont know how to do that or if i need to.

0 Likes

#13

Is it safe to assume that you will process in the function nodes only messages that have msg.type = "broadcast" ?

If that is the case it is useless to forward function nodes messages that are of another type. As a "quick win" You can use a single switch node after the HDL node just to filter messages. The configuration of the switch node would be like:

r-01

0 Likes

#14

Yes copied it that way but was thinking about a way to copy everything in the debug console. Yes will only use broadcast messages.

0 Likes

#15

Perhaps you want to try this other path. This solution is "smaller" and easier to maintain (assuming it is working or will be fixed if not).

You should add to your Node-RED flow, after the HDL node, the nodes that are shown in the second "line" of the picture.

The switch named sender id-type has to be amended to include all you sender ids and sender types.`

If the solution works you will not add a function for each device, only a line in the switch that I mentioned before. Each line added will add an output in the switch node. This output will give you the "level" property stored in msg.payload

[{"id":"f3532a89.51f868","type":"tab","label":"HDL - Payload Split","disabled":false,"info":""},{"id":"e254694c.13ce78","type":"inject","z":"f3532a89.51f868","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":200,"wires":[["c558898f.8d0ee8"]]},{"id":"111c8090.584b3f","type":"switch","z":"f3532a89.51f868","name":"filter broadcast","property":"type","propertyType":"msg","rules":[{"t":"eq","v":"broadcast","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":160,"y":320,"wires":[["d8d30b43.018298"]]},{"id":"13ed3bc2.376a04","type":"debug","z":"f3532a89.51f868","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"level","x":780,"y":280,"wires":[]},{"id":"c558898f.8d0ee8","type":"function","z":"f3532a89.51f868","name":"Dataset","func":"msg = \n{\n    \"topic\": \"255.255\",\n    \"payload\": \"{ channel: 2, success: true, level: 80 }\",\n    \"sender\": {\n        \"id\": 60,\n        \"subnet\": 1,\n        \"channels\": {\n            \"1\": {\n                \"level\": 0,\n                \"device\": \"[Circular ~.sender]\",\n                \"number\": 1,\n                \"domain\": null,\n                \"_events\": {},\n                \"_eventsCount\": 0\n            },\n            \"2\": {\n                \"level\": 46,\n                \"device\": \"[Circular ~.sender]\",\n                \"number\": 2,\n                \"domain\": null,\n                \"_events\": {},\n                \"_eventsCount\": 0\n            },\n            \"3\": {\n                \"level\": 100,\n                \"device\": \"[Circular ~.sender]\",\n                \"number\": 3,\n                \"domain\": null,\n                \"_events\": {},\n                \"_eventsCount\": 0\n            },\n            \"4\": {\n                \"level\": 100,\n                \"device\": \"[Circular ~.sender]\",\n                \"number\": 4,\n                \"domain\": null,\n                \"_events\": {},\n                \"_eventsCount\": 0\n            },\n            \"5\": {\n                \"level\": 100,\n                \"device\": \"[Circular ~.sender]\",\n                \"number\": 5,\n                \"domain\": null,\n                \"_events\": {},\n                \"_eventsCount\": 0\n            },\n            \"6\": {\n                \"level\": 80,\n                \"device\": \"[Circular ~.sender]\",\n                \"number\": 6,\n                \"domain\": null,\n                \"_events\": {},\n                \"_eventsCount\": 0\n            }\n        },\n        \"bus\": {\n            \"id\": 99,\n            \"type\": 65534,\n            \"subnet\": 1,\n            \"address\": [\n                0,\n                0,\n                0,\n                0\n            ],\n            \"port\": 6000,\n            \"gateway\": \"192.168.10.250\",\n            \"socket\": \"[internal]\",\n            \"devices\": {\n                \"1.23\": {\n                    \"id\": 23,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 3047,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"255.255\": {\n                    \"id\": 255,\n                    \"subnet\": 255,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": null,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.60\": \"[Circular ~.sender]\",\n                \"1.62\": {\n                    \"id\": 62,\n                    \"subnet\": 1,\n                    \"channels\": {\n                        \"1\": {\n                            \"level\": 0,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.62]\",\n                            \"number\": 1,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        },\n                        \"2\": {\n                            \"level\": 0,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.62]\",\n                            \"number\": 2,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        },\n                        \"4\": {\n                            \"level\": 0,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.62]\",\n                            \"number\": 4,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        },\n                        \"6\": {\n                            \"level\": 100,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.62]\",\n                            \"number\": 6,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        }\n                    },\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 621,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.61\": {\n                    \"id\": 61,\n                    \"subnet\": 1,\n                    \"channels\": {\n                        \"1\": {\n                            \"level\": 100,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.61]\",\n                            \"number\": 1,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        },\n                        \"2\": {\n                            \"level\": 67,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.61]\",\n                            \"number\": 2,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        },\n                        \"3\": {\n                            \"level\": 0,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.61]\",\n                            \"number\": 3,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        },\n                        \"4\": {\n                            \"level\": 0,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.61]\",\n                            \"number\": 4,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        },\n                        \"5\": {\n                            \"level\": 100,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.61]\",\n                            \"number\": 5,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        }\n                    },\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 617,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.22\": {\n                    \"id\": 22,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 1109,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.142\": {\n                    \"id\": 142,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 308,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.102\": {\n                    \"id\": 102,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 162,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.80\": {\n                    \"id\": 80,\n                    \"subnet\": 1,\n                    \"channels\": {\n                        \"8\": {\n                            \"level\": 0,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.80]\",\n                            \"number\": 8,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        }\n                    },\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 430,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.144\": {\n                    \"id\": 144,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 321,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.141\": {\n                    \"id\": 141,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 308,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.56\": {\n                    \"id\": 56,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 134,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.70\": {\n                    \"id\": 70,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 854,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.140\": {\n                    \"id\": 140,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 323,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.100\": {\n                    \"id\": 100,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 167,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.1\": {\n                    \"id\": 1,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": null,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.55\": {\n                    \"id\": 55,\n                    \"subnet\": 1,\n                    \"channels\": {},\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 134,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                },\n                \"1.81\": {\n                    \"id\": 81,\n                    \"subnet\": 1,\n                    \"channels\": {\n                        \"1\": {\n                            \"level\": 0,\n                            \"device\": \"[Circular ~.sender.bus.devices.1.81]\",\n                            \"number\": 1,\n                            \"domain\": null,\n                            \"_events\": {},\n                            \"_eventsCount\": 0\n                        }\n                    },\n                    \"bus\": \"[Circular ~.sender.bus]\",\n                    \"type\": 430,\n                    \"domain\": null,\n                    \"_events\": {},\n                    \"_eventsCount\": 1\n                }\n            },\n            \"domain\": null,\n            \"_events\": {\n                \"command\": [\n                    null,\n                    null\n                ],\n                \"broadcast\": [\n                    null,\n                    null\n                ]\n            },\n            \"_eventsCount\": 2\n        },\n        \"type\": 600,\n        \"domain\": null,\n        \"_events\": {},\n        \"_eventsCount\": 1\n    },\n    \"type\": \"broadcast\",\n    \"_msgid\": \"4a22c7dc.637ab8\"\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":240,"y":200,"wires":[["111c8090.584b3f"]]},{"id":"b72dd349.5912a","type":"switch","z":"f3532a89.51f868","name":"sender id-type","property":"hash","propertyType":"msg","rules":[{"t":"eq","v":"60-600","vt":"str"},{"t":"eq","v":"61-600","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":580,"y":320,"wires":[["13ed3bc2.376a04"],["98b1dacb.636dd8"]]},{"id":"d8d30b43.018298","type":"function","z":"f3532a89.51f868","name":"Build hash and store level","func":"msg.hash = msg.sender.id.toString() + \"-\" + msg.sender.type.toString();\n\nlet a = msg.payload.split(\" \");\n    if ( (a[3] == \"success:\") && (a[4] === \"true,\") && (a[2] == \"2,\")  )\n    {\n      msg.level = Number(msg.payload = a[6]);\n    }\n    \nreturn msg;","outputs":1,"noerr":0,"x":370,"y":320,"wires":[["b72dd349.5912a"]]},{"id":"98b1dacb.636dd8","type":"debug","z":"f3532a89.51f868","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"level","x":780,"y":320,"wires":[]}]
0 Likes

#16

Why do you need to test against "success"?
Surely the state will be either success: true or success: false?

Also, have you considered fixing the bad json, and then parsing it. Something like:

if ((msg.type == "broadcast")&&(Number(msg.sender.id == 60))&&(Number(msg.sender.type = 617))) {
            var a = msg.payload.replace((/([\w]+)(:)/g), "\"$1\"$2");
            var b = JSON.parse(a.replace((/'/g), "\""));
              if ((b.success === true)&&(b.channel === 2)){
                Number(msg.payload = (b.level));
                }
        }
return msg;
[{"id":"a105fff1.66348","type":"function","z":"c53060.842a0fa","name":"","func":"            var a = msg.payload.replace((/([\\w]+)(:)/g), \"\\\"$1\\\"$2\");\n            var b = JSON.parse(a.replace((/'/g), \"\\\"\"));\n              if ((b.success === true)&&(b.channel === 1)){\n                Number(msg.payload = (b.level));\n                }\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":1290,"wires":[["f0a5ba0d.383ec8"]]},{"id":"9d0b5eae.cb47a","type":"inject","z":"c53060.842a0fa","name":"","topic":"","payload":"{ channel: 1, success: true, level: 66 }","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":1290,"wires":[["a105fff1.66348"]]},{"id":"f0a5ba0d.383ec8","type":"debug","z":"c53060.842a0fa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":510,"y":1290,"wires":[]}]
0 Likes

#17

Thanks Andrei.
Not working correct but this is absolutely the bether way of doing what i want.

Was a bit confused at first by where you got the value 600 i had only seen 617 before. But realised that i have 2 different dimmer versions. I tought initially that type 617 was just a dimmer command, but realise now that it refers to different hardware revisions.

Your path works great for channel 2 on the dimmers. But for channel 1,3,4,5,6 it shows for number 6: "{ channel: 6, success: true, level: 80 }"

My dimmers have 6 channels so in effect it is 6 dimmers in one. channel in the payload is the dimmer id.

Have tried working with your path and adding a hash for channel in between msg.sender.id and msg.sender.type. But have not managed to do it because of the way i split the payload and identified the channel number i get a "," after the channel nr.
se line 4 end in the build hash and store level function for where i originaly got channel number 2.

Have attached a revised path so that you can see the messages out for each of the dimmer channels. Where each input should go to the oposite debug only. Try injecting the 2 channel and it works only on all 6. and if you try the 1 you see the 2 problem.

export flow.txt (163.5 KB)

Thanks again

0 Likes

#18

Good, let´s fix the flow then. A question before: Do you have any control over how the payload property is generated? For example: "payload": "{ channel: 3, success: true, level: 80 }"

I ask this question because a few things could be optimized simplified if we had a payload with the properties between quotes:

"payload": "{ "channel": 3, "success": true, "level": 80 }",

0 Likes

#19

Is that;

payload: "{ "channel": 3, "success": true, "level": 80 }"
0 Likes

#20

I have no control over how the payload is generated. I agree it would have been simpler if only the level was in the payload and channel and success had its separate variables.
Would have to change the way the node plugin works to do that. And i have no idea if that is possible or how to do that.
https://flows.nodered.org/node/node-red-contrib-hdl

0 Likes