If Switch Node CONTAINS a string clarification

I have a node red flow that checks if the payload CONTAINS the word ‘Game’ to continue the flow if found. However, the sensor attached to it will report different results (for example, it will say Game (Playstation) or Game (Steam)). Now, in the Events: State node it says Ignore if current state equals previous state. Will those 2 options stated above trigger a state change? Even if the switch node specifies ‘Contains’? Because the keyword that the flow is looking for is the same (Game), but the string afterwards changes. I do not want it to trigger a change based on the 2nd part of the string.

Flow attached for clarification:

[{"id":"afcb7ac9e2cc828a","type":"switch","z":"9bc82eaf8e96bc0d","name":"Options","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"TV/HDMI","vt":"str"},{"t":"cont","v":"MiniPC","vt":"str"},{"t":"cont","v":"Nvidia Shield","vt":"str"},{"t":"cont","v":"Game","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":5,"x":740,"y":300,"wires":[["687d30e28f011a4f"],[],["7c86942b88e75b43"],["cd6d1c4a88f31d22"],[]]},{"id":"27e5560a3cca5bb4","type":"server-state-changed","z":"9bc82eaf8e96bc0d","name":"Samsung Frame TV Source","server":"b3afb4a3.474b18","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"sensor.samsung_frame_tv_dynamic_source","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"audiomode","propertyType":"msg","value":"","valueType":"str"}],"x":240,"y":300,"wires":[["afcb7ac9e2cc828a","7b89f5a8f03cfcf7"]]},{"id":"b3afb4a3.474b18","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"25","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"","statusYear":"hidden","statusMonth":"hidden","statusDay":"numeric","statusHourCycle":"h12","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

I do not want it to trigger a change based on the 2nd part of the string.

Can you post the incoming message that you are trying to filter?

“Game (Playstation)” and “Game (Steam)” are different states, so the events: state node will fire if it changes from one to the other.

If you want to prevent the flow from proceeding, you could use a change node to set another message property to the part you’re after (eg. “Game” in this case), and then use a filter node to block the flow unless that property changes. The change could use $substringBefore(payload, " ") for the game examples, but I don’t know the full format of the others to know if it would work for them too.

Of course you could alternatively do the above in a template sensor in HA which just extracts the part you’re interested in, and then update your events: state node to use that instead. This is probably the way I’d go, because I like to see these computed values to ensure they’re working as I expect.

1 Like

this is the best option to go. Actually this was my first version of the sensor, but I wanted to make a catch all for sources for all my devices. I may revert back to avoid a state change issue.