Issue with trying to flash light, short delay then turn off

Hi,

I want to use following approach to switch off some lights: flash, delay for a short period of time, then switch
off. Below flow breaks, as rather than calling turn_off in the last node, the last node repeats the toggle/flash call from the previous node. Any way to avoid this apart from adding a change node in between?


Thanks

[{"id":"ebd52ecd94687f37","type":"inject","z":"cd2fe3da8e670daa","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":300,"y":1540,"wires":[["00d955ab647ed421"]]},{"id":"00d955ab647ed421","type":"api-call-service","z":"cd2fe3da8e670daa","name":"Light Flash","server":"35ec02d8.34fade","version":5,"debugenabled":false,"domain":"light","service":"toggle","areaId":[],"deviceId":[],"entityId":["light.zolder"],"data":"{\"flash\":\"short\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","output_location":"payload","output_location_type":"msg","x":510,"y":1540,"wires":[["3132484583840fd2"]]},{"id":"3132484583840fd2","type":"delay","z":"cd2fe3da8e670daa","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":700,"y":1540,"wires":[["96c8455842fe3442"]]},{"id":"96c8455842fe3442","type":"api-call-service","z":"cd2fe3da8e670daa","name":"Light Off","server":"35ec02d8.34fade","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.zolder"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":900,"y":1540,"wires":[[]]},{"id":"35ec02d8.34fade","type":"server","name":"Home Assistant Odroid","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]

It should not do that, but maybe the output of the call service node contains information in the message that override the settings of the last call service node.
Try to connect the delay directly to the inject node instead and see if this changes or add a debug node to the light flash node with the output set to the complete message.

Connecting the inject node directly makes the last node work as expected. the message does indeed seem to override the behavior of the last node - not sure if this should be logged as a bug?

Replacing delay with a trigger node solves the issue for now.

Its not a bug. You have your msg.payload=sent data. This means that the options you specify in the data field for flash and short continue downstream to the other call service node, and are then used in that node as well.

Screenshot from 2022-12-20 09-27-46

If you change the dropdown to timestamp or something else, that should stop those options from flowing into the other node.

Thanks Tim,

I understand. But this means all fields we fill in when creating home assistant related nodes are optional and will be overwritten if a corresponding message comes in?

Feels counterintuitive, but who am I to judge :slight_smile:

I looked at your flow again and it looks different from mine - I think you are running an older version and this might be handled better in newer versions of node-red-contrib-home-assistant-websocket (node) - Node-RED

What version are you running? You should be able to go to click the hamburger menu at the top right and click “manage palette” to update it. Be aware that there have been breaking changes that might impact you (release notes here - Releases · zachowj/node-red-contrib-home-assistant-websocket · GitHub )

Hi Tim, I run v14.0.0 of the Node Red Addon (latest) which incorporates v 3.0.2 of Node-red i believe

It has 0.47.1 of the node-red-contrib-home-assistant-websocket (node) - Node-RED

So i should be quite up2date

Ok so not a version issue. I run in docker and I believe you’re running the addon so things look a little different sometimes between them.

That’s the way I’ve always understood it to work. I just tried this and clicking the inject node sets the light to the 100% specified in the function node versus the 50% specified in the data field of call service node. Msg.payload seems to always override what is specified in the node’s data.

[{"id":"e91ff268bca28cdd","type":"api-call-service","z":"65d4f7b6aa8e19da","name":"Light","server":"ae531ce.a39906","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.sunroom_light"],"data":"{\"brightness_pct\":50}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":490,"y":160,"wires":[[]]},{"id":"e5b7d4ba2bfea820","type":"inject","z":"65d4f7b6aa8e19da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":160,"wires":[["a45ffec4a270933e"]]},{"id":"a45ffec4a270933e","type":"function","z":"65d4f7b6aa8e19da","name":"Brightness","func":"var payload = msg.payload;\nmsg.payload =  {  \n      \"data\":{  \n         \"brightness_pct\":100\n      }\n   }\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":160,"wires":[["e91ff268bca28cdd"]]},{"id":"ae531ce.a39906","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}]

I would think that would be what a lot of people want though - a default defined in the data field, with a way to override it in a different circumstance with a different message/setting. I’m sure you could post on the Github page if you have other ideas for how it should work. I agree it might be nice to have a toggle that says “override msg.payload” or something like that.