MQTT usage howto

Hi

So i am trying to make an automation in Home Assistant using Node-Red
the basic idea is

press a dimmer up button
read the current state of the light
depending on the brightnes state add a step of 50 or set to max brightnes

i have a Gledopto GL-C-007P
according to Zigbee2MQTT the commands are

zigbee2mqtt/FRIENDLY_NAME/get
{"brightness": ""}

it is more or les working.

my problem i that i have to subscripe to # to actualy get a readout
if i subscribe to zigbee2mqtt/FRIENDLY_NAME/get i get nothing

also when i get a readout it is not just brightnes
it is all states at once
like this

"{"brightness":254,"color":{"x":0.5245,"y":0.4136},"color_mode":"color_temp","color_temp":495,"linkquality":72,"state":"OFF","update":{"state":"idle"},"update_available":false}"

how am i supposed to do anything with this ?
i only need Brightnes

any ideas ??

BR
Thomas

When subscribe to # and your receive the brightness. If you look at the debug the topic that received the brightness should be listed.

Or install mqtt explorer to see all the topics and payloads.

1 Like

this is how it looks in Node-Red



if i try to subscripe to zigbee2mqtt/KIT_GL_BEL_01 i get this

how do i get that da... thing to only publish what i need instead of all states at once?

BR
Thomas

I've only skimmed this thread but if I've understood, you may want to look at an "experimental" setting in Zigbee2MQTT. By default it only publishes a single topic that has a complex JSON object in it. But you can change the setting to also publish each setting individually. Can't remember the setting name but I have it on for my setup and it works really well and you can then just subscribe to what you want instead of having to get everything each time.

Nice :slight_smile:
Sounds like what i need

Google will be my friend now
have a nice weekend

1 Like

If you change your mqtt-in node to output a parsed JSON object, is the brightness available as msg.payload.brightness?

like this ?

The output looks better, but i would still like to have only brightness

i see that there is an "object" in the output canned brightnes but it is followed by more info i dont want at this moment

You can use msg.payload.brightness in downstream nodes.
But if you really want to get rid of the other data, a change node can set msg.payload to msg.payload.brightness. That should give you msg.payload == 254.

i will give it a try

Thank you :slight_smile:

yep

that worked

now i just have to put it in a sequence that actually works :slight_smile:

Thanks

just one last question

i want to get the MQTT request in to a sequence and i dont think that will be a problem

my problem is that how do i initiate the "state" request

at the moment i a using a inject node but in the working sequence it till have to be triggered some how and the injectnode dont have an input trigger so i need to use a different node i think

the sequence is
button press - switch - currentstate on/off - here i want the inject MQTT - read MQTT state - bla-bla-bla

can i use a service call instead if an inject node ?
i tried current state but that one wants an entity :frowning:

I see a lot of posts which seem to relate to Home Assistant eg "service call" but I don't really know what Home Assistant is.

I did just spend half an hour watching YouTube to try and learn about it but I'm still pretty much in the dark.

Personally I use Node-red dashboard buttons to initiate flows such as turning on the coffee machine.
Untitled 4

Button press - MQTT to turn socket on/off, MQTT to request and obtain power consumption, Dashboard to provide a user interface.

What does Home Assistant offer beyond that?

I am sooo not the right person to answer your question.
i have only been trying to use Home Assistant since late last year

but why i started using it was a recomendation from friends who was using it and the fact that i wanted to try and automate stuff in my home.
before that i was using Wago and Siemens Logo in my garage and garden to automate but i wanted to go all in.
I am no tecky coder so HA was a good option for me to begin with.
It integrates all i can think of i need and want to automate in to one platform.

anything from my kitchen hood, lighting, curtains, zigbee, wifi, z-wave, BT, garagedoor, ESP, Vacumcleaner to where are the kids at the moment.

it is easy to get the basics working, but i wanted to do a bit more and that is where i ran in to problems with MQTT

if you wanted to use an physical button how would you do it ?

I have a couple of LED capacitive touch buttons connected to ESP8266s, the whole assembly can fit in a little plastic case about 4cm square. The buttons are discussed here
The ESP runs Tasmota and uses MQTT to send button press messages.
Very home brew and cheap.

I have half formed plans to replace them with battery powered ESPs which can deep sleep between presses. The current ones can't do this because the capacitative buttons need power so deep sleep is not an option.

The nicest commercial buttons seem to be Flic but too expensive at $30.

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