Posts

Showing posts from March, 2022

node-red flow my tears the progammer said

 Having got a couple of weeks of node-red experience. I feel qualified to get a little critical. In my first post on node-red I did already find reason to complain about the lack of namespaces, there was a conflict in my project meaning I failed to access node-red-contrib-crypto-js-dynamic, my code instead called node-red-contrib-crypto-js and failed. My next target is the "flow". Flow is misnamed, there are flows of information through node-red, but what is called a "flow" is simply a named tab where you may put many different flows. If you choose to store information in a flow, you are storing information on the equivalent of a big piece of paper.  Once that piece of paper is full and you need a new one, then your new bit of paper/tab/flow will no longer have access to the information on your first bit of paper/flow/tab. Your only real resort is to use the global context. Both of these issues are a classic case of ease of use, hitting the threshold of big boys/gir

A reliable tuya authentication in node-red

In passing when working with tuya and node-red I had a couple of issues, the first one was conflicts with node-red-contrib-crypto-js-dynamic and node-red-contrib-crypto-js. node-red just doesn't seem clever when it comes to duplicate node names. In this example I have replaced the "hmac" function with a copy called mj_hmac. This can be replaced with the hmac from node-red-contrib-crypto-js-dynamic or failing that you will be unable to pass the tuya secret key as a parameter and will have to enter it in the hmac node dialog. The second issue is that tuya authorisation is on a fixed timeout of two hours.  If you refresh the key at 1 hour and 59 minutes it will only be valid for 1 minute. This flow keeps track of the time remaining and refreshes just after expiry. I have not seen errors since. However as a backup plan I do have sub flows that if they see an error reauthenticate. If anyone is reading and interested I can post them as well. [ { "id" : &qu

Node-red "easy" home automation

A few weeks ago, we had solar panels installed. Not before time given the energy price rises. The question naturally arose as this isn't as yet a battery storage system as to how to use the excess energy when there is any? An obvious answer is to whack on the immersion heater if there is sufficient spare. We are using the Solax Cloud system for monitoring our panels and this provides a very simple API to get all the information needed in one REST call. So next up was to call an electrician to put the immersion on a socket and get a suitably rated smart plug one that doesn't just switch but reports consumption for good measure. Like most smart plugs this is a "tuya" device and so also has an API. So how am I going to program this with any number of languages to choose from? I have a house full of smart gadgets, harmony remotes, hue lights, nest thermostats, alexa routines, but I have never felt the need to look for a programming solution before now as I have never had