SOLVED. Cannot access attributes in MQTT plugin onPoll

Also linked to this unanswered post:Problem accessing custom attributes in an MQTT plugin onPoll()

I am totally stuck on this and would really appreciate some guidance.

I cannot get at attribute contents within onPoll()

Eg I have a device 1002:0 (name is Housemodes) that has attributes scene0, scene1 etc. They are set to meaningful names and work correctly in any controls. eg binding Housemodes.scene3

console.log(plugin.Devices[“1002:0”].Attributes[3]) gives me “scene3” which is the name of the attribute - completely useless - i need its contents.

console.log(plugin.Devices[“1002:0”].scene3) gives me null

Is this even possible and if so - how?

Try doing this:

console.log(plugin.Devices["1002:0"]["scene3"]);

Although, I think what you did here should have also worked. I wonder if maybe the value actually is null. Maybe you haven’t actually set it yet.

As a test, try setting it 1st first with a test value & then do a console write.

plugin.Devices["1002:0"]["scene3"] = "Test value";
console.log(plugin.Devices["1002:0"]["scene3"]);

Also, “1002:0” is not a valid name. Device names should not start with numbers nor should they contain colons. The Designer will not let you manually type that name. I’m guessing these are automated device names. You will probably want to choose a different naming scheme. Like “D1002_0” or something like that.

Thanks -already played with some of the suggestions.

Device Id 1002:0 name is Housemodes

In onPoll() If I set plugin.Devices[“1002:0”].scene3 = " fred" and then immediately console.log it it is set to “fred” CORRECT.

If I reference it as plugin.Devices[“1002:0”][“scene3”] and read it back immediately it also works correctly.

console.log("ee "+ plugin.Devices[“Housemodes”].scene3) gives me “Housemodes is not defined” but in any controls binding Housemodes.scene3 gives the correct contents of scene3

I’ll do some more testing tomorrow but it is driving me up the wall!

The 1002:0 is the Id of the device - copied from the example MQTT plugin back in my first few days with HR. The first part of the Id is my unique thing identifier from Node red.

It has worked apparently OK in every other aspect (as far as I know) up to now. I wonder if you are on to something here. If I change that to be Dnnn I wonder what else I may break. I have a big implementation but could play with a throw away copy. It’s late now - will try tomorrow.

Oh yeah, my bad. You are correct. That is fine.

Doh. You built my hopes up then!
I have a workaround plan to use global variables in the plug-in. It’s a lot of work though so if I could access device attributes it would be much better

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