Simplifying Flows

I consider myself knowledgeable on Node-Red and its integration with HA, but I still struggle on simplifying/combining nodes. I have several flows that only deal with motion sensors and lighting. I have one where I dim the living room lights when the LR TV turns on. I have both a Wyze motion sensor and a camera motion sensor through Blue Iris. Here is my flow:

[{"id":"92266247.3aa2b","type":"api-call-service","z":"bc5d2546.59a7a8","name":"Living Room Lamps on 25%","server":"79e1f09.1e9b71","version":1,"service_domain":"light","service":"turn_on","entityId":"light.living_room_lamp, light.entry_lamp_1, light.entry_lamp_2, light.piano_lamp_1, light.piano_lamp_2","data":"{\"brightness_pct\": \"25\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":580,"y":1140,"wires":[[]]},{"id":"4bb15d56.44cfc4","type":"api-call-service","z":"bc5d2546.59a7a8","name":"Living Room Lamps on 100%","server":"79e1f09.1e9b71","version":1,"service_domain":"light","service":"turn_on","entityId":"light.living_room_lamp, light.entry_lamp_1, light.entry_lamp_2, light.piano_lamp_1, light.piano_lamp_2","data":"{\"brightness_pct\":\"100\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":590,"y":1220,"wires":[[]]},{"id":"99361a7e.8d31a","type":"server-state-changed","z":"bc5d2546.59a7a8","name":"Motion (Living Room)","server":"79e1f09.1e9b71","version":1,"entityidfilter":"binary_sensor.living_room_motion","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":140,"y":1180,"wires":[["70bd03cc.bb15ac"],[]]},{"id":"70bd03cc.bb15ac","type":"api-current-state","z":"bc5d2546.59a7a8","name":"TV On?","server":"79e1f09.1e9b71","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.vizio_smartcast","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":340,"y":1180,"wires":[["92266247.3aa2b"],["4bb15d56.44cfc4"]]},{"id":"4a2cd129.b67358","type":"inject","z":"bc5d2546.59a7a8","name":"","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":true,"onceDelay":0.1,"x":190,"y":1120,"wires":[["70bd03cc.bb15ac"]]},{"id":"5b88d66b.b88578","type":"server-state-changed","z":"bc5d2546.59a7a8","name":"Motion (Living Room Camera)","server":"79e1f09.1e9b71","version":1,"entityidfilter":"binary_sensor.livingroom_camera_motion","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":160,"y":1240,"wires":[["70bd03cc.bb15ac"],[]]},{"id":"79e1f09.1e9b71","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

How can I use both motion sensors while still checking on the status of the TV? There has to be a simpler way.

what is your complete use case: depending on the TV is on or off, you want to turn on the living rooms with different brightness? is that all, you don’t need to turn off the lights at some point?

why do you need the inject node? when a motion detected in one of those sensor, node red will check the state of the TV and turn on the lights either 25% or 100%.

Let me try to clarify.

Without the inject node, the only time the lights will brighten after the TV is turned off is if the flow senses motion. I also want the lights to brighten to 100% if the the TV is turned off without sensing motion. If everyone is sitting in a chair/couch, motion may not necessarily be triggered.

I would also like to dim the lights if no motion is seen for 30 minutes. I haven’t started to work that out, yet.

My other OCD thing is the clutter of having three trigger nodes. I know that I could probably do this with one.

Thanks for the help.

achieving all this in one flow will make it a spaghetti, maybe consider splitting them:

  1. turn on the lights, if the motion detected. if TV is on: 25%, otherwise 100%. just remove the inject node and it’s there. alternatively you can use trigger:state node, with using contains criteria in entity id (assuming you have only 2 entities starting with “binary_sensor.living”

[{"id":"dc83ef5f.2a90e","type":"api-call-service","z":"de9989cc.589d18","name":"Living Room Lamps on 25%","server":"73c1c524.2f66cc","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.living_room_lamp, light.entry_lamp_1, light.entry_lamp_2, light.piano_lamp_1, light.piano_lamp_2","data":"{\"brightness_pct\": \"25\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":720,"y":620,"wires":[[]]},{"id":"e818a48e.cd9a18","type":"api-call-service","z":"de9989cc.589d18","name":"Living Room Lamps on 100%","server":"73c1c524.2f66cc","version":1,"service_domain":"light","service":"turn_on","entityId":"light.living_room_lamp, light.entry_lamp_1, light.entry_lamp_2, light.piano_lamp_1, light.piano_lamp_2","data":"{\"brightness_pct\":\"100\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":720,"y":660,"wires":[[]]},{"id":"419e7681.9a3c68","type":"api-current-state","z":"de9989cc.589d18","name":"TV On?","server":"73c1c524.2f66cc","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.vizio_smartcast","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":420,"y":640,"wires":[["dc83ef5f.2a90e"],["e818a48e.cd9a18"]]},{"id":"6f9bfcd5.fa4b74","type":"trigger-state","z":"de9989cc.589d18","name":"motion sensors on","server":"e447d17a.16a64","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.living","entityidfiltertype":"substring","debugenabled":false,"constraints":[{"id":"g9juudtut8b","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":170,"y":640,"wires":[["419e7681.9a3c68"],[]]},{"id":"73c1c524.2f66cc","type":"server","z":"","name":"Home Assistant","legacy":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true},{"id":"e447d17a.16a64","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]
  1. turn on lights 100% brightness, if TV turned off. use something like this. current state and prev state constraints are handy.
    image
[{"id":"cc881d83.4d926","type":"trigger-state","z":"de9989cc.589d18","name":"TV turned off","server":"e447d17a.16a64","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"media_player.living_room_tv","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"90extnwv38m","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"id":"bowojddxngu","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":130,"y":760,"wires":[["f3f67bbd.dff508"],[]]},{"id":"f3f67bbd.dff508","type":"api-call-service","z":"de9989cc.589d18","name":"Living Room Lamps on 100%","server":"73c1c524.2f66cc","version":1,"service_domain":"light","service":"turn_on","entityId":"light.living_room_lamp, light.entry_lamp_1, light.entry_lamp_2, light.piano_lamp_1, light.piano_lamp_2","data":"{\"brightness_pct\":\"100\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":360,"y":760,"wires":[[]]},{"id":"e447d17a.16a64","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true},{"id":"73c1c524.2f66cc","type":"server","z":"","name":"Home Assistant","legacy":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]
  1. dim the lights if no motion. many options here but I found delay node the simplest

Based on your response, I have designed this flow. I will test it out today to see if it provides what I intend. Thank you for your help and thoughts.