Device State Information (Probably just MQTT novice issue)

I am housing all of my Smarthome logic in Node-Red. I control devices connected to Z2M, Homebridge, and Hubitat there.

A simple example of something I am looking to do is as follows:

  • When a button is pushed toggle a bulb between off and on.

I know how to do this when everything is connected to the Hubitat. Basically the logic is as follows:

  1. Receive the button push event
  2. Check current state of bulb
  3. If on send off command
  4. If off send on command

All of these have very clear analogies on how to accomplish them if the button and bulb are connected to Z2M, with 1 exception. That is step 2.

Is there a method via MQTT to retrieve the current state?
I don’t think there is.I think what I need to do is capture the state when it is sent by Z2M on a change and store it in Node-Red and then reference that stored value for step 2. I just wanted confirmation that I wasn’t missing something obvious.

You can send a message to the /get topic, it will update its main topic.

I use a node red node for storing state:

There is also
node-red-contrib-zigbee2mqtt that may be of help