[Help] With lights capturing existing state, action then return to state

I’m new to node red, and i am trying to set a flow that does the following:

IF motion is detected
Check time (to set brightness difference for night time)
Capture the existing state of the lights
Flash Red
Restore lights to the existing state.

Now the lights can be off and trigger this flow, or on and trigger this flow.

If they are off when the flow gets triggered I am getting this error:

"Call-service error. /lights/9/state parameter, bri, is not modifiable. Device is set to off."

If they are on, the flow triggers but the lights stay red at the end. is anyone able to help me solve this?

I’ve solved the return to state part so it’s no longer red at the end.
to save the current state


and to restore
image

but now when the lights are off and it triggers, its only white, it wont flash as a colour still get the same error:

"Call-service error. /lights/9/state parameter, bri, is not modifiable. Device is set to off."

So I added this

to turn the light on for 1ms at 1% then flash red, and this works, but then when the lights go back off if triggered from an off state they stay red at the next time lights are turned on normally

check out the scene.create service

This would be a solution whithin NR alone. It stores the state of the light you set, goes red and recovers after 5 seconds. Set your entity_id whithin the inject node for testing. Will work with on off states and will recover the color_temp.

[{"id":"abc695db.c4dd08","type":"api-current-state","z":"937ef78.ec6b408","name":"Get state","server":"9405c3fe.d0a6c","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{entity_id}}","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":240,"y":260,"wires":[["7aaa6b60.fbcaa4"]]},{"id":"b6218c4.ae5967","type":"inject","z":"937ef78.ec6b408","name":"","props":[{"p":"payload"},{"p":"entity_id","v":"light.your_light","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":260,"wires":[["abc695db.c4dd08"]]},{"id":"7aaa6b60.fbcaa4","type":"change","z":"937ef78.ec6b408","name":"store brightness, color temp and service","rules":[{"t":"set","p":"payload.data.brightness","pt":"flow","to":"data.attributes.brightness","tot":"msg"},{"t":"set","p":"payload.data.color_temp","pt":"flow","to":"data.attributes.color_temp","tot":"msg"},{"t":"set","p":"payload.service","pt":"flow","to":"\"turn_\" & payload","tot":"jsonata"},{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"data","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":260,"wires":[["d7868ab4.2997c8"]]},{"id":"d7868ab4.2997c8","type":"api-call-service","z":"937ef78.ec6b408","name":"red","server":"9405c3fe.d0a6c","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"{{entity_id}}","data":"{\"brightness_pct\": 50, \"color_name\": \"red\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":730,"y":260,"wires":[["1f61c6da.c056c9"]]},{"id":"1f61c6da.c056c9","type":"delay","z":"937ef78.ec6b408","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":870,"y":260,"wires":[["2410438e.b9892c"]]},{"id":"ea19ca0.48c5e38","type":"api-call-service","z":"937ef78.ec6b408","name":"","server":"9405c3fe.d0a6c","version":3,"debugenabled":false,"service_domain":"light","service":"","entityId":"{{entity_id}}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1310,"y":260,"wires":[[]]},{"id":"2410438e.b9892c","type":"change","z":"937ef78.ec6b408","name":"brightness and color_temp recovery","rules":[{"t":"set","p":"payload.data.brightness","pt":"msg","to":"payload.data.brightness","tot":"flow"},{"t":"set","p":"payload.data.color_temp","pt":"msg","to":"payload.data.color_temp","tot":"flow"},{"t":"set","p":"payload.service","pt":"msg","to":"payload.service","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":260,"wires":[["ea19ca0.48c5e38"]]},{"id":"9405c3fe.d0a6c","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}]
1 Like

i am using scenes to capture the state and then calling it later after the flash
image

are you saying to forget that and let NR do the work?

And what problems do you find with the scene.create service? it should do it, doesn’t it?

I just gave you some input on how to do in whithin NR. It’s up to you afterall

To solve the inconsistent behavious in the past I used to set a 2 second delay after the scene.create call service, to make sure the servive was catching the right states of the lights.

As far as I remember it used to delay when catching the state thus catching the wrong attributes so I ended up not using the scene.create service.

Come to think of it, one workaround for using the scene create without falling in this delay issue, you could do this:

[{"id":"c3f4967f.9d6718","type":"server-state-changed","z":"937ef78.ec6b408","name":"Light changes?","server":"9405c3fe.d0a6c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.1, light.2, light.3","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":240,"y":260,"wires":[["c4990825.1526c8"]]},{"id":"c4990825.1526c8","type":"api-call-service","z":"937ef78.ec6b408","name":"Scene create","server":"9405c3fe.d0a6c","version":3,"debugenabled":false,"service_domain":"scene","service":"create","entityId":"","data":"{\"scene_id\":\"noderedmasterbedroom_currentstate\",\"snapshot_entities\":[\"light.1\",\"light.2\",\"light.3\"]}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":440,"y":260,"wires":[[]]},{"id":"9405c3fe.d0a6c","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}]

By unchecking the “current state equals previous state” from the first node, the flow will trigger whenever any of the attributes changes thus creating an updated scene. You should disable this flow when you want to flash it red and enable it again when the flash has ended, otherwise it’ll create a new scene with the red flash and this flow will be useless.

Find a way to trigger this flow on startup too since scenes created with this service vanish upon restarts.

This way you’ll always have your scene updated to the latest states.

1 Like

ill have a look at it thanks for the input

1 Like