Hi guys,
I just started my very few steps using functional nodes as I´m not a programmer so please bear with me if this request is rather simple, stupid. Here is the use case I´m trying to accomplish:
When entering my office, I like the motion sensor to turn on the light (quite simple). This is what I would like to achieve:
IF motion is detected (msg.payload.occupancy===true) AND no lights are on (("BueroLicht_AN")===false) THEN the light should be turned an
When turning on the light, different scenes for day- and nighttime should be chosen
You're using "strict equality" (===) rather than "equality" (==). This is good, but it means if the types don't match, they will not be equal. For example, msg.payload.occupancy could contain the string "true", rather than the binary value true, and "true" === true is false, because they are different types.
If you use a debug node to show the payload, you will be able to tell. It will either have occupancy: "true" for a string, or occupancy: true for a binary value. Your comparison should match. If the types already match, it could be your flow variable that differs. You can check this in the Context Data tab.
As @TotallyInformation points out the problem is that you do not have an else clause on the outer if. Therefore, if the first test fails you are returning the original message unchanged. A simple solution is the replace the last two lines with
} else {
msg = null
}
return msg
This works because returning null tells it not to pass on any message.
The OP said this, so if occupancy is true and the global is true and the flow is false, then payload should be changed to scene. That makes me think that the conditional values have not been met. Sure if the flow and occupancy values are not met the payload will not be changed, but that's not what the OP has said. he needs to confirm his conditional values
Hi everyone,
thank you so much for all the feedback you gave - That is amazing!
I tried to incorporate as much as I could and also tried to simplify the function in order to first get it going before adding more complexity to it. Now this is my new flow: