Node red , input_booleans and how to stop an automation

So i want my lights to cycle colors. But my strips doesn’t support random or colorloop so I copied and pasted this flow and got it work. But obviously I cant stop it. When i turn of the light it just gets on and keeps on going. I have no idea how to stop this. I have a vaguer idea that i need to use an input_boolean
but i cant get my head around how to do it.

Is it possible to turn this of when i turn off the rgb light identity ?

Thanks in advance


[{"id":"04f201e54e9fc6fd","type":"template","z":"8fac6b2580decde7","name":"admin","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{ \"data\": {\"entity_id\" : \"light.rgb_light\", \"rgb_color\" : {{payload.data.rgb_color}} }}","output":"json","x":690,"y":240,"wires":[["677e52db21cee4f6","1d48a0b698560759"]],"icon":"node-red-contrib-color-convert/color-convert.png"},{"id":"4e38b829efe500d6","type":"function","z":"8fac6b2580decde7","name":"change rgb","func":"var i = flow.get(\"i\");\nvar red   = Math.round(Math.sin(0.3*i + 0) * 127 + 128);\nvar green = Math.round(Math.sin(0.3*i + 2) * 127 + 128);\nvar blue  = Math.round(Math.sin(0.3*i + 4) * 127 + 128);\n\ni++;\nif (i>=32) {\n    i = 0;\n}\n\nflow.set(\"i\", i);\n\nmsg.payload = {};\nmsg.payload.data = {};\nmsg.payload.data.rgb_color = \"[\" + red + \", \" + green + \", \" + blue + \"]\";\n\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":240,"wires":[["04f201e54e9fc6fd","288285b6cc78da32"]]},{"id":"5fc6cec43bfa6dad","type":"function","z":"8fac6b2580decde7","name":"set var","func":"flow.set(\"i\", 0);\n\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":240,"wires":[["4e38b829efe500d6"]]},{"id":"288285b6cc78da32","type":"delay","z":"8fac6b2580decde7","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":540,"y":320,"wires":[["4e38b829efe500d6"]]},{"id":"677e52db21cee4f6","type":"api-call-service","z":"8fac6b2580decde7","name":"Cycle","server":"cc5f2328.3e1bd","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":870,"y":240,"wires":[["5121b90714ca6e1b"]]},{"id":"1d48a0b698560759","type":"debug","z":"8fac6b2580decde7","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":160,"wires":[]},{"id":"5121b90714ca6e1b","type":"debug","z":"8fac6b2580decde7","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":160,"wires":[]},{"id":"b8712ff7c2b85db2","type":"inject","z":"8fac6b2580decde7","name":"23:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 23 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":220,"y":240,"wires":[["5fc6cec43bfa6dad"]]},{"id":"cc5f2328.3e1bd","type":"server","name":"Home Assistant","version":4,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]

You can just add it in the loop:

[{"id":"5fc6cec43bfa6dad","type":"function","z":"ebaa69a9.649708","name":"set var","func":"flow.set(\"i\", 0);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":980,"wires":[["4e38b829efe500d6"]]},{"id":"b8712ff7c2b85db2","type":"inject","z":"ebaa69a9.649708","name":"23:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 23 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":100,"y":980,"wires":[["5fc6cec43bfa6dad"]]},{"id":"4e38b829efe500d6","type":"function","z":"ebaa69a9.649708","name":"change rgb","func":"var i = flow.get(\"i\");\nvar red   = Math.round(Math.sin(0.3*i + 0) * 127 + 128);\nvar green = Math.round(Math.sin(0.3*i + 2) * 127 + 128);\nvar blue  = Math.round(Math.sin(0.3*i + 4) * 127 + 128);\n\ni++;\nif (i>=32) {\n    i = 0;\n}\n\nflow.set(\"i\", i);\n\nmsg.payload = {};\nmsg.payload.data = {};\nmsg.payload.data.rgb_color = \"[\" + red + \", \" + green + \", \" + blue + \"]\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":980,"wires":[["04f201e54e9fc6fd","288285b6cc78da32"]]},{"id":"f5b8e37d6573b3b7","type":"api-current-state","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.someboolean","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":490,"y":1120,"wires":[["4e38b829efe500d6"],[]]},{"id":"04f201e54e9fc6fd","type":"template","z":"ebaa69a9.649708","name":"admin","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{ \"data\": {\"entity_id\" : \"light.rgb_light\", \"rgb_color\" : {{payload.data.rgb_color}} }}","output":"json","x":570,"y":980,"wires":[["677e52db21cee4f6","1d48a0b698560759"]],"icon":"node-red-contrib-color-convert/color-convert.png"},{"id":"288285b6cc78da32","type":"delay","z":"ebaa69a9.649708","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":220,"y":1120,"wires":[["f5b8e37d6573b3b7"]]},{"id":"677e52db21cee4f6","type":"api-call-service","z":"ebaa69a9.649708","name":"Cycle","server":"cc5f2328.3e1bd","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":750,"y":980,"wires":[["5121b90714ca6e1b"]]},{"id":"1d48a0b698560759","type":"debug","z":"ebaa69a9.649708","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":900,"wires":[]},{"id":"5121b90714ca6e1b","type":"debug","z":"ebaa69a9.649708","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":900,"wires":[]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30},{"id":"cc5f2328.3e1bd","type":"server","name":"Home Assistant","version":4,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

But what kind of color change does this do?
There are simpler ways to change color on a light.

This is how I would do it.

[{"id":"4e38b829efe500d6","type":"function","z":"ebaa69a9.649708","name":"change hue","func":"\nmsg.payload = {\n    data: {\n        'entity_id': 'light.somelight',\n        'hs_color': [(msg.data.attributes.hs_color[0] + 3) % 360, 100]\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":980,"wires":[["677e52db21cee4f6","288285b6cc78da32"]]},{"id":"288285b6cc78da32","type":"delay","z":"ebaa69a9.649708","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":330,"y":1080,"wires":[["f5b8e37d6573b3b7"]]},{"id":"677e52db21cee4f6","type":"api-call-service","z":"ebaa69a9.649708","name":"Cycle","server":"cc5f2328.3e1bd","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":850,"y":980,"wires":[["5121b90714ca6e1b"]]},{"id":"5121b90714ca6e1b","type":"debug","z":"ebaa69a9.649708","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":980,"wires":[]},{"id":"b8712ff7c2b85db2","type":"inject","z":"ebaa69a9.649708","name":"23:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 23 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":170,"y":980,"wires":[["4bd0683db381b61f"]]},{"id":"f5b8e37d6573b3b7","type":"api-current-state","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.someboolean","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":590,"y":1080,"wires":[["4bd0683db381b61f"],[]]},{"id":"4bd0683db381b61f","type":"api-current-state","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.somelight","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":400,"y":980,"wires":[["4e38b829efe500d6"]]},{"id":"cc5f2328.3e1bd","type":"server","name":"Home Assistant","version":4,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

I could not see any entity name so you need to edit that in the nodes.

This changes color every 5s. Can you pls show me the easier way to do it ?
I was gonna ask that as well this changes colors from red to green.But i would like to have random.

entity name is in the admin template. light.rgb_light

I added the light name and this is what i am getting
TypeError: Cannot read properties of undefined (reading ‘0’)

In what node?

change hue

Can you turn on the light and take a screenshot of the developer tools of this light, it’s the attributes I’m mostly interested in


supported_color_modes:
  - rgb
friendly_name: Rgb Light
supported_features: 40
color_mode: rgb
brightness: 80
hs_color:
  - 228.785
  - 83.922
rgb_color:
  - 41
  - 81
  - 255
xy_color:
  - 0.147
  - 0.084

is this what you are asking ?

Perfect.
Can you put a debug node set to complete message on the current state node just before the function node and show me the output


{"_msgid":"7001fb53cbf55ba0","payload":"off","topic":"","data":{"entity_id":"light.rgb_light","state":"off","attributes":{"supported_color_modes":["rgb"],"friendly_name":"Rgb Light","supported_features":40},"context":{"id":"01GAPHJENCJBBN285FVW3H8G5D","parent_id":null,"user_id":"c9d6606607184ad49defcc28a95d66a4"},"last_changed":"2022-08-17T18:38:08.060Z","last_updated":"2022-08-17T18:38:08.060Z","timeSinceChangedMs":374913,"original_state":"off"}}

and really thank you for taking time to do this.

I see the light was off.
That is the issue.
Add a call service between the inject and the current state node to turn on the light first, perhaps you need to add a small delay between (like 100 ms or so).

So the flow looks like this now. I changed the boolean name aswell with something that i added from helpers.

[{"id":"815f6f0303f6aafa","type":"tab","label":"Flow 8","disabled":false,"info":"","env":[]},{"id":"598b0ca597ea1785","type":"function","z":"815f6f0303f6aafa","name":"change hue","func":"\nmsg.payload = {\n    data: {\n        'entity_id': 'light.rgb_light',\n        'hs_color': [(msg.data.attributes.hs_color[0] + 3) % 360, 100]\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":790,"y":160,"wires":[["3cf1427b4e010cf9","2430cd93b1c4cae1"]]},{"id":"2430cd93b1c4cae1","type":"delay","z":"815f6f0303f6aafa","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":470,"y":260,"wires":[["c05f112184df8b9f"]]},{"id":"3cf1427b4e010cf9","type":"api-call-service","z":"815f6f0303f6aafa","name":"Cycle","server":"cc5f2328.3e1bd","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":990,"y":160,"wires":[["aa009c4864662589"]]},{"id":"aa009c4864662589","type":"debug","z":"815f6f0303f6aafa","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1150,"y":120,"wires":[]},{"id":"dab413185a705899","type":"inject","z":"815f6f0303f6aafa","name":"23:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":70,"y":160,"wires":[["d93841da4056a626"]]},{"id":"c05f112184df8b9f","type":"api-current-state","z":"815f6f0303f6aafa","name":"","server":"3425f38c5bea8c36","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.rgb","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":700,"y":260,"wires":[["2509719a4441d2d8"],[]]},{"id":"2509719a4441d2d8","type":"api-current-state","z":"815f6f0303f6aafa","name":"","server":"3425f38c5bea8c36","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.rgb_light","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":540,"y":160,"wires":[["598b0ca597ea1785","53817c282f5baba5"]]},{"id":"53817c282f5baba5","type":"debug","z":"815f6f0303f6aafa","name":"debug 17","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":780,"y":100,"wires":[]},{"id":"195e1749e4d5d371","type":"api-call-service","z":"815f6f0303f6aafa","name":"","server":"a60309f5.9e69e8","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.rgb_light"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":290,"y":160,"wires":[["2509719a4441d2d8"]]},{"id":"d93841da4056a626","type":"delay","z":"815f6f0303f6aafa","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":170,"y":260,"wires":[["195e1749e4d5d371"]]},{"id":"cc5f2328.3e1bd","type":"server","name":"Home Assistant","version":4,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"},{"id":"3425f38c5bea8c36","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"},{"id":"a60309f5.9e69e8","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]

This is the error i am getting when i activate it when the light is off.

This is the error when it is already on.

And the light doesnt change in both conditions.

Sorry I meant like this:

If it doesn’t work then try and delay more because the light has to be on to get the data attributes

Light gets on and no change in colors :frowning:

Does the loop continue to loop?
Try and change the value in the function node, perhaps 3 is too little and it just stays in one color.

'hs_color': [(msg.data.attributes.hs_color[0] + 3) % 360, 100]
                                                ^ change this to 10 or 15 or something.

I dont think so. There is on one output in degub nodes.

Is the boolean on?
The last node (cycle). Make that a light turn on instead. Not sure if it works with homeassistant turn on

Looks like this