Use flow.data as data attribute of call_service Node

Hi,

I want to automate my Cinema Mode.
Whenever my Chromecast starts 1 Media App (lets say Netflix) I want to save the state of the current light (via switchnode I copy the value of msg.payload, msg.topic and msg.data into flow variables.

If the Sensor Reports that none of the Apps is running it should switch on the lights with given attributes from a switchnode which writes my flow variables back into the message).

My Debug Nodes tell me that my message really contains all the information I had stored before.
Now the challenge I’m struggling with:
How can I use the HA call service with the payload, topic and most importantly the data of the msg. passed through?

[{"id":"4ff54085.5e9c6","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"53d94457.1f2aec","type":"inject","z":"4ff54085.5e9c6","name":"","topic":"","payload":"None","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":320,"wires":[["124d1156.74b357"]]},{"id":"124d1156.74b357","type":"switch","z":"4ff54085.5e9c6","name":"Rly?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Netflix","vt":"str"},{"t":"eq","v":"None","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":320,"wires":[["52696a25.511174","b9849f6e.976ef"],["605a5dd1.43add4"]]},{"id":"b9849f6e.976ef","type":"api-current-state","z":"4ff54085.5e9c6","name":"Status Office Light","server":"18b877af.344b38","halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"override_payload":true,"override_data":true,"entity_id":"light.gruppebuero","state_type":"str","outputs":1,"x":470,"y":240,"wires":[["f56c628d.9b5fc"]],"outputLabels":["flow.test"]},{"id":"52696a25.511174","type":"delay","z":"4ff54085.5e9c6","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":340,"wires":[["5b073278.9b0824"]]},{"id":"605a5dd1.43add4","type":"change","z":"4ff54085.5e9c6","name":"load from flow variable","rules":[{"t":"set","p":"payload","pt":"msg","to":"payloadsavewz","tot":"flow"},{"t":"set","p":"topic","pt":"msg","to":"topicsavewz","tot":"flow"},{"t":"set","p":"data","pt":"msg","to":"datasavewz","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":420,"wires":[["a23d4086.ef0198","f3152942.8f3d98"]]},{"id":"3d0e84c0.357bcc","type":"debug","z":"4ff54085.5e9c6","name":"Save","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":860,"y":180,"wires":[],"inputLabels":["flow.wz"]},{"id":"f56c628d.9b5fc","type":"change","z":"4ff54085.5e9c6","name":"save to flow variable","rules":[{"t":"set","p":"payloadsavewz","pt":"flow","to":"payload","tot":"msg"},{"t":"set","p":"topicsavewz","pt":"flow","to":"topic","tot":"msg"},{"t":"set","p":"datasavewz","pt":"flow","to":"data","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":240,"wires":[["3d0e84c0.357bcc"]]},{"id":"5b073278.9b0824","type":"api-call-service","z":"4ff54085.5e9c6","name":"turn_on_movielights","server":"18b877af.344b38","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.gruppebuero\",\"brightness\":\"10\",\"rgb_color\":[0,255,0]}","render_data":false,"mergecontext":"","output_location":"","output_location_type":"none","x":660,"y":340,"wires":[[]]},{"id":"a23d4086.ef0198","type":"api-call-service","z":"4ff54085.5e9c6","name":"Office Light","server":"18b877af.344b38","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.gruppebuero\"}","render_data":true,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":670,"y":420,"wires":[["4e6e0895.5924e"]],"inputLabels":["payload.data"]},{"id":"4e6e0895.5924e","type":"api-current-state","z":"4ff54085.5e9c6","name":"Status Office Light","server":"18b877af.344b38","halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"override_payload":true,"override_data":true,"entity_id":"light.gruppebuero","state_type":"str","outputs":1,"x":870,"y":420,"wires":[["3dee6019.f0685"]],"outputLabels":["flow.test"]},{"id":"f3152942.8f3d98","type":"debug","z":"4ff54085.5e9c6","name":"Restore","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":670,"y":480,"wires":[]},{"id":"3dee6019.f0685","type":"debug","z":"4ff54085.5e9c6","name":"Debug","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":860,"y":480,"wires":[]},{"id":"c42614bc.bc7f28","type":"inject","z":"4ff54085.5e9c6","name":"","topic":"","payload":"Netflix","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":260,"wires":[["124d1156.74b357"]]},{"id":"18b877af.344b38","type":"server","z":"","name":"<Insert your Server here>","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}] ```
1 Like

I do something similar, here’s an extract from the flow.

Write the info about the light entity to the message, but a variable would work too (directly from the current state node)

Then I dim the lights, later I reset the light using the data stored previously.

Here’s the expanded data cell

2 Likes

Thanks for the reply.
My current state node doesn’t provide something like “entity location”, maybe thats due to a different version of the unraid docker.

But however. With "brightness": "{{data.attributes.brightness}}" I was able to raise the brightness to the 100% it was before.

How would I do the same with an array, of lets say RGB Values? My attempts don’t work. Since rgb values exspect an array I tried to set every value by itself.

mustache templates use dot notation even for arrays
{{data.attributes.rgb_color.0}}

1 Like

Thank you. This is absolutely brillant and solved something I’ve been sweating on for a long time. I wanted to use the state of brightness of “light #1” to synchronize the brightness of “light #2”

[{"id":"e90bf93c.3ccf88","type":"server-state-changed","z":"cbd6d85d.24f998","name":"Light 1","server":"a0eea9da.0fe1d8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.office_ikea_panel","entityidfiltertype":"exact","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,"x":170,"y":640,"wires":[["ce8cfe44.8a014"]]},{"id":"ce8cfe44.8a014","type":"api-current-state","z":"cbd6d85d.24f998","name":"State","server":"a0eea9da.0fe1d8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.office_ikea_panel","state_type":"str","state_location":"","override_payload":"none","entity_location":"officebrightness","override_data":"msg","blockInputOverrides":false,"x":310,"y":660,"wires":[["203d893c.f65876"]]},{"id":"203d893c.f65876","type":"api-call-service","z":"cbd6d85d.24f998","name":"Light 2","server":"a0eea9da.0fe1d8","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.office_light_1, light.office_light_2, light.office_light_3","data":"{\"brightness\":\"{{officebrightness.attributes.brightness}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":470,"y":640,"wires":[["3cb8d13b.b307be"]]},{"id":"3cb8d13b.b307be","type":"debug","z":"cbd6d85d.24f998","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":640,"wires":[]},{"id":"a0eea9da.0fe1d8","type":"server","name":"Home Assistant New","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

The entity is a lamp with adjustable color temperature, how to synchronize the color temperature at the same time