Read switch state after a query

Hello, i’m new to openhab and i need some assistance for reading the state of a switch via mqtt launching a query.
I explain why: i’m using some esp board that report output status after a query.
for example to read the status of gpio4 i need to write via mqtt topic


espboardname/toesp/ is the topic and
{out14?} is the payload

and after a second or so the board reply:




as the status of gpio is ON or OFF.

I have successfully made and item to change the gpio state, but i’m here stuck with the reading of the state.
I need that becouse i can change the state also outside openhab2 ambient

A more typical approach would be for the ESP to report any change in the Item’s states automatically and not require a poll.

Without that, you will have to set up a rule to periodically send the MQTT message to toesp and a separate Item that receives the messages on the fromesp topic.

Thank you Rich for the kind answer.
Can you point me to the openhab section or some “key words” i can use to make a search on the forum?

thank you