# Function block to combine 2 analogue signals

**URL:** <https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836>\
**Category:** General\
**Created:** [23 January 2025 08:35 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836 "2025-01-23T08:35:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![SomersetSmartHome](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@SomersetSmartHome](https://discourse.nodered.org/u/SomersetSmartHome)\
**Post date:** [23 January 2025 08:35 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836/1 "2025-01-23T08:35:01Z")

</div>

I have a heating schedule with various set points during the day.

I want the option to manually override the current set point if required. This value will come from a different device.

I need a function block which takes these 2 inputs and outputs the value which has changed most recently.

Any thoughts how I can do this please?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 January 2025 08:57 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836/2 "2025-01-23T08:57:26Z")

</div>

Add Filter nodes to each of the two inputs so that you only get a message when the value changes. Then you can just feed the wires to the next node.

[Edit] In fact you may not need the Filter nodes, you only need them if messages with repeated values arrive down the wires.

---

<div class="post-metadata">

**Author:** ![SomersetSmartHome](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@SomersetSmartHome](https://discourse.nodered.org/u/SomersetSmartHome)\
**Post date:** [23 January 2025 10:18 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836/3 "2025-01-23T10:18:35Z")

</div>

Thanks, Colin, the filter block looks perfect.

So I can just connect the outputs of 2 filter blocks together and that works? I trained as a hardware engineer originally and I'm still adjusting to combining outputs together...

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 January 2025 11:39 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836/4 "2025-01-23T11:39:40Z")

</div>

If the messages come independently (from separate sources), you can use the join node.

e.g.

```auto
event data 1 ---> add topic "v1" ---+---> Join ---> Use msg.payload.v1 and msg.payload.v2
event data 2 ---> add topic "v2" ---^

```

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

If you make a request for values, you can simply put stuff in series and add extra properties to the msg or payload.

e.g. `inject -> get value 1 -> copy payload to msg.v1 -> get value 2 -> copy payload to msg.v2 -> use msg.v1 and msg.v2` (in some logic node).

In short, you be able to use 2 values in some kind of comparison or logic, they should be in the same msg.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 January 2025 11:55 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836/5 "2025-01-23T11:55:21Z")

</div>

The OP just wants to pass on whichever message arrived most recently.

No need for filter, join or function nodes, just wire it up.

A junction node (does nothing)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1e3a670d996514751a45fc53e2722890e2b8c979.png)

Or

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/04df0689dde92feb1309f77993a23c5da69584a4.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 January 2025 14:23 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836/6 "2025-01-23T14:23:24Z")

</div>

> [@jbudd](#):
>
> No need for filter,

The filter is needed if the incoming messages may be repeated. The OP asked for them to be used only if the value changed.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 January 2025 14:33 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836/7 "2025-01-23T14:33:32Z")

</div>

I guess it's safe to assume that the "override" input can be passed on whenever it is entered by the user.  
There may well be extra complexity if the "normal" input arrives every few minutes, in which case a filter may indeed be necessary to prevent it from overriding the override.  
I assumed that "Normal" inputs would only arrive at the specified hours eg 16:00: 22, 22:00: 17, ... and in that case any normal input would override an earlier "override" input.

The original question is not a complete description of the requirement imho (sorry!).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 January 2025 15:04 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836/8 "2025-01-23T15:04:46Z")

</div>

> [@jbudd](#):
>
> The original question is not a complete description of the requirement imho

True, but my suggestion is a complete solution to the problem as described.

---

<div class="post-metadata">

**Author:** ![SomersetSmartHome](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@SomersetSmartHome](https://discourse.nodered.org/u/SomersetSmartHome)\
**Post date:** [26 January 2025 10:50 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836/9 "2025-01-26T10:50:29Z")

</div>

Turns out the Tuya TRV value sometimes gets through even though it hasn't changed; I set up a WhatsApp to be sent on every 'change' and this peaked at 120 messages in one minute, all with the same value. (It then didn't see a 'change' for 4 hours. Odd)

Adding the Filter block as @jbudd suggested has stopped that. Only real changes get through now.

It's only been running a short while, but so far, its perfect.

Thanks to everyone who replied.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 April 2025 10:50 UTC](https://discourse.nodered.org/t/function-block-to-combine-2-analogue-signals/94836/10 "2025-04-26T10:50:49Z")

</div>

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