Reading sensor data info change node

Hi

I have a sensor named sensor.stuen2lightcolorr containing the R color of RGB from a hue light.
I want to in a change node to read this value, together with the equal value from G and B sensor.

Hope someone have a good solution?

In config they are created like this examble

sensor:
  - platform: template 
    sensors:
      kitchenlightcolorr:
        value_template: "{{ states.light.kitchen.attributes.rgb_color[0] }}"
        friendly_name: 'Kitchen RGB Color R'

[{"id":"6d584818.9ce608","type":"change","z":"b7656499.b2541","name":"Livingroom2","rules":[{"t":"set","p":"data.lamp","pt":"msg","to":"livingroom2","tot":"str"},{"t":"set","p":"data.lightcolorr","pt":"msg","to":"sensor.stuen2lightcolorr","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":3660,"wires":[["9efa6429.d74df8"]]}]
1 Like

Your sensor reads the R value. You have nothing that reads the G and B values. Why? Why wouldn’t you have your sensor read all the values?

I do read all 3 values. It was easyer for me to make 2 sensors then a sensor with an array in it.
Also, i consider going over to reading mired values instead og RGB.

Problem still persist, reading sensor value from a change node.

Of course it does. It’s because your sensor only reads one value and you want values from sensors that don’t exist? Or do they?

You haven’t really given any details except that you have one sensor that depends on a single value in an array of another device and you want to act on a change, but use the data from other sensors that, from where I sit and can see, don’t exist?

Hi

Sorry it went a bit fast when i wrote original post.
Let me try to give another examble.

From a hue motion sensor, i have the automaticalle generated variable

sensor.hue_motion_sensor_1_light_level

Gives a value of eg. 2.72

I would like to read this value and set with other variables inside a change node.
In this flow export theres only made 1 change and setting payload, to make sure noting interferes.

[{"id":"6d584818.9ce608","type":"change","z":"b7656499.b2541","name":"Livingroom2","rules":[{"t":"set","p":"payload","pt":"msg","to":"sensor.hue_motion_sensor_1_light_level","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":3640,"wires":[["9efa6429.d74df8"]]},{"id":"9efa6429.d74df8","type":"debug","z":"b7656499.b2541","name":"Default Test","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":3640,"wires":[]},{"id":"41bb97aa.3b3ad8","type":"inject","z":"b7656499.b2541","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":3640,"wires":[["6d584818.9ce608"]]}]

I’ve fizzled around with J: expression and $env variable, but can’t find the correct solution.

Hope you can help me with this clarification.

What I’m not understanding is why You even need those sensors.

The debug node set to full msg will give you the complete msg.object
Which when connected to a change node output evertthing including the rgb values, bri etc

Used a few hours researching, and it dosn’t seem that the change node can read sensor data anyway, so the only way to do it is as you suggest, read them in one node and manipulate them to correct structure using change nodes.
I was hoping to do it all from 1 node.

sorry typo
meant to say state change node

but without the output on state changed ticked
if you select that it only output on state change (on/off)
if you untick it it output on all changes
if you just click output on connect
you will get the complete msg.object and all the relevent values you need with out making separate sensors

or i’m not getting what you wanting to do.

The change node can see every bit of the entire msg object that feeds into it. So if the sensor data is being fed into it, it can read it.

That’s what we have been telling you.

You could almost do it with a trigger: state node

Ok, so I have been working on this idea.

Appears that at the time I worked on it the first time, I was unable to get the color from the lamps, and therefor used the sensors, but experience and researched teached me more.
I made this work for my issue.

Thanks for your patience and guidence!

[{"id":"19fca0ec.fc812f","type":"change","z":"b7656499.b2541","name":"Livingroom2","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{\"entity_id\":\"light.hue_color_lamp_1_3\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":4140,"wires":[["945ee9b8.4b1858"]]},{"id":"f2dd1cb5.b2734","type":"inject","z":"b7656499.b2541","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":380,"y":4140,"wires":[["19fca0ec.fc812f"]]},{"id":"945ee9b8.4b1858","type":"api-current-state","z":"b7656499.b2541","name":"","server":"c07167d6.bc6238","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"","state_type":"str","state_location":"","override_payload":"none","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":760,"y":4140,"wires":[["bc400693.6559d8"],["bc400693.6559d8"]]},{"id":"c9ff405f.1320d","type":"debug","z":"b7656499.b2541","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1250,"y":4140,"wires":[]},{"id":"bc400693.6559d8","type":"change","z":"b7656499.b2541","name":"CleanBox","rules":[{"t":"set","p":"payload.state","pt":"msg","to":"data.state","tot":"msg"},{"t":"set","p":"payload.brightness","pt":"msg","to":"data.attributes.brightness","tot":"msg"},{"t":"set","p":"payload.color_temp","pt":"msg","to":"data.attributes.color_temp","tot":"msg"},{"t":"set","p":"payload.colorr","pt":"msg","to":"data.attributes.rgb_color[0]","tot":"msg"},{"t":"set","p":"payload.colorg","pt":"msg","to":"data.attributes.rgb_color[1]","tot":"msg"},{"t":"set","p":"payload.colorb","pt":"msg","to":"data.attributes.rgb_color[2]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":4140,"wires":[["c9ff405f.1320d"]]},{"id":"c07167d6.bc6238","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]

I’m still working with the change nodes.
For some reason, using the following 2 change nodes, the second node deletes the payload of the first. The second node correctly inserts the key and array.

Hope you guys can help me again.

[{"id":"4be98c7e.b36814","type":"change","z":"b7656499.b2541","name":"Desired Color","rules":[{"t":"set","p":"payload.desired_color_temp","pt":"msg","to":"350","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"{\"desired_rgb\":[0,0,0]}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":3700,"wires":[["72630aa0.a6cfb4"]]},{"id":"a5554af6.92add8","type":"change","z":"b7656499.b2541","name":"Desired Brightness","rules":[{"t":"set","p":"payload.desired_brightness","pt":"msg","to":"0 = default","tot":"str"},{"t":"set","p":"payload.desired_brightness","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":3660,"wires":[["4be98c7e.b36814","7f45aa4f.04b434"]]}]

Neither one of these change nodes makes any sense at all.

This is literally setting 2 values to the same attribute, which makes the first one null and isn’t actually doing anything.
image

What is the point of putting either of these change nodes in the order they are in?
image

It seems you are unnecessarily setting payload data that doesn’t need to be there.

Provide us with an example of the data that comes from your sensor or light that is triggering this flow, and the output you are EXPECTING.

From what I can see, you are overcomplicating this entire thing.

Hi again

So I think i might have nailed the entire thing.
Wanting to have light color change during day, and if I change it from the HUE app, activate a switch to indicate that manual control is active.
If manual control is turned off, reset color to auto.
What is not considered yet, is what happens if the manual override switch is turned off after the lights are turned off.

I did do it different before, but I think this is more streamlined way to do it.
The code can show signs of some of the old code.

configuration.yaml

input_boolean:
  manualstuen2:
    name: "Stue2 lys manuelt tændt"
    icon: mdi:lightbulb-on
    initial: off

Node -red

[{"id":"8a031fad.97f44","type":"subflow","name":"Save Light settings","info":"","category":"","in":[{"x":20,"y":80,"wires":[{"id":"9ae81bf4.ab8d98"}]}],"out":[{"x":360,"y":80,"wires":[{"id":"9ae81bf4.ab8d98","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"9ae81bf4.ab8d98","type":"function","z":"8a031fad.97f44","name":"Save Light settings","func":"\n// Array in global https://stackoverflow.com/questions/49481558/node-red-global-array-variable-get-set-not-seeming-to-work\n// global.set(\"arrOldSettings[\"+i+\"], i);\n\n// A mired is a microreciprocal degree. It’s derived by dividing 1,000,000 by the Kelvin temperature. So 5600K has a mired of 180 (1,000,000/5600 = 179.57).\n// https://www.tvtechnology.com/opinions/the-art-of-the-mired-measurement\n\nvar MyLight = msg.payload;\nvar OldSettings = global.get(\"OldSettings\");\nvar new_msg = \"\";\n\nif ( typeof msg !== \"undefined\" ) {\n    if ( typeof msg.data !== \"undefined\" ) {\n        if ( typeof msg.data.attributes !== \"undefined\" ) {\n\n            if ( typeof msg.data.attributes.rgb_color !== \"undefined\" ) {\n                OldSettings[ MyLight + 'lightcolorr' ] = msg.data.attributes.rgb_color[0];\n                OldSettings[ MyLight + 'lightcolorg' ] = msg.data.attributes.rgb_color[1];\n                OldSettings[ MyLight + 'lightcolorb' ] = msg.data.attributes.rgb_color[2];\n                new_msg.payload = \"Saved following as default rgb_color for \" + MyLight + \": \" + msg.data.attributes.rgb_color;\n            } else if ( typeof msg.data.attributes.color_temp !== \"undefined\" ){ \n                //get the mired value\n                // The Mired to Kelvin value is devided by 100 to round it and then multiplyed by 100, to achive a round kelvin number of eg 2600 (Instead of 2577 at 388 Mired)\n                var MiredToKelvin = ( (Math.round( (1000000 / msg.data.attributes.color_temp) / 100 ) ) * 100 );\n\n                OldSettings[ MyLight + 'lightcolorr' ] = OldSettings[\"ArrKelvinConvert\"][MiredToKelvin]['R'];\n                OldSettings[ MyLight + 'lightcolorg' ] = OldSettings[\"ArrKelvinConvert\"][MiredToKelvin]['G'];\n                OldSettings[ MyLight + 'lightcolorb' ] = OldSettings[\"ArrKelvinConvert\"][MiredToKelvin]['B'];\n                \n                new_msg.payload = new_msg.payload + \"Saved following as default color_temp (\" + msg.data.attributes.color_temp + \") convert to kelvin (\" + MiredToKelvin + \") convert to RGB (\" + OldSettings[\"ArrKelvinConvert\"][MiredToKelvin]['R']  + \", \" + OldSettings[\"ArrKelvinConvert\"][MiredToKelvin]['G']  + \", \" + OldSettings[\"ArrKelvinConvert\"][MiredToKelvin]['B'] + \") for \" + MyLight;\n            } else { new_msg.error = \"fail4\"; }\n\n            if ( \"brightness\" in msg.data.attributes ) {\n                OldSettings[ MyLight + 'brightness'] = msg.data.attributes.brightness;\n                new_msg.payload = new_msg.payload + \" ::: Set \" + MyLight + \"Brightness = \" + OldSettings[ MyLight + 'brightness' ];\n            } else { new_msg.error = \"fail5\"; }\n\n        } else { new_msg.error = \"fail3\" }\n    } else { new_msg.error = \"fail2\" }\n} else { new_msg.error = \"fail1\" }\n\nglobal.set(\"OldSettings\", OldSettings);\n\nreturn new_msg;","outputs":1,"noerr":0,"x":190,"y":80,"wires":[[]]},{"id":"96e64d5a.9d8c1","type":"subflow","name":"Stuen2 On","info":"","category":"","in":[{"x":40,"y":40,"wires":[{"id":"9335e183.91a65"},{"id":"71b91873.6ae738"}]}],"out":[],"env":[]},{"id":"9335e183.91a65","type":"api-call-service","z":"96e64d5a.9d8c1","name":"Stuen2 On","server":"468387c0.b24028","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_1_3","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":40,"wires":[[]]},{"id":"d1fcdc8a.8840f","type":"debug","z":"96e64d5a.9d8c1","name":"Stuen2 Subflow 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":890,"y":80,"wires":[]},{"id":"992bb09e.cdb19","type":"api-current-state","z":"96e64d5a.9d8c1","name":"Stuen2 Light Already On?","server":"468387c0.b24028","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.hue_color_lamp_1_3","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":410,"y":200,"wires":[["d99838f4.3d3d68"],["71b91873.6ae738"]]},{"id":"71b91873.6ae738","type":"delay","z":"96e64d5a.9d8c1","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":140,"wires":[["992bb09e.cdb19"]]},{"id":"40272f52.2bc0a","type":"debug","z":"96e64d5a.9d8c1","name":"Stuen2 Subflow 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":890,"y":120,"wires":[]},{"id":"4e1dd6ff.b9d428","type":"debug","z":"96e64d5a.9d8c1","name":"Stuen2 Subflow 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":890,"y":160,"wires":[]},{"id":"437be4de.f1c26c","type":"change","z":"96e64d5a.9d8c1","name":"Stuen2","rules":[{"t":"set","p":"payload.name","pt":"msg","to":"stuen2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":200,"wires":[["73046ae2.c642d4"]]},{"id":"73046ae2.c642d4","type":"subflow:8a031fad.97f44","z":"96e64d5a.9d8c1","name":"","env":[],"x":890,"y":200,"wires":[[]]},{"id":"d99838f4.3d3d68","type":"change","z":"96e64d5a.9d8c1","name":"CleanBox","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.colorb","pt":"msg","to":"data.attributes.rgb_color[2]","tot":"msg"},{"t":"set","p":"payload.entity_id","pt":"msg","to":"data.entity_id","tot":"msg"},{"t":"set","p":"payload.state","pt":"msg","to":"data.state","tot":"msg"},{"t":"set","p":"payload.brightness","pt":"msg","to":"data.attributes.brightness","tot":"msg"},{"t":"set","p":"payload.color_temp","pt":"msg","to":"data.attributes.color_temp","tot":"msg"},{"t":"set","p":"payload.colorr","pt":"msg","to":"data.attributes.rgb_color[0]","tot":"msg"},{"t":"set","p":"payload.colorg","pt":"msg","to":"data.attributes.rgb_color[1]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":260,"wires":[["437be4de.f1c26c"]]},{"id":"7d074c78.101bd4","type":"function","z":"b7656499.b2541","name":"Light Box","func":"// Version 4 of 9/1-2020\n\n// Array in global https://stackoverflow.com/questions/49481558/node-red-global-array-variable-get-set-not-seeming-to-work\n// global.set(\"arrOldSettings[\"+i+\"], i);\n\n\n//if ( typeof global.get(\"OldSettings\") == 'object' ){\n    var OldSettings = global.get(\"OldSettings\");\n//}\n\nvar Payload_Name = \"default\";\nvar Payload_Entity_ID = \"default\";\nvar Payload_Manual_Switch = \"\";\nvar Payload_State = \"on\";\nvar Payload_Brightness = 0;\nvar Payload_Transition = 1;\nvar Payload_Color_Temp = 0;\n//var Payload_Color_RGB = { \"R\": 0, \"G\": 0, \"B\": 0 };\nvar Payload_Desired_Brightness = 128;\nvar Payload_Desired_Color_Temp = 250;\nvar RGB_Tolerance = OldSettings[ 'RGB_Tolerance' ];\nvar strLightMsg = msg;                                                  // The msg for setting light options\nvar intSetManualOverride = 0; // 0 = auto, 1 = manual override\nvar strSetManualOverrideMsg = msg;                                     // The msg for setting manual override state\nstrLightMsg.payload.debug = { \"debug_start\": \"Start debugging\" };\nvar Payload_Force_To_Auto = 0;\n\nif ( typeof msg !== \"undefined\" ) {\n    if ( typeof msg.payload !== \"undefined\" ) {\n        if ( typeof msg.payload.name !== \"undefined\" ) {\n            Payload_Name = msg.payload.name;\n        }\n        if ( typeof msg.payload.light !== \"undefined\" ) {\n            Payload_Entity_ID = msg.payload.light;\n        }\n        if ( typeof msg.payload.manual_switch !== \"undefined\" ) {\n            Payload_Manual_Switch = msg.payload.manual_switch;\n        }\n        if ( typeof msg.payload.state !== \"undefined\" ) {\n            Payload_State = msg.payload.state;\n        }\n        if ( typeof msg.payload.brightness !== \"undefined\" ) {\n            Payload_Brightness = msg.payload.brightness;\n        }\n        if ( typeof msg.payload.color_temp !== \"undefined\" ) {\n            Payload_Color_Temp = msg.payload.color_temp;\n        }\n//        if ( typeof msg.payload.color_rgb !== \"undefined\" ) {\n//            Payload_Color_RGB = msg.payload.color_rgb;\n//        }\n        if ( typeof msg.payload.transition !== \"undefined\" ) {\n            if ( msg.payload.transition === 0 ) {\n                Payload_Transition = OldSettings[Payload_Name][\"default\"][\"transition\"];\n            } else {\n                Payload_Transition = msg.payload.transition;\n            }\n        }\n        if ( typeof msg.payload.desired_brightness !== \"undefined\" ) {\n            if ( msg.payload.desired_brightness === 0 ) {\n                Payload_Desired_Brightness = OldSettings[Payload_Name][\"default\"][\"brightness\"];\n            } else {\n                Payload_Desired_Brightness = msg.payload.desired_brightness;\n            }\n        }\n        if ( typeof msg.payload.desired_color_temp !== \"undefined\" ) {\n            if ( msg.payload.desired_color_temp === 0 ) {\n                Payload_Desired_Color_Temp = OldSettings[Payload_Name][\"default\"][\"color_temp\"];\n            } else {\n                Payload_Desired_Color_Temp = msg.payload.desired_color_temp;\n            }\n        }\n        if ( typeof msg.payload.desired_rgb !== \"undefined\" ) {\n            if ( msg.payload.desired_rgb === 0 ) {\n                Payload_Desired_RGB = OldSettings[Payload_Name][\"default\"][\"color_rgb\"];\n            } else {\n                Payload_Desired_RGB = msg.payload.desired_rgb;\n            }\n            // missing saving of RGB because of troubles with the arrays\n        }\n        if ( typeof msg.payload.forced_to_auto !== \"undefined\" ) {\n            Payload_Force_To_Auto = msg.payload.forced_to_auto;\n        }\n    }\n\n    var OldSettings_Current_Color_Temp = OldSettings[Payload_Name][\"current\"][\"color_temp\"];\n    var OldSettings_Current_Brightness = OldSettings[Payload_Name][\"current\"][\"brightness\"];\n\n    if ( Payload_State == \"on\" ) {\n        strLightMsg.payload.debug.debug1 = \"Payload_State == 'on'\";\n        if ( Payload_Force_To_Auto === 0) {\n            strLightMsg.payload.debug.debug2 = \"Payload_Force_To_Auto === 0\";\n            if ( Payload_Color_Temp > 0) {\n                if ( ( Payload_Color_Temp > ( OldSettings_Current_Color_Temp + RGB_Tolerance ) ) || ( Payload_Color_Temp < ( OldSettings_Current_Color_Temp - RGB_Tolerance ) ) ) {\n                    intSetManualOverride = 1;\n                    strLightMsg.payload.debug.debug3 = \"SetManualOverride = 1 because of Payload_Color_Temp \" + Payload_Color_Temp + \" <> \" + OldSettings_Current_Color_Temp + \" +- \" + RGB_Tolerance;\n                } else {\n                    strLightMsg.payload.debug.debug3 = \"Not setting SetManualOverride because of Payload_Color_Temp \" + Payload_Color_Temp + \" = \" + OldSettings_Current_Color_Temp + \" +- \" + RGB_Tolerance;\n                }\n            } else {\n                strLightMsg.payload.debug.debug3 = \"Color_temp not supplied or < 0\";\n            }\n            if ( ( Payload_Brightness > ( OldSettings_Current_Brightness + RGB_Tolerance ) ) || ( Payload_Brightness < ( OldSettings_Current_Brightness - RGB_Tolerance ) ) ) {\n                intSetManualOverride = 1;\n                strLightMsg.payload.debug.debug4 = \"SetManualOverride = 1 because of Payload_Brightness \" + Payload_Brightness + \" <> \" + OldSettings_Current_Brightness + \" +- \" + RGB_Tolerance;\n            } else {\n                strLightMsg.payload.debug.debug4 = \"Not setting SetManualOverride because of Payload_Brightness\" + Payload_Brightness + \" = \" + OldSettings_Current_Brightness + \" +- \" + RGB_Tolerance;\n            }\n        } else {\n            strLightMsg.payload.debug.debug2 = \"Payload_Force_To_Auto === 1\";\n        }\n    } else {\n        strLightMsg.payload.debug.debug1 = \"Payload_State == 'off'\";\n    }\n\n\n    if ( (intSetManualOverride === 0) ){\n        if ( Payload_Desired_Color_Temp > 0 ){                              // If kelvin is set in function call\n            \n            Payload_Desired_Color_Temp = ( Payload_Desired_Color_Temp > 500 ) ? 500 : Payload_Desired_Color_Temp;\n            Payload_Desired_Color_Temp = ( Payload_Desired_Color_Temp < 153 ) ? 153 : Payload_Desired_Color_Temp;\n                                                                            // If color temp is above or below hue limitations\n            strLightMsg.payload.data = {\n                'brightness': Payload_Desired_Brightness,                   // Brightness 1-255 from function call\n                'color_temp': Payload_Desired_Color_Temp,                   // Color temp 153-500 from function call\n                'transition': Payload_Transition                            // Transition time from function call\n            };\n            strLightMsg.payload.debug.debug5 = \"Setting light options with color_temp: \" + Payload_Desired_Color_Temp + \" and brightness: \" + Payload_Desired_Brightness + \" and transition: \" + Payload_Transition;\n        } else if ( (Payload_Desired_RGB[\"R\"] > 0) || (Payload_Desired_RGB[\"B\"] > 0) || (Payload_Desired_RGB[\"G\"] > 0) ){\n                                                                            // Else if RGB color is set in funciton call\n            strLightMsg.payload.data = {\n                'brightness': Payload_Desired_Brightness,                   // Brightness 1-255 from function call\n                'rgb_color': Payload_Desired_RGB,                           // RGB Color from function call\n                'transition': Payload_Transition                            // Transition time from function call\n            };\n            strLightMsg.payload.debug.debug5 = \"Setting light options with RGB: \" + Payload_Desired_RGB + \" and brightness: \" + Payload_Desired_Brightness + \" and transition: \" + Payload_Transition;\n        } else {                                                            // If no RGB or Kelvin color was set in function call\n            strLightMsg.payload.data = {\n                'brightness': 200,                                          // Brightness 1-255\n                'color_temp': 350,                                          // Color temp\n                'transition': 1                                             // Transition time\n            };\n            strLightMsg.payload.debug.debug6 = \"Setting light options to default - ERROR in supplied data\";\n        }\n    }\n}\n\nglobal.set(\"OldSettings\", OldSettings);\n\nif ( intSetManualOverride == 1 ){\n    strSetManualOverrideMsg.payload.entity_id = Payload_Manual_Switch;\n    strSetManualOverrideMsg.payload.debug = strLightMsg.payload.debug;\n    strSetManualOverrideMsg.payload.debug.debug7 = \"strLightMsg = null\";\n    strLightMsg = null;\n} else {\n    strSetManualOverrideMsg = null;\n    strLightMsg.payload.debug.debug8 = \"strSetManualMsg = null\";\n    OldSettings[Payload_Name][\"current\"][\"brightness\"] = Payload_Desired_Brightness;\n    OldSettings[Payload_Name][\"current\"][\"color_temp\"] = Payload_Desired_Color_Temp;\n}\n\nreturn [\n    strLightMsg,\n    strSetManualOverrideMsg,\n];\n\n\n\n","outputs":2,"noerr":0,"x":500,"y":4080,"wires":[["896af69c.f4a1e8","b4600bdb.8d10b8"],["89b17d9e.1d8eb","e7735460.a78368"]]},{"id":"f2dd1cb5.b2734","type":"inject","z":"b7656499.b2541","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":3980,"wires":[["d6e36bb5.c79488"]]},{"id":"945ee9b8.4b1858","type":"api-current-state","z":"b7656499.b2541","name":"Get Light States","server":"c07167d6.bc6238","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"","state_type":"str","state_location":"","override_payload":"none","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":520,"y":3980,"wires":[["9913f88c.cb58f8","4a24789c.238e08"],[]]},{"id":"c9ff405f.1320d","type":"debug","z":"b7656499.b2541","name":"Debug 1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":880,"y":3940,"wires":[]},{"id":"9913f88c.cb58f8","type":"change","z":"b7656499.b2541","name":"CleanBox","rules":[{"t":"set","p":"payload.state","pt":"msg","to":"data.state","tot":"msg"},{"t":"set","p":"payload.colorb","pt":"msg","to":"data.attributes.rgb_color[2]","tot":"msg"},{"t":"set","p":"payload.brightness","pt":"msg","to":"data.attributes.brightness","tot":"msg"},{"t":"set","p":"payload.color_temp","pt":"msg","to":"data.attributes.color_temp","tot":"msg"},{"t":"set","p":"payload.colorr","pt":"msg","to":"data.attributes.rgb_color[0]","tot":"msg"},{"t":"set","p":"payload.colorg","pt":"msg","to":"data.attributes.rgb_color[1]","tot":"msg"},{"t":"set","p":"payload.light","pt":"msg","to":"payload.entity_id","tot":"msg"},{"t":"set","p":"payload.data.entity_id","pt":"msg","to":"payload.manual_switch","tot":"msg"},{"t":"set","p":"payload.entity_id","pt":"msg","to":"payload.manual_switch","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":3980,"wires":[["a5554af6.92add8","c9ff405f.1320d"]]},{"id":"a5554af6.92add8","type":"change","z":"b7656499.b2541","name":"Desired Brightness","rules":[{"t":"set","p":"payload.desired_brightness","pt":"msg","to":"0 = Default Brightness","tot":"str"},{"t":"set","p":"payload.desired_brightness","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"payload.desired_transition","pt":"msg","to":"0 = Default Transition","tot":"str"},{"t":"set","p":"payload.desired_transition","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":3980,"wires":[["4be98c7e.b36814","7f45aa4f.04b434"]]},{"id":"4be98c7e.b36814","type":"change","z":"b7656499.b2541","name":"Desired Color","rules":[{"t":"set","p":"payload.desired_color_temp","pt":"msg","to":"0 = Default [ 153-500 ]","tot":"str"},{"t":"set","p":"payload.desired_color_temp","pt":"msg","to":"350","tot":"num"},{"t":"set","p":"payload.desired_rgb","pt":"msg","to":"0 = disabled","tot":"str"},{"t":"set","p":"payload.desired_rgb","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":3980,"wires":[["72630aa0.a6cfb4","c8e8d9dd.cdb838"]]},{"id":"7f45aa4f.04b434","type":"debug","z":"b7656499.b2541","name":"Debug 2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1100,"y":3940,"wires":[]},{"id":"72630aa0.a6cfb4","type":"debug","z":"b7656499.b2541","name":"Debug 3","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1300,"y":3940,"wires":[]},{"id":"c8e8d9dd.cdb838","type":"api-current-state","z":"b7656499.b2541","name":"If Manual Override is Off","server":"468387c0.b24028","version":1,"outputs":2,"halt_if":"false","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"","state_type":"habool","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":250,"y":4040,"wires":[["c63a0f0d.ea5cf","7d074c78.101bd4"],["a736e0f.077512"]]},{"id":"c63a0f0d.ea5cf","type":"debug","z":"b7656499.b2541","name":"Debug 4","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":500,"y":4040,"wires":[]},{"id":"b4600bdb.8d10b8","type":"subflow:96e64d5a.9d8c1","z":"b7656499.b2541","name":"","env":[],"x":710,"y":4080,"wires":[]},{"id":"896af69c.f4a1e8","type":"debug","z":"b7656499.b2541","name":"Debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":700,"y":4040,"wires":[]},{"id":"89b17d9e.1d8eb","type":"debug","z":"b7656499.b2541","name":"Debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":700,"y":4180,"wires":[]},{"id":"a736e0f.077512","type":"debug","z":"b7656499.b2541","name":"Debug 7","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":500,"y":4120,"wires":[]},{"id":"e7735460.a78368","type":"api-call-service","z":"b7656499.b2541","name":"Set Manual Override On","server":"c07167d6.bc6238","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":750,"y":4120,"wires":[["2687c5ef.51b00a"]]},{"id":"c7b2d83b.1c4ac8","type":"server-state-changed","z":"b7656499.b2541","name":"Settings (Manual turns off)","server":"c07167d6.bc6238","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.manualstuen2","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"false","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":230,"y":3900,"wires":[["efa77c7b.5e0d6"],[]]},{"id":"efa77c7b.5e0d6","type":"change","z":"b7656499.b2541","name":"CleanBox","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"data","pt":"msg"},{"t":"delete","p":"topic","pt":"msg"},{"t":"set","p":"data","pt":"msg","to":"{\"force_to_auto\":\"1\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":3900,"wires":[["d6e36bb5.c79488","b9590be5.0e1e38"]]},{"id":"d6e36bb5.c79488","type":"change","z":"b7656499.b2541","name":"Settings","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.forced_to_auto","pt":"msg","to":"data.force_to_auto","tot":"msg"},{"t":"delete","p":"data","pt":"msg"},{"t":"set","p":"payload.name","pt":"msg","to":"livingroom2","tot":"str"},{"t":"set","p":"payload.entity_id","pt":"msg","to":"light.hue_color_lamp_1_3","tot":"str"},{"t":"set","p":"payload.manual_switch","pt":"msg","to":"input_boolean.manualstuen2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":3980,"wires":[["945ee9b8.4b1858","779bb38c.bb787c"]]},{"id":"2687c5ef.51b00a","type":"debug","z":"b7656499.b2541","name":"Debug 8","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":960,"y":4120,"wires":[]},{"id":"b9590be5.0e1e38","type":"debug","z":"b7656499.b2541","name":"Debug 9","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":580,"y":3900,"wires":[]},{"id":"779bb38c.bb787c","type":"debug","z":"b7656499.b2541","name":"Debug 0","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":500,"y":3940,"wires":[]},{"id":"4a24789c.238e08","type":"debug","z":"b7656499.b2541","name":"Debug 0.1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":3940,"wires":[]},{"id":"d57d8b78.1e1c38","type":"function","z":"b7656499.b2541","name":"Set Default Kelvin and Brightness","func":"\n// Automatically create the global array\nvar OldSettings;\n\nif ( typeof global.get(\"OldSettings\") !== 'object' ){\n    OldSettings = { \n    RGB_Tolerance: 4,\n    intDefaultKelvin: 250,\n    intDefaultBrightness: 128,\n    intDefaultTransition: 1,\n    ArrKelvinConvert: 0,\n    \"default\": {\n        \"brightness\": 128,\n        \"transition\": 1,\n        \"color_temp\": 250,\n        \"color_rgb\": { \"R\": 0, \"G\": 0, \"B\": 0 }\n    },\n\n    \"livingroom2\": {\n        \"default\": {\n            \"brightness\": 128,\n            \"transition\": 1,\n            \"color_temp\": 250,\n            \"color_rgb\": { \"R\": 0, \"G\": 0, \"B\": 0 }\n        },\n        \"current\": {\n            \"brightness\": 0,\n            \"color_temp\": 0,\n            \"color_rgb\": { \"R\": 0, \"G\": 0, \"B\": 0 }\n        },\n    },\n\n    }\n} else {\n    OldSettings = global.get(\"OldSettings\");\n}\n\nvar intDate = new Date();\nvar intHours = intDate.getHours();\n\nswitch ( intHours ) {\n    case 18:\n        OldSettings[\"intDefaultKelvin\"] =\"3700\";\n        OldSettings[\"intDefaultBrightness\"] =\"128\";\n        OldSettings[\"intDefaultTransition\"] =\"5\";\n        \n        OldSettings[\"livingroom2\"][\"default\"][\"color_temp\"] = OldSettings[\"default\"][\"color_temp\"];\n        OldSettings[\"livingroom2\"][\"default\"][\"brightness\"] = OldSettings[\"default\"][\"brightness\"];\n\n    break;\n    default:\n        OldSettings[\"intDefaultKelvin\"] =\"3500\";\n        OldSettings[\"intDefaultBrightness\"] =\"128\";\n        OldSettings[\"intDefaultTransition\"] =\"1\";\n        \n        OldSettings[\"livingroom2\"][\"default\"][\"color_temp\"] = OldSettings[\"default\"][\"color_temp\"];\n        OldSettings[\"livingroom2\"][\"default\"][\"brightness\"] = OldSettings[\"default\"][\"brightness\"];\n\n}\n\nglobal.set(\"OldSettings\", OldSettings);\nmsg.payload = { data: { OldSettings } };\n\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":3840,"wires":[["b0a18b3.4808c78"]]},{"id":"875e3387.7e898","type":"inject","z":"b7656499.b2541","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":3840,"wires":[["d57d8b78.1e1c38"]]},{"id":"b0a18b3.4808c78","type":"debug","z":"b7656499.b2541","name":"Test","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":3840,"wires":[]},{"id":"c07167d6.bc6238","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true},{"id":"468387c0.b24028","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

Again, you are setting duplicate payload data for no reason at all.

What this Change Node does is set msg.payload.desired_brightness to 0 = Default Brightness, then immediately sets the SAME property to 0.

WHY?

What purpose is this supposed to serve?

Exact same problem with this one:

I don’t know about that. The entire flow is confusing as hell. I’m not really sure what it’s supposed to do, aside from a WHOLE LOT OF JAVASCRIPT


Compared to my previous solution with 3 function code blocks, and periodic errors, this looks better and works better for me.

About me setting 2 values at the same time, the first value is only there to show that if you set setting to 0 it will take the default value instead. Another solution for this is to use comments block, but this worked faster for me and stayed with the block.

About my original post, it’s not possible to read variable values with a change block, I thought it was. Especially with all the advanced functions you have available in there.

Later I asked about 2 change nodes that deleted my payload

[{"id":"4be98c7e.b36814","type":"change","z":"b7656499.b2541","name":"Desired Color","rules":[{"t":"set","p":"payload.desired_color_temp","pt":"msg","to":"350","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"{\"desired_rgb\":[0,0,0]}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":3700,"wires":[["72630aa0.a6cfb4"]]},{"id":"a5554af6.92add8","type":"change","z":"b7656499.b2541","name":"Desired Brightness","rules":[{"t":"set","p":"payload.desired_brightness","pt":"msg","to":"0 = default","tot":"str"},{"t":"set","p":"payload.desired_brightness","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":3660,"wires":[["4be98c7e.b36814","7f45aa4f.04b434"]]}]

It appears that I made an error with the second node, setting the msg.payload replaces it, not adding.
image
I never figured out how to add the RGB array from the change node, and that’s why my flow only runs with color_temp for the moment.

Set payload to be an object and then add the property you want.