# Values changing

**URL:** <https://discourse.nodered.org/t/values-changing/59131>\
**Category:** General\
**Created:** [28 February 2022 15:32 UTC](https://discourse.nodered.org/t/values-changing/59131 "2022-02-28T15:32:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herbert](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@Herbert](https://discourse.nodered.org/u/Herbert)\
**Post date:** [28 February 2022 15:32 UTC](https://discourse.nodered.org/t/values-changing/59131/1 "2022-02-28T15:32:37Z")

</div>

Hello experts,

I have a question about MQTT value changes.

My photovoltaik (PV) system is displayes in green, the load from house in red.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/274e451dce1f81acf7f9e885296cc95860cba1fa.png)

You can see the load starts ab 1500W and go ahead...  
At Time 14:29 the load decrease, then the PV power also. If the load increase, the PV power also increase.

In the end let me say if both values increase within 10 seconds, and this "feature" is more than 3 times within 30 minutes, I will start a trigger. I cannot say how much the increases or decreses are. It is depending on battery SOC, PV power, load,... And I have no idea how Nodered can handle it. But I´m sure somebody have a solution. 🙂

Here detailed with 2 values increase and decrease:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/6/560d0a4e6cf21e139b97b03cfd33ce959ac3d408.png)

Thank you in advance and best regards

---

<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:** [28 February 2022 15:47 UTC](https://discourse.nodered.org/t/values-changing/59131/2 "2022-02-28T15:47:13Z")

</div>

Node red can handle it if you can come up with a _precise_ requirement for what you want to do.  
Remember that any measurement is likely to have some random fluctuation, so using words like 'increase' is meaningless unless you can say exactly what you mean by that.

---

<div class="post-metadata">

**Author:** ![Herbert](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@Herbert](https://discourse.nodered.org/u/Herbert)\
**Post date:** [8 March 2022 16:41 UTC](https://discourse.nodered.org/t/values-changing/59131/3 "2022-03-08T16:41:39Z")

</div>

Hello. OK will I try to define it better. Both values are variables from 0 to 10000 and change every 5 seconds.  
If the red value increase (from exist value) more than 300 and within 20 seconds the green value increase more than 200 then send start a trigger for 1 minute.

So I have 12 green values and 12 red values in 1 minute. Per day I have approx. this diagram for better understanding:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/01e911ad24a3fb5c7c600f69cca62bfec0a3967d.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:** [8 March 2022 17:17 UTC](https://discourse.nodered.org/t/values-changing/59131/4 "2022-03-08T17:17:45Z")

</div>

> [@Herbert](#):
>
> If the red value increase (from exist value) more than 300

Do you mean that when one sample is more than 300 greater than the previous?

> [@Herbert](#):
>
> within 20 seconds the green value increase more than 200

Do you mean that the value at the start of the window must be captured and the total of 200 increase must be within 20 seconds, or do you mean that there must be a sample to sample increase of 200 within the 20 seconds?

What happens if the red line keeps increasing for several samples? Does the 20 second keep restarting or is it just extended?

What happens if the red line increases by the threshold, so the 20 seconds starts, then the red line dips for 15 seconds and then goes back up again. What happens to the window then?

> [@Herbert](#):
>
> then send start a trigger for 1 minute.

> [@Herbert](#):
>
> then send start a trigger for 1 minute

I don't understand what you mean by that. Do you mean send a start message, then a minute later send a stop message? If so then again there are questions about what happens when things keep increasing (or start increasing again) during that minute, what happens then? It is necessary to try and think of all these eventualities before you build it.

---

<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:** [8 March 2022 17:31 UTC](https://discourse.nodered.org/t/values-changing/59131/5 "2022-03-08T17:31:19Z")

</div>

Is it always the load which increases first, or could it be PV power first then load?

---

<div class="post-metadata">

**Author:** ![Herbert](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@Herbert](https://discourse.nodered.org/u/Herbert)\
**Post date:** [8 March 2022 18:17 UTC](https://discourse.nodered.org/t/values-changing/59131/6 "2022-03-08T18:17:23Z")

</div>

> [@Colin](#):
>
> > [@Herbert](#):
> >
> > If the red value increase (from exist value) more than 300
> 
> Do you mean that when one sample is more than 300 greater than the previous? - YES correct.
> 
> > [@Herbert](#):
> >
> > within 20 seconds the green value increase more than 200
> 
> Do you mean that the value at the start of the window must be captured and the total of 200 increase must be within 20 seconds, or do you mean that there must be a sample to sample increase of 200 within the 20 seconds? SECOND. Sample to sample.
> 
> What happens if the red line keeps increasing for several samples? Does the 20 second keep restarting or is it just extended? - RESTARTING
> 
> What happens if the red line increases by the threshold, so the 20 seconds starts, then the red line dips for 15 seconds and then goes back up again. What happens to the window then? - FOR this issue every 20 seconds there is a restart from a trigger.
> 
> > [@Herbert](#):
> >
> > then send start a trigger for 1 minute.
> 
> > [@Herbert](#):
> >
> > then send start a trigger for 1 minute
> 
> I don't understand what you mean by that. Do you mean send a start message, then a minute later send a stop message? If so then again there are questions about what happens when things keep increasing (or start increasing again) during that minute, what happens then? It is necessary to try and think of all these eventualities before you build it. - TRIGGER Node is here the plan (activate a relay)  
> If the value increse again, maybe there are some clouds away and more pv power can be created or if the red line increase more, there is more load at this time.

I know that this feature is not so easy to understand... Let my try it little different to explain:  
The red "peaks" are something like a load in the house - electrical heater. This electrical heater is active for example 5 minutes. So you can see the normally load from house is 500W. If the electrical heater is on via thermostate and the green PV power increase for the same time (with some seconds delay) I can see my PV battery can´t catch the complete PV power and increase. In this case I will activate an additional heater for warm water (via relay).

I hope it is more clear 🫤

---

<div class="post-metadata">

**Author:** ![Herbert](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@Herbert](https://discourse.nodered.org/u/Herbert)\
**Post date:** [8 March 2022 18:20 UTC](https://discourse.nodered.org/t/values-changing/59131/7 "2022-03-08T18:20:48Z")

</div>

Yes, load increases at first, then the pv power.  
I explained it in previous text. If there is more load, then it could be created more PV power. This is the reason why the green pv power increase also.

---

<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:** [8 March 2022 18:33 UTC](https://discourse.nodered.org/t/values-changing/59131/8 "2022-03-08T18:33:45Z")

</div>

This flow uses a node-red-contrib-simple-gate.  
If either Load or PV increases or decreases by more than a certain amount, the gate is opened for 20 seconds, so a corresponding change in the other measurement will be passed through to the debug output.  
It only notices change between a measurement and the immediately previous one.  
There are sure to be many edge cases where this fails.

 ![Untitled 4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/e/3eb7b9d7b6c96d52d23f32aabece560b0c6d11f0.jpeg)

```auto
[{"id":"0859c4d4a89178b4","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"8fa0819c1f7857c4","type":"group","z":"0859c4d4a89178b4","name":"Detect change between successive Load values","style":{"label":true},"nodes":["ea52375c298fbab8","74ef51bb373691d1","72192ae517ae1ccc","a06b371e17dc272b"],"x":34,"y":39,"w":412,"h":162},{"id":"7ef96c7797edf93a","type":"group","z":"0859c4d4a89178b4","name":"Detect change between successive PV values","style":{"label":true},"nodes":["05d79d29b29f49ff","f612edb98416ed33","f5622a948e6c4875","d37d2ee94a231fa9"],"x":34,"y":319,"w":412,"h":162},{"id":"b52aed442d733c38","type":"group","z":"0859c4d4a89178b4","name":"Open Gate for 20s","style":{"label":true},"nodes":["6662e25bbd0b02e7","769839ee8c2fb5b4"],"x":34,"y":219,"w":412,"h":82},{"id":"ea52375c298fbab8","type":"inject","z":"0859c4d4a89178b4","g":"8fa0819c1f7857c4","name":"Load 1500","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Load","payload":"1500","payloadType":"num","x":140,"y":160,"wires":[["72192ae517ae1ccc"]]},{"id":"3570ef32b448bc4d","type":"gate","z":"0859c4d4a89178b4","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":590,"y":260,"wires":[["6333688fa5432796"]]},{"id":"6662e25bbd0b02e7","type":"trigger","z":"0859c4d4a89178b4","g":"b52aed442d733c38","name":"","op1":"open","op2":"close","op1type":"str","op2type":"str","duration":"20","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":130,"y":260,"wires":[["769839ee8c2fb5b4"]]},{"id":"05d79d29b29f49ff","type":"inject","z":"0859c4d4a89178b4","g":"7ef96c7797edf93a","name":"PV 750","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"PV","payload":"750","payloadType":"num","x":130,"y":440,"wires":[["f612edb98416ed33"]]},{"id":"6333688fa5432796","type":"debug","z":"0859c4d4a89178b4","name":"Do something ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":260,"wires":[]},{"id":"74ef51bb373691d1","type":"inject","z":"0859c4d4a89178b4","g":"8fa0819c1f7857c4","name":"Load 1100","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Load","payload":"1100","payloadType":"num","x":140,"y":80,"wires":[["72192ae517ae1ccc"]]},{"id":"72192ae517ae1ccc","type":"rbe","z":"0859c4d4a89178b4","g":"8fa0819c1f7857c4","name":"Changed by 300?","func":"deadbandEq","gap":"300","start":"","inout":"in","septopics":false,"property":"payload","topi":"topic","x":330,"y":120,"wires":[["6662e25bbd0b02e7","3570ef32b448bc4d"]]},{"id":"769839ee8c2fb5b4","type":"change","z":"0859c4d4a89178b4","g":"b52aed442d733c38","name":"msg.topic = control","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":260,"wires":[["3570ef32b448bc4d"]]},{"id":"f612edb98416ed33","type":"rbe","z":"0859c4d4a89178b4","g":"7ef96c7797edf93a","name":"Changed by 200?","func":"deadbandEq","gap":"200","start":"","inout":"in","septopics":false,"property":"payload","topi":"topic","x":330,"y":400,"wires":[["3570ef32b448bc4d","6662e25bbd0b02e7"]]},{"id":"a06b371e17dc272b","type":"inject","z":"0859c4d4a89178b4","g":"8fa0819c1f7857c4","name":"Load 1250","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Load","payload":"1250","payloadType":"num","x":140,"y":120,"wires":[["72192ae517ae1ccc"]]},{"id":"f5622a948e6c4875","type":"inject","z":"0859c4d4a89178b4","g":"7ef96c7797edf93a","name":"PV 600","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"PV","payload":"600","payloadType":"num","x":130,"y":400,"wires":[["f612edb98416ed33"]]},{"id":"d37d2ee94a231fa9","type":"inject","z":"0859c4d4a89178b4","g":"7ef96c7797edf93a","name":"PV 450","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"PV","payload":"350","payloadType":"num","x":130,"y":360,"wires":[["f612edb98416ed33"]]}]

```

---

<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:** [8 March 2022 18:36 UTC](https://discourse.nodered.org/t/values-changing/59131/9 "2022-03-08T18:36:20Z")

</div>

> [@Herbert](#):
>
> Let my try it little different to explain

We don't need to understand the bigger picture. We need a complete definition of the logic required with all possibilities covered.

---

<div class="post-metadata">

**Author:** ![Herbert](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@Herbert](https://discourse.nodered.org/u/Herbert)\
**Post date:** [8 March 2022 20:10 UTC](https://discourse.nodered.org/t/values-changing/59131/10 "2022-03-08T20:10:54Z")

</div>

Thanks. Let me try it out. It looks good. Tomorrow first test.

---

<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:** [7 May 2022 20:11 UTC](https://discourse.nodered.org/t/values-changing/59131/11 "2022-05-07T20:11:20Z")

</div>

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