Use Value from front end input box

This is my automation for turning on a closet light. It is hard coded to turn on if the kitchen brightness check node is 50 or less then the lux value from a motion sensor in the kitchen. I want to be able to change that hard coded 50 to get a value I can set from the front end, front an input box or input slider.

[{"id":"e22d85ec.7a1fa8","type":"server-state-changed","z":"fc5facd3.2748a","name":"Kids Linen Closet Door","server":"6bf3852e.cfd07c","version":1,"entityidfilter":"binary_sensor.kids_linen_closet_door","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":160,"y":500,"wires":[["f7057cb1.d2b4b"]]},{"id":"f7057cb1.d2b4b","type":"switch","z":"fc5facd3.2748a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":500,"wires":[["aaf68026.931e6"],["a38111ee.1455e"]]},{"id":"61419ae9.719094","type":"api-call-service","z":"fc5facd3.2748a","name":"Turn Kids Hallway Light On","server":"6bf3852e.cfd07c","version":1,"service_domain":"light","service":"turn_on","entityId":"light.kids_hallway_light_dimmer","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":820,"y":520,"wires":[[]]},{"id":"a38111ee.1455e","type":"api-call-service","z":"fc5facd3.2748a","name":"Turn Kids Hallway Light Off","server":"6bf3852e.cfd07c","version":1,"service_domain":"light","service":"turn_off","entityId":"light.kids_hallway_light_dimmer","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":560,"y":640,"wires":[[]]},{"id":"aaf68026.931e6","type":"api-current-state","z":"fc5facd3.2748a","name":"Check Kitchen Brightness","server":"6bf3852e.cfd07c","version":1,"outputs":2,"halt_if":"50","halt_if_type":"num","halt_if_compare":"lte","override_topic":false,"entity_id":"sensor.kitchen_lux_sensor","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":530,"y":480,"wires":[["61419ae9.719094"],[]]},{"id":"6bf3852e.cfd07c","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

Just use a get state node and check the value of an input slider

How would I check if the value of the input slider is equal to or less than the state of the brightness of the motion sensor?

??

That seems pretty basic to me.

Check state of slider (value). Check brightness of motion sensor and compare them. Use flow variables, or stick them into the msg object.

I get what I have to do, the logic, I don’t how how to compare the two values.

You can store them in the msg object or in a flow variable, then it’s a simple comparison using JavaScript function.

Getting closer, this is what I got:

[{"id":"775ddad4.a661b4","type":"server-state-changed","z":"1b1aacf6.17d013","name":"Pantry Closet Door","server":"6bf3852e.cfd07c","version":1,"entityidfilter":"binary_sensor.pantry_closet_door","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":90,"y":300,"wires":[["2ac843f0.7e7ffc"]]},{"id":"2ac843f0.7e7ffc","type":"switch","z":"1b1aacf6.17d013","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":300,"wires":[["aae625.085d99d8"],["7addec3.45ccd14"]]},{"id":"2a11329a.c292de","type":"api-call-service","z":"1b1aacf6.17d013","name":"Turn Hallway Light On","server":"6bf3852e.cfd07c","version":1,"service_domain":"light","service":"turn_on","entityId":"light.hallway_light_dimmer","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":880,"y":220,"wires":[[]]},{"id":"7addec3.45ccd14","type":"api-call-service","z":"1b1aacf6.17d013","name":"Turn Hallway Light Off","server":"6bf3852e.cfd07c","version":1,"service_domain":"light","service":"turn_off","entityId":"light.hallway_light_dimmer","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":480,"y":360,"wires":[[]]},{"id":"aae625.085d99d8","type":"function","z":"1b1aacf6.17d013","name":"Check Kitchen Brightness","func":"const states = global.get('homeassistant').homeAssistant.states;\nconst kitchenlux = states['sensor.kitchen_lux_sensor'].state;\nconst inputbox = states['input_number.box1'].state;\n\nlet message;\nif (kitchenlux < inputbox) {\n    message = \"dark\";\n} else if (kitchenlux > inputbox) {\n    message = \"bright\";\n} else {\n    return;\n}\n\nmsg.payload = message;\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":240,"wires":[["addb78e0.368048","1191d558.c6bd7b"]]},{"id":"addb78e0.368048","type":"switch","z":"1b1aacf6.17d013","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"dark","vt":"str"},{"t":"eq","v":"bright","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":240,"wires":[["2a11329a.c292de"],[]]},{"id":"1191d558.c6bd7b","type":"debug","z":"1b1aacf6.17d013","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":510,"y":300,"wires":[]},{"id":"6bf3852e.cfd07c","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

With the fuction node code as:

const states = global.get('homeassistant').homeAssistant.states;
const kitchenlux = states['sensor.kitchen_lux_sensor'].state;
const inputbox = states['input_number.box1'].state;

let message;
if (kitchenlux < inputbox) {
    message = "dark";
} else if (kitchenlux > inputbox) {
    message = "bright";
} else {
    return;
}

msg.payload = message;
return msg;

It works, but is this the best way to do this?

I see the function node has the option for 2 outputs. If I use that I can remove the switch node after the function node. How would I setup the 2 outputs from the function.

https://nodered.org/docs/user-guide/writing-functions