I am only using node-red to send audio notifications to my Google home devices. And still testing whether to use the Google cast or castv2 nodes.
For the castv2 nodes a special message form is required which, according to the creator, is best to setup in a function node and send it directly to the castv2 node.
each command has to be send separately to the castv2 node. E.g. if an audio message has to be send to a Google home device with a certain volume, then this are 3 commands: first the volume change command and then the audio command and then the volume back to the original level.
To avoid errors these commands are send in a sequence, the second and third command with a delay.
This works perfectly with the setTimer command and it only takes one function node.
The flow you see in this thread is using the cast node, which has a different message structure. This node sends audio and volume change in one command. For this node I could use the change node and a trigger node, but the reason that the castv2 node was created was because the audio and volume in one message to the Google home devices caused many times errors.
Recently the node-red-contrib-cast node was updated, so I am testing if this update has a better performance.
But both cast nodes, have no problem with the setTimeout function, so I think I will stick to this method, unless you can convince me of the disadvantages using, this function
None of that makes any difference to my comments. As you have given the impression of being relatively inexperienced in these matters I was just pointing out that it is possible to manage without javascript, using the built in nodes instead. There is nothing wrong with using a Function node though it can be more tricky to make sure you have coded for every eventuality. For example, have you considered whether you need to worry about what will happen if another message comes in before the timeouts have run down?
That I am for sure...trial and error is my learning curve.
And I appreciate everyoneâs advice
This taking care in the domoticz script. The 2 delayed messages are only send when the device is ON, if the device is set to off before the the delay time is reached, then these 2 messages are not send to mqtt.
The function node only compares the string values, so other messages but these 4 strings I mentioned donât pass the node.
I have other cast flows for example doorbell. It can happen that someoneâs at the door at the same time one of the âfrietpanâ audio message is send to the same device...i donât have a solution for that yet...also never tested what will happen...also quite difficult to trigger the exact same time for both messages I guess?
The function node will still send the delayed messages even if the device is off, do you mean something else will stop them going any further?
Also what would happen if it were switched off and then on again before the function node sends its delayed messages?
Since node red is single threaded they can only be one after the other, not at exactly the same time. You can test this by, for example, simulating it by writing a function node that sends one message immediately followed by the other. Or a trigger node could do a similar thing.
No, I think you misunderstand me. The on/off switch and the script which handles the messages (delay included) already take place in domoticz. This script wonât send both delayed messages to mqtt and telegram if the switch is turned off before the first delay time is reached. And also not the last delayed message if switched off between the first and second delay time.
So the node-red flow only has to wait until a (delayed) message arrives, and then cast an audio clip to my Google home devices depending on the type of message. It doesnât know that this message is delayed, it just triggers an audio clip if a certain text string is incoming.
Now I certainly am confused. The function you posted sends a message (msgFrietpanKlaar or the other one) and after 7 seconds delay sends another message (msgVolumeBack). That is the delayed message I am talking about, and what will happen in your function node if it gets another input message before the msgVolumeBack message has been sent.
Oh sorry hahaha, that delay is for the duration of the audio clip. This audio cast has to finish first before the volume can be turned down.
Well the audio cast will be overruled by the next one. But that could only be an audio cast of a doorbell, which is also one of my flows or when Google home starts to talk on its own. But that would be quite a coincidence. I doubt if I can prevent this with a code, and as a backup I still have the telegram notifications.