How to send sequential MQTT commands?

Hi everyone,

I am controlling a Hue bulb via MQTT, please see the image for example commands. I would like to be able to sequentially send commands, with a time interval in-between.

Example requirement 1:
Change colour to red
Send breathe effect
Change colour back to original

Example requirement 2:
Send blink effect
Change brightness to 0%
Timer for 25mins
Set brightness to 100%

Currently I am able to achieve example 2 with two trigger nodes, but I'm thinking there's a better way.

Example flow and image:

[{"id":"32ea31c.fdaa2ce","type":"inject","z":"be5275e8.e06c78","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"state\": \"TOGGLE\"}","payloadType":"str","x":180,"y":260,"wires":[["771df0dd.4182f"]]},{"id":"d6ef1d4f.d3bbb","type":"inject","z":"be5275e8.e06c78","name":"Brightness 128 (0-254)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"brightness\": 128}","payloadType":"str","x":190,"y":300,"wires":[["771df0dd.4182f"]]},{"id":"274eb720.4bed68","type":"inject","z":"be5275e8.e06c78","name":"Brightness 254 (0-254)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"brightness\": 254}","payloadType":"str","x":190,"y":340,"wires":[["771df0dd.4182f"]]},{"id":"719b3dc2.9f4344","type":"inject","z":"be5275e8.e06c78","name":"Brightness 254 (0-254) 3s transition","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"brightness\":254,\"transition\":3}","payloadType":"str","x":230,"y":420,"wires":[["771df0dd.4182f"]]},{"id":"9efad94e.13cd48","type":"inject","z":"be5275e8.e06c78","name":"Brightness 128 (0-254) 3s transition","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"brightness\":128,\"transition\":3}","payloadType":"str","x":230,"y":380,"wires":[["771df0dd.4182f"]]},{"id":"de76be8d.2109d","type":"inject","z":"be5275e8.e06c78","name":"RED","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"state\": \"ON\", \"color\": {\"r\":255,\"g\":0,\"b\":0}}","payloadType":"str","x":140,"y":480,"wires":[["771df0dd.4182f"]]},{"id":"6eba34cd.40425c","type":"inject","z":"be5275e8.e06c78","name":"WHITE","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"state\": \"ON\", \"color\": {\"r\":255,\"g\":255,\"b\":255}}","payloadType":"str","x":140,"y":520,"wires":[["771df0dd.4182f"]]},{"id":"8136de4d.1c46a","type":"inject","z":"be5275e8.e06c78","name":"WARM WHITE","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"state\": \"ON\", \"color\": {\"r\":246,\"g\":205,\"b\":139}}","payloadType":"str","x":170,"y":560,"wires":[["771df0dd.4182f"]]},{"id":"b770ee26.83e3a","type":"inject","z":"be5275e8.e06c78","name":"blink","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"effect\": \"blink\"}","payloadType":"str","x":140,"y":640,"wires":[["771df0dd.4182f"]]},{"id":"9a010167.7c088","type":"inject","z":"be5275e8.e06c78","name":"breathe","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"effect\": \"breathe\"}","payloadType":"str","x":140,"y":680,"wires":[["771df0dd.4182f"]]},{"id":"f50019d1.6ac198","type":"inject","z":"be5275e8.e06c78","name":"okay","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"effect\": \"okay\"}","payloadType":"str","x":140,"y":719,"wires":[["771df0dd.4182f"]]},{"id":"b91dc597.ad0998","type":"inject","z":"be5275e8.e06c78","name":"channel_change","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"effect\": \"channel_change\"}","payloadType":"str","x":170,"y":759,"wires":[["771df0dd.4182f"]]},{"id":"4078e819.89ac08","type":"inject","z":"be5275e8.e06c78","name":"finish_effect","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"effect\": \"finish_effect\"}","payloadType":"str","x":160,"y":799,"wires":[["771df0dd.4182f"]]},{"id":"564dc1e4.9fa2c","type":"inject","z":"be5275e8.e06c78","name":"stop_effect","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"effect\": \"stop_effect\"}","payloadType":"str","x":150,"y":839,"wires":[["771df0dd.4182f"]]},{"id":"2c2e8d32.8f44b2","type":"inject","z":"be5275e8.e06c78","name":"warm","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"color_temp\": \"warm\", \"transition\":0.5}","payloadType":"str","x":490,"y":780,"wires":[["771df0dd.4182f"]]},{"id":"43a72856.590158","type":"inject","z":"be5275e8.e06c78","name":"cool","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"color_temp\": \"cool\", \"transition\":0.5}","payloadType":"str","x":490,"y":700,"wires":[["771df0dd.4182f"]]},{"id":"5c482c34.d43174","type":"inject","z":"be5275e8.e06c78","name":"coolest","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"color_temp\": \"coolest\", \"transition\":0.5}","payloadType":"str","x":490,"y":660,"wires":[["771df0dd.4182f"]]},{"id":"9b821b66.de3188","type":"comment","z":"be5275e8.e06c78","name":"coolest, cool, neutral, warm, warmest","info":"","x":550,"y":860,"wires":[]},{"id":"899e1d9e.3c954","type":"inject","z":"be5275e8.e06c78","name":"neutral","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"color_temp\": \"neutral\", \"transition\":0.5}","payloadType":"str","x":490,"y":740,"wires":[["771df0dd.4182f"]]},{"id":"2d3a6ecd.1bb882","type":"inject","z":"be5275e8.e06c78","name":"warmest","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"color_temp\": \"warmest\", \"transition\":0.5}","payloadType":"str","x":500,"y":820,"wires":[["771df0dd.4182f"]]},{"id":"cd15b7c6.1ca0b8","type":"inject","z":"be5275e8.e06c78","name":"Startup: neutral","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"color_temp_startup\": \"neutral\"}","payloadType":"str","x":570,"y":310,"wires":[["771df0dd.4182f"]]},{"id":"771df0dd.4182f","type":"debug","z":"be5275e8.e06c78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":520,"wires":[]}]

You could have commands in an array and use split node to send individual commands, with possible delays between each.
e.g.

[{"id":"d6ef1d4f.d3bbb","type":"inject","z":"5a245aa1.510164","name":"Brightness 128 (0-254)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"{\\\"state\\\": \\\"ON\\\", \\\"color\\\": {\\\"r\\\":255,\\\"g\\\":0,\\\"b\\\":0}}\",\"{\\\"effect\\\": \\\"blink\\\"}\",\"{\\\"state\\\": \\\"ON\\\", \\\"color\\\": {\\\"r\\\":255,\\\"g\\\":255,\\\"b\\\":255}}\"]","payloadType":"json","x":200,"y":2960,"wires":[["e4c3c2c8.f3c9d8"]]},{"id":"e4c3c2c8.f3c9d8","type":"split","z":"5a245aa1.510164","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":400,"y":2960,"wires":[["771df0dd.4182f"]]},{"id":"771df0dd.4182f","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":550,"y":2960,"wires":[]}]

You could have a lookup table of commands and just send the keys to create the commands array on the fly if you wished. You could also do all this in a function node, using node.send().

1 Like

If the intervals are fixed then you could send them all at once and pass that through a Delay node in Rate Limit mode.

1 Like

@E1cid @Colin thanks both, between the two suggestions I already have a better solution!

Are you going to share it?
It may help others reading this topic.

2 Likes

I see how my wording was not clear, I should have typed, ....now I have a better solution. I was referring to the solution in the earlier comments....

I always like to share the solution, normally I find my own posts many months later!
Here is the flow combining the two recommendations:

[{"id":"e5b27cff.d8a45","type":"inject","z":"be5275e8.e06c78","name":"Mutltiple commands in JSON format","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"{\\\"state\\\": \\\"ON\\\", \\\"color\\\": {\\\"r\\\":255,\\\"g\\\":0,\\\"b\\\":0}}\",\"{\\\"effect\\\": \\\"blink\\\"}\",\"{\\\"state\\\": \\\"ON\\\", \\\"color\\\": {\\\"r\\\":255,\\\"g\\\":255,\\\"b\\\":255}}\"]","payloadType":"json","x":220,"y":950,"wires":[["6a20483c.6e3928"]]},{"id":"6a20483c.6e3928","type":"split","z":"be5275e8.e06c78","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":460,"y":950,"wires":[["61a44d40.64e014"]]},{"id":"94673838.562f08","type":"debug","z":"be5275e8.e06c78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":950,"wires":[]},{"id":"61a44d40.64e014","type":"delay","z":"be5275e8.e06c78","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":630,"y":950,"wires":[["94673838.562f08"]]}]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.