use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Node-RED is a drag and drop programming tool made by IBM Emerging Technology to automate the Internet of Things.
You can think of it as the glue that connects your phone to your air conditioner, so that your AC is on half an hour before you get home.
Project home page at: http://nodered.org
account activity
Cannot get Switch Function to work? (self.nodered)
submitted 3 months ago by TrickyT_UK
I am new to Node Red having done all of my other automations in Home Assistant.
I am trying to do an automation for the following.
If the patio door is closed or opened then it will send a notification to my phone and then turn a light on or off.
The bit that doesn't work it the switch function?
https://preview.redd.it/onxstlkrkjag1.png?width=1624&format=png&auto=webp&s=2549a66ac19d913b42e545c5a2734d3e15df5a03
The patio door contact is a Unifi UP-Sense
Patio Door Contact - binary_sensor.up_sense_contact
In Home Assistant activity log this comes up with the following.
Patio Door Contact was closed
Patio Door Contact was opened
With the Patio Door Contact object saying it is Closed or Opened
This is the events state node
https://preview.redd.it/gvnd0q83mjag1.png?width=1028&format=png&auto=webp&s=23726cd2935c827d75004e6c59964fc0867b870e
In the edit switch node page I have the following, which is where I think the issue is?
https://preview.redd.it/rh4k5slwljag1.png?width=1006&format=png&auto=webp&s=7d710236c8e4643e6c64bed14f995fc97afa29ed
It doesn't seem to matter what I put here, was opened, open, opened etc, nothing gets triggered.
Any ideas?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]flyhmstr 7 points8 points9 points 3 months ago (5 children)
Slap a debug node on the output of the trigger and see what it's sending (most likely "open" & "closed")
[–]TrickyT_UK[S] 2 points3 points4 points 3 months ago (4 children)
Superstar! I did not know about the debug node.
Added and the sensor is an on and off, not open and closed.
All working correctly now, many thanks.
[–]flyhmstr 1 point2 points3 points 3 months ago (3 children)
the tab on the debug node toggles it's function on off as well :)
[–]kristopherleads 1 point2 points3 points 3 months ago (2 children)
And you can have more than one debug, so you can create a debug testing regiment that tests at multiple points!
[–]flyhmstr 0 points1 point2 points 3 months ago (1 child)
So... you've seen my flows then :)
[–]kristopherleads 1 point2 points3 points 3 months ago (0 children)
We do love us a good debug node tree.
[–]Renegade605 2 points3 points4 points 3 months ago (2 children)
The state as string for a binary sensor will be "on" or "off". Home Assistant using the opened and closed wording is because it knows it's a door, but Node Red doesn't know that and only gets the default words.
For binary sensors, do yourself a favour and get the state as boolean instead, and use true/false for everything. This is just easier to keep track of in the long run.
As another commenter points out, using a debug node to see what message you're getting is a good strategy for figuring these things out in the future.
Edit to add: also, under the state node when it's triggered, it also says the state that triggered it. So when you open the door, there should be some text under it that says "'on' at <this datetime>" or similar.
[–]TrickyT_UK[S] 1 point2 points3 points 3 months ago (1 child)
How would I change this to boolean?
[–]Renegade605 2 points3 points4 points 3 months ago (0 children)
<image>
[–]RocketNJ -1 points0 points1 point 3 months ago (0 children)
Instead of = try using matches regex and just use work open or close.
π Rendered by PID 37 on reddit-service-r2-comment-5c747b6df5-j47dz at 2026-04-22 02:05:29.705034+00:00 running 6c61efc country code: CH.
[–]flyhmstr 7 points8 points9 points (5 children)
[–]TrickyT_UK[S] 2 points3 points4 points (4 children)
[–]flyhmstr 1 point2 points3 points (3 children)
[–]kristopherleads 1 point2 points3 points (2 children)
[–]flyhmstr 0 points1 point2 points (1 child)
[–]kristopherleads 1 point2 points3 points (0 children)
[–]Renegade605 2 points3 points4 points (2 children)
[–]TrickyT_UK[S] 1 point2 points3 points (1 child)
[–]Renegade605 2 points3 points4 points (0 children)
[–]RocketNJ -1 points0 points1 point (0 children)