SOLVED. Problem accessing custom attributes in an MQTT plugin onPoll()

I’ve been struggling with a problem of how to access other devices attributes in my version of the MQTT plugin,

I have some heating devices that as well as the DisplayName field also have custom attributes - eg EditedName and NodeRedThingId. The attributes work as expected in the various controls.

I now have timer devices that control a variable list of heating zones. They have a custom attribute called ThingList. If I populate this in the plugin directly everything works as expected and I display the end result using gridview.

To do this programmatically - Node red sends ThingList as a comma separated set of thing numbers. Because I already have the user edited zone names in HR it should be easy to pick up the EditedName attribute to populate the Object that gridview uses.

Can’t get it to work.
console.log(plugin.Devices[13+":0"].DisplayName gives me the correct (NON edited) zone name
console.log(plugin.Devices[13+":0"].EditedName gives me null.

It is the same problem with any of the devices attributes - they all come back as null. It is the same problem with any device. I can correctly look up the DisplayName but not the attributes EditedName

As well as the controls correctly showing the edited name I also print it when it is updated in onPoll
console.log(device.EditedName) and it has the correct value.

I think I am missing something obvious - but what?

Thanks for your suggestions.

Coppo

Solved it - totally my fault and it was down to order of the way things were published.
I can access a custom attribute by using any of the following:
plugin.Devices[13+":0"].AttributeName or
plugin.Devices[13+":0"][“AttributeName”]
If it shows as null it genuinely was null at that moment as Bill suggested may be the case!

The problem was the attributes were filled in when the mqtt topic was changed. Thats fine - understood.

The object requiring the other device attributes was generally not changing so no new topic was being published after the very first time. When poll ran it was correctly picking up the other device attributes as null because they hadn’t been set at that point in time.

I can’t believe I fell into that hole. Apologies for wasting folks time.

1 Like