#Node Red Automation help - Storing and restoring light settings

12 messages · Page 1 of 1 (latest)

modern eagle
#

I'm trying to make a node-red automation that will, when a movie is played on a device check the settings of the two lamps that I have in the livingroom and store that information, and then set the lamps to a specific colour and brightness. If the movie is paused lift the brightness of the those lamps, and if the movie is stopped put the lights back in what ever state they were in. I've got this far, but i'm not sure if i'm on the right path.

https://pastebin.com/0hzRMKWg

Thanks.

west mica
#

Right now, your only trigger is not idle, though, too

#

So, it's only going to evaluate any of this when the media_player goes from idle->something else

#

I think your playing/paused/stopped switch is on the wrong property too, currently set to msg.data.new_state.attributes.media_content_type

#

But it sounds like whatever property that should be, should actually be the triggering attribute

#

That way this triggers anytime that attribute changes

modern eagle
#

i'm not too worried about teh switch logic i can figure that out, its the store and restore state that i'm having issues with. The nodes beloe produce this error:
"HomeAssistantError: extra keys not allowed @ data['0']"

[{"id":"28753778786b243f","type":"function","z":"68f343f366ce4cfb","name":"RestoreConsole Lamp","func":"// Retrieve the light state from flow context\nvar lightState = flow.get('ConsolelightState');\nif (lightState) {\n msg.payload = 'ConsolelightState'; // Prepare the payload for the light\n} else {\n msg.payload = { "error": "No state saved" }; // Handle the case where no state is saved\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1400,"y":1120,"wires":[["755ee213ed232525"]]},{"id":"755ee213ed232525","type":"api-call-service","z":"68f343f366ce4cfb","name":"Restore Console Lamp","server":"3d7d30f6.8912c","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":["65202bce3273e4af299c10cdbef94648"],"entityId":[],"data":"msg.payload","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1660,"y":1120,"wires":[["a3cf829140ea1439"]]},{"id":"3d7d30f6.8912c","type":"server","name":"Home Assistant","version":5,"addon":false,"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","enableGlobalContextStore":true}]

#

This is the save node.

[{"id":"434c8e1b73796b5c","type":"api-current-state","z":"68f343f366ce4cfb","name":"Get Console Status","server":"3d7d30f6.8912c","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.console_lamp","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":1390,"y":820,"wires":[["0e8f86cc5820cd50"]]},{"id":"0e8f86cc5820cd50","type":"function","z":"68f343f366ce4cfb","name":"Save Current Lamp Settings","func":"// Store the light state in flow context\nflow.set('ConsolelightState', msg.payload);\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1720,"y":820,"wires":[["8d6a61599e430122"]]},{"id":"3d7d30f6.8912c","type":"server","name":"Home Assistant","version":5,"addon":false,"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","enableGlobalContextStore":true}]

west mica
modern eagle
#

well that was much easier than expect. Thank you so much. Scene create, and scene_turn did the job!
Thanks!

modern eagle
#

one thing i've just realised is that if i pause and then play it will save the ew state of the lights, is there of using setting up a current state node that if the last msg.payload was paused it stops the message?