Flow for State-Change notification - question

Hello there!

I wanted to make a notification flow, that gets the average electricity price aep from a sensor and compares that to the current electricity price cep from another sensor.
This flow sends a notification to my phone on every run (once per hour) about the current price and if the price is below or above average. So far so good, i have got that part working.

This is fine, but 24 notifications a day are quite annoying if it would suffice to get a notification only if the price falls below or rises above the average price.

what i want is the following.

i want to modify the flow to check the price (maybe every 5 minutes) but only notifies me once the cep falls below aep and also once the cep rises obove the aep.

if, for example, the cep was below the aep the last time the flow was running (i.e. run 1 cep = 0.292 aep 0.310) and is below the aep again (i.e.run 2 cep 0.298 aep 0.310), i dont want to get notified.

Basically i only want to get notified if the state changes from cep < aep to cep > aep or cep > aep to cep < aep.

How would i get this state-change-part to work?
I dont want a "drop in solution" from you guys, but a hint in the right direction.

i have no expirience in this stuff, but i want to get a grasp on it an learn, so if someone can come up with a viable idea i am all ears :wink:

I am also fine with the right "searchterm" for the Forum-Search-Function

thanks for your time

(btw, sry if i butchered the english language, obviously it is not my fist language)

You can use the combination of "switch" node and "filter" node.

  • The switch node outputs "true" or "false" info by comparing "aep" and "cep".

  • The filter node blocks the output unless the status changes from the last time.

Hi there,

This depends on whether the sensors data in is one msg, or in individual msgs.

If both are in a single msg you can use a function node and context to retrieve the previous state (greater, less than, equal) compare that to the current state, with an output that indicates a change (or not). - use context.set to save the current state and a default value when you use context.get the first time as there will be no previous value

If individual msgs you will also need to save the current cep or aep to context, then retrieve both from context and compare them to get a current state.

This is a very basic outline but the idea is that you can do what you are after by saving values to context. There are lots of entries in the forum explaining the use of context, flow & global to save data

Yes. If there are two messages coming from two sensors, then you need to combine the messages with context.set, context.get or flow.set, flow.get methods. Then followed by the switch node and filter node.

thank you for your suggestion!
this nudged me in the right direction.
I used just the filter node and put it right in front of my notify-node.
this way I could filter the payload.data.title (in my case it changes, depending if the price is above or below average)

here a screenshot of the complete flow:

thank you again!

and thanks for the other suggestion @Buckskin

1 Like

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