I wanted to get your opinion on the usage of Node RED and MQTT. Recently I have been moving from integrating mosquitto with openhab to integrating with node-red.
What I mean with that is that instead of configuring the mqtt channel on the item in openhab, I only create the item in openhab. Then instead of updating the state of the item through openhab mqtt integration, i created a MQTT receiving node in Node-RED and use that to transform where needed (change node) and update the item state in openHAB.
The main benefit for me is that I dont need to mess around with java scripts to do my simple transformations and can handle these with the change node in Node-RED.
For example if my motion sensor sends an MQTT message with “occupancy:false”, I can easily use a change node in Node-RED with “if contains false, set payload to OFF” and send that payload to the item state for my motion sensor (Switch)
The motion sensor was just an example. I also have temp/hum, contact and vibration sensors and switches in the system.
I will continue with node-red for my transformations and use openHAB for managing the item states.
Running a completely separate service just to avoid using a transformation that you probably don’t need to be using anyway seems like a way to avoid a little bit of work now (learning how to properly use transformations) at the expense of a lot more work later on (upgrades, breakages in NodeRed or openHAB, etc). I wouldn’t recommend it.
If you were using NodeRed for other features of NodeRed beyond doing this transformation then that is something else entirely. In that case you’d be using NodeRed anyway so most of those extra long term costs will have to be paid anyway. Therefore the little bit of labor you save up front doesn’t result in extra work long term so it’s not that bad of a choice.
As a for instance, if you have a message “temperature: 20 °C” a simple “REGEX(temperature: (\d+)°C” would do the job.
Thanks for your elaborate response. I will have a closer look at what REGEX can do for me. It might be more manageable then using NodeRed as that requires several nodes to achieve a item state update.
As a side note I am also using NodeRed as a rule engine so it is not purely for these kind of transformations.
How about when it comes to switches (single tap , double, long hold, etc)?
If it’s about using the raw button channel events and you use node red, we had a long thread about different approaches how to use them in node red directly starting at this post continuing quite a bit down Node-RED as Alternative Rule Engine