Get value from an object with complex title

I'm sorry if this has been answered already but I can't seem to find my specific case.

I fetch values from an SQL database and want to use these in graphs and charts of the dashboard module. For some values I sum various fields in a single SQL statement and want to use that combined output.

I know you can transfer values using a function or change node with a payload statement like "msg.payload.item"

However with complex SQL statements it tells me the node is invalid.

The SQL statement is something like:

msg.topic ='select (`Solar_zuid`+`Solar_west`+`Solar_oost`+`Solar_center`+`Solar_new`) from power order by Timestamp desc limit 1'
return msg;

What I would get is something like:
(Solar_zuid+Solar_west+Solar_oost+Solar_center+Solar_new): 1234 }

Obviously I just need that value "1234".

Thanks for your help!

Welcome to the forum Lars.

Give your calculated value an alias:

msg.topic ='select (`Solar_zuid`+`Solar_west`+`Solar_oost`+`Solar_center`+`Solar_new`) as total from power order by Timestamp desc limit 1'

The output should be an object {"total":1234}
and the value should be msg.payload.total

Edit - the output is probably an array of one or more objects so you may need msg.payload[0].total

1 Like

Thanks Jbudd that did the trick!

So simple it turns out! You just need to know it :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.