Help! NodeRed and MQTT

When you are sending a message to the HE command node you need to specify both a
"msg.command" and "msg.arguments". You can do this by using a "change node" setting those properties as needed based on the payload from the "MQTT IN" node..

Also note that the value coming from the "MQTT IN" node is always a string I think.

Thanks! So what would I populate in the rules section?

Maybe try something like this.. I haven't used that device so not completely sure..

It's been a while since I've messed with attributes.. usually just switches and such. That last bit is a "jsonata" expression that converts msg.payload to a number..

Don't take this the wrong way, as it is meant to be constructive....

  1. I would strongly recommend that you go read the node-red documentation, and work through the examples/tutorials. It covers all basic node types like switch, change, etc as well as the basic concepts of msg.payload and msg.payload objects
  2. Make sure you look at the online help for a node-red node. They almost always list what valid inputs are to the node. In the case of the hubitat command node it explicitly tells you that you need to specify msg.command and msg.arguments in the incoming message if you want it to be set dynamically.

Nothing wrong with asking for help - so I'm not trying to discourage you. But there is no substitute for reading the (very well written) documentation either.

3 Likes

@daniel.john.edge What is the complete message object coming out of the MQTT node?

@erktrek Also, if setEnergy is selected in the Edit Command Node screen, it doesn't need to be part of the Change Node also does it?

3 Likes

Yeah you are right although I generally send both for completeness/best practices. I assumed the value @daniel.john.edge was pulling from MQTT was a number if not then more JSONATA magic might have to occur....

btw and slightly off topic.. jsonata really rocks for this stuff. You can do some crazy things.. (tooting my own horn slightly here so apologies)

2 Likes

This is whats coming out of the MQTT node:

HAStateStream50/sensor/emoncms_use/state : msg.payload : string[5]
"603.0"

I’m just lost in terms of how to configure the change node to pass msg.payload as an argument to setEnergy in the command node

Do I need to handle the conversion from string to number?

No need to convert to a number, the command node/Maker API should cast it correctly on its own. If not, THEN go through the effort to explicitly convert it.

2 Likes

Does it matter if it's a string or not? That's why I converted..

1 Like

Don't think so. I have never explicitly converted any value I've sent to a command node - I just leave them as whatever they are coming in - string, number, other. The Hubitat side will attempt to cast it to the expected type regardless.

2 Likes

I was very close ! I had the to arguments for the set reversed for some reason!
That’s sorted it! And values now flowing through!

Thanks all for your help!

Are there any considerations for throttling the updates to hubitat? This is an energy monitor (running on an emonpi) - its publishing the current electricity usage to my MQTT broker - the value is updated very frequently..

There are only 3 inputs (max) to a hubitat command node - anything else in the message (like msg.payload) will just be ignored.

Also note that the command node documentation states the inputs are expected to be strings. So if you send it a number it is likely converting it to a string before sending to Maker API anyway...

There is an RBE node and a third party throttle node as well.. which I've used on occasion.

You can also throttle with the built-in delay node as well.

3 Likes

So many possibilities with NR... I can't thank you enough for bringing it to my attention and all the early stuff you did.

2 Likes

Great! I’ll give that a go!!

2 Likes

Thanks Again! And I’ll go RTFM :slight_smile:

I really do mean that in the nicest way possible :slight_smile: . The node-red tutorials are very good. And knowing that the online node info typically lists allowed inputs is really useful to know/reference as well.

1 Like

Yes - you’re right - I was getting myself lost in some of the basic concepts - but I’ll work my way through the tutorials - they do seem good!

1 Like

No worries, and while this isn't a node-red specific help forum, there are many people on here that use it and can try to help in a pinch!

1 Like