Appending an attribute to an incoming message from a flow context

Hi,
i'm new here, thank you for the great forum, well i'm playing with interactive ui-tables, and i have this specific table containing my temperature sensors on the same table i have a column which is editable. The column (isUsedForHeating) should configure whether a temperature sensor should be considered when controlling my heating system, e.g i want for instance if a room is not currently used then the heater should not switch on because the temperature is too low in the specific room.

So the attribute "isUsedForHeating" can be edited by a user directly in the table. That is not a problem since i get a callback from the table and i can change the flow context.

My problem is only when a new temperature value is received i cant append the value from the context directly.
image
i would imagine to use a change node and do the following:


but how can i get the <msg.topic>, (the device name is unique and passed through msg.topic)? Or what would be the best way to append the attribute from the stored context?

This is the table:

I'm a C programmer so please excuse my limited java script skills.

Thanks in advance!

Regards
ChankyTheConqueror

Hi.

I'm no expert, but here's a try.

Looking at what you said I think I understand what you mean.

You get the incoming message and pass it through a change node to set part of the message to a flow.context value.

That part is editable on the table as shown above.

So what is it you then want to do?

Maybe a screen shot of that part of the flow would help too. (Not all of it)

Is it you want the column that is labelled as "Used for heating" to be the topic value?

Hi,
Yes i want to pass it through a change node and append the attribute. I think i'm almost there i just need a little push. Here is what im currently trying with Jsonata but im getting an invalid expression:


image

this is my flow:


this is my flow context:

{
    "zTempSensRobin": {
        "device": "zTempSensRobin",
        "battery": 57,
        "humidity": 53.82,
        "last_seen": 1639081831131,
        "linkquality": 144,
        "pressure": 959,
        "temperature": 21.33,
        "voltage": 2925,
        "roomName": "Robin's room",
        "lowBattery": false,
        "lastSeen": "09/12/2021 22:30",
        "isUsedForHeating": true
    }
}

Thanks

You may need to use the JSON node just after the node that receives the temperature.

I'm not sure i understand what you mean, do you mean instead of the change node i should use a JSON node?

Sorry. I may be wrong.

Just to establish what is going on, please put a debug node (set to show the entire message content) on the output of the node who's message we are looking.

This way we can see what the message looks like and work from there.

(I was meaning to put a JSON node between that blue node before the change node.)

Try

$flowContext("tableData." & topic & ".isUsedForHeating")

This is an incoming message

{
    "topic": "zTempSensRobin",
    "qos": 0,
    "retain": true,
    "_msgid": "79dfd26beb15a90a",
    "state": {
        "battery": 57,
        "humidity": 54.79,
        "last_seen": 1639084512516,
        "linkquality": 147,
        "pressure": 959,
        "temperature": 21.44,
        "voltage": 2925,
        "roomName": "Robin's room",
        "lowBattery": false,
        "lastSeen": "09/12/2021 23:15",
        "device": "zTempSensRobin"
    }
}

Thanks.

I think I shall defer to what @E1cid said as a possibility to fix the problem.

it works now thanks alot what a great forum!

1 Like

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