Based on the work of @notenoughtech, I've finally managed to get a battery powered Tuya TRV talking to Node-Red. There were a some breaking changes in his example flows which I can pass on to anyone who is interested.
Whenever target temperature is changed within NR the green 'BR Target Temp' node will fire with the new value as msg.payload. At that moment, I need to send it AND msg.time to 'Hash the Body Data' node. I can't work out how to do this.
Also, I need the the payload of 'Sign SignStr with Secret' to appear at the 'function' node at the same time as the payload from BR Target Temp - because BR Target Temp payload is used again and sent to 'http request' as a "code:value" pair. Again, I can't work out how to do this.
Thanks @ThingsTinkerer. I've used your suggestion (var now = new Date(); works better than const now = new Date();). That's addressed that issue.
I'm now trying to combine 2 inputs to give me a msg.payload and a msg.header.
var bright = msg.bright;
msg.header = '{"commands":[{"code":"bright_value_v2","value":bright}]}';
In my head, the code above should take the incoming value of msg.bright, assign it to the var bright and drop the value into the formula, but it doesn't. It outputs the work bright instead of the value.
I don't think I'll ever get my head around scripting - 30 years of structured 'C' programming is holding me back and means I have to rely on my extended brain, which is people like you!
I now have msg.time, msg.command and msg.payload arriving at the function node, but because they come from 2 different nodes, the data arrives at different times, firing function twice, neither with all of the information required.
How can I combine information from 2 nodes and have it arrive and be processed at the same time?
That's gonna be more complicated. There are 2 options:
context (store values in memory)
join node
Context is manual so you need to control the logic yourself. I suggest using node context in the function node where the messages are to be merged. With join node, you can achieve this grouping automatically, but you need to add a parts object to all the incoming messages.
Thanks @ThingsTinkerer. Which way would you do it?
It's difficult to see why Tuya feel the need to encrypt twice; 256 bit encryption is a challenge once, so encrypting my radiator valve setting twice seems a bit OTT!
Presumably someone, somewhere has implemented a Tuya Cloud flow using NR, so a solution should already exist....
The only thing (I think!) I need to do now is to convert msg.payload from an object to a string in order for the message to look like it does in the 'hard coded' version of my code where the value is injected.
In Javascript, it's as easy as doing JSON.stringify(msg.payload);. For combining 2 messages, I think I would try with join node (automatic), adding parts object to each message first.