wutu / pimatic-mqtt

MQTT plugin for Pimatic
https://pimatic.org/plugins/pimatic-mqtt/
GNU Affero General Public License v3.0
9 stars 13 forks source link

MQTTButtons didn't show state #43

Closed pc-maniac closed 5 years ago

pc-maniac commented 6 years ago

I have device with array of switches. Device designed by myself, so I can change topics/commands if needed. Device have separate topic for change state and for read state. Change state commands: 0 - off, 1 - on, 2 - switch State: 0 - off, 1 - on If I use MQTTSwitch widget, all worked correctly, I can turn device on/off and check it state by button state on the WebGUI.

But then I tried to use MQTTButtons widget. I've added several buttons, set state topic, command topic and message 2 for switching state. Button worked well, command sends, but state didn't shows by the button. But if on the same device exist MQTTSwitch widget, it changes state if I click MQTTButtons button.

Then I opened code of the plugin and trying to understand it (didn't know coffee script and pimatic API). Find this:

          if b.stateTopic == topic
            payload = message.toString()
            if payload == b.message
              @emit 'button', b.id

As I understend, to change button state, message from button config needs to be the same as the state message. Trying to change message on one of the button no 1. Then I press this button, device turned on and sends back state message 1. MQTTSwitch immediately shown the state, but MQTTButtons button didn't changes.

This is bug, or by design this buttons didn't show the device state?

mwittig commented 5 years ago

MQTTButton, or generally, pimatic button device types do have state ("button" exhibits the last triggered button or default settings as set by the device implementation), however, the state is not visualized in the UI by design.

mwittig commented 5 years ago

I have investigated the matter further and will come with a generic solution for the pimatic ButtonsDevice which is the base device for MQTTButton. The feature will be available with the next release of pimatic and pimatic-mobile-frontend.

mwittig commented 5 years ago

Released with pimatic-mobile-frontend@0.9.16