Cleanest way of setting and else clause? how do you set it?

for example, I have this flow. If first condition is true and either second or third are false, then Set serial, otherwise Set off.

The only way I think of making the else is by drawing a couple of lines

This is no big deal in this particular flow but there are other cases where the else implies binding lots of nodes… How do you guys deal with this?

When all conditions are and or or the trigger: state node does the trick, but when there’s a mix of and and or conditions, this problem usually arises.

I use render template. I don’t have an example of multiple else but there is in ha templates

{% set state = states('sensor.hallway_lux') %}
{% if is_number(state) and state | float < 50 and
is_state('binary_sensor.xvr_second_floor_motion', 'on') %}
on
{%-else %}off{% endif %}

If you’re concerned with speed personally I wouldn’t recommend the render template node as it makes a call to HA on every input. Where most other nodes use cached states of entities.

1 Like

It could all be hidden inside a function node also.

I use functions with plain java a lot…

Hopefully somebody will bring an alternative without java nor render template. Otherwise function node seems to be the best alternative…

I use helpers, A LOT.

It gives a cleaner look in node red, but then you need to maintain helpers. So pick your poison I guess…

Using your example I would create a dedicated HELPERS page in node red and set it up to say if both PIR B & P are true, turn on helper. If either are false, turn helper off.

Then in your flow you posted it would just be below. Condensing 2 nodes into 1 helper isnt a big deal, but like you said if your checking 5,6,7 nodes at once, a single helper would be a cleaner visual.

Alternativelty, if you want to keep everything localized in node red you can create a subflow which would in essence still have the same logic as your HELPER page. Then the PIR HELPER OFF? node would just be replaced by a single subflow node.

image

I appreciate your suggestion, although it feels like moving the garbage under the carpet. I believe I’ll do the subflow suggestion though, thanks again.

I’m hoping to find something a la the complete node, something like: if the flow starts and doesn’t reach these point/points, continue somewhere else. This way if for example a flow has 15 conditonal nodes, one pointing to option A and fourteen pointing to option B, just draw option A and set the else without drawing too many lines… I believe what I want doesn’t exist…

1 Like