Saw-tooth to rectangular function / create additional message

Sorry if this is a beginner question, but I have the following situation:

A KNX message is received everytime a binary switch changes its value, i.e. toggles between on and off. When displaying these on or off status in a dashboard line chart, obviously and correctly a saw-tooth pattern results, with diagonal lines between the 0 and the 1 state.

However, this does not reflect the binary nature and makes it difficult to immediately and intuitively see in which periodes the switch was on or off. What I want is a rectangular shape with a horizontal line at 1 for on and at 0 for off.

My thought was that I would simply need to add an additional data point each time a new state arrives. For example, the state is 0 since quite a time and a 1 is received, I would add a 0, so the line chart represents the old and the new 0 value and immediately after I would give the 1 resulting in the almost-vertical rise to state 1. Perfect representation of the switch values.

But how do I do this in NodeRed? I need a node that can create one additional message and passes on the original message very close after each other (otr maybe it works consecutive at the same time).

Assuming you are using the standard dashboard chart then set the Interpolate field in the config to Step.

Wow, perfect, they even thought of this. Sorry for the stupid question, I didn't even had the idea that they might have programmed that. Fantastic! Solved.

But, anyway, would there have been a solution like mine? Duplicating message with changed payload?

Yes, you could do that in a function node, saving the previous value in the node context then each time a new value comes in send the previous one first. The node red docs page Writing Functions tells you how to use the node context.

Hm, I can simply use then inverted state without memorising the previous state, but I cannot figure out how to make one function return two messages.

See the docs https://nodered.org/docs/user-guide/writing-functions

That is ok, provided you can absolutely guarantee you will only get a message on a state change which may be true in your case. Personally I wouldn't do that though, it is called defensive programming.

Yeah, your are right and I agree from a programmer's point of view. However, in this case the KNX actor can be set to send a message only on change.

Anyway, your answer with "interpolate: step" solved then issue in a perfect way, so now I am just curious how I could produce two messages from one incoming message.

Have you read the guide Dave linked to?

Sorry, got distracted by the "store in context" issue. Yes, I now processed the multiple output options. This solved the issue. I could implement everything I wanted.

Thanks again!

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