jeubanks / hubitat-mqtt-bridge

MIT License
28 stars 29 forks source link

Can turn devices off but not on #3

Open wilvancleve opened 6 years ago

wilvancleve commented 6 years ago

First, thanks for this library. I'm so close to perfectly happy here that I can taste it, but something is off, and I can't tell exactly what.

I'm working on a single switch. My HA install is updated by changes of Hubitat state. When the switch is on, I can turn it off from HA, and see the MQTT messages (in both the bridge, an MQTT client, and in the Hubitat logs). When the switch is off, I cannot successfully turn it on in HA (or by publishing a request in MQTT). The message is sent from HA to MQTT, but it does not appear in the Hubitat logs for the Bridge App, the Bridge Device, or the switch, and the light does not turn on.

It would seem to me that the issue here is in the way the Bridge App is processing the on payload for the switch, but I can't figure out why that would be.

Here's the relevant section of my HA config

switch:
  - platform: mqtt
    name: "Outside Light"
    state_topic: "hubitat/Outside Light/switch/state"
    command_topic: "hubitat/Outside Light/switch/cmd"
    payload_on: "on"
    payload_off: "off"
    retain: true

And here's my mqtt bridge config

    # Specify your MQTT Broker's hostname or IP address here
    host: 192.168.164.2
    preface: hubitat

    state_read_suffix: state
    state_write_suffix: set_state

    command_suffix: cmd

# Port number to listen on
port: 8080

Googling indicates to me that I'm not the first person to have a problem between off and on.

jeubanks commented 6 years ago

Welcome. I only ported another persons work.

It has been a while since I’ve done any work with this. However try changing this.

state_write_suffix: set_state

Change that to match your “cmd” state from HA.

In the mqtt HA command_topic the suffix is “cmd”. Not entirely sure since it’s been a long time, but it’s worth a try.

From: wilvancleve Sent: Thursday, June 7, 2018 00:22 To: jeubanks/hubitat-mqtt-bridge Cc: Subscribed Subject: [jeubanks/hubitat-mqtt-bridge] Can turn devices off but not on (#3)

First, thanks for this library. I'm so close to perfectly happy here that I can taste it, but something is off, and I can't tell exactly what. I'm working on a single switch. My HA install is updated by changes of Hubitat state. When the switch is on, I can turn it off from HA, and see the MQTT messages (in both the bridge, an MQTT client, and in the Hubitat logs). When the switch is off, I cannot successfully turn it on in HA (or by publishing a request in MQTT). The message is sent from HA to MQTT, but it does not appear in the Hubitat logs for the Bridge App, the Bridge Device, or the switch, and the light does not turn on. It would seem to me that the issue here is in the way the Bridge App is processing the on payload for the switch, but I can't figure out why that would be. Here's the relevant section of my HA config switch:

And here's my mqtt bridge config `mqtt:

Specify your MQTT Broker's hostname or IP address here

host: 192.168.164.2 preface: hubitat state_read_suffix: state state_write_suffix: set_state

command_suffix: cmd Port number to listen on port: 8080 ` Googling indicates to me that I'm not the first person to have a problem between off and on. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

wilvancleve commented 6 years ago

That seems to have done it, though I can't for the life of me figure out why it worked for on->off before and not off->on and now it works for both. Thanks for the suggestion!

xAPPO commented 5 years ago

There is some issue with the duplicate message detection (and dropping) in server.js lines 265-274 which can make it drop messages that are actually needed. This causes either the 'on' or 'off' messages to get dropped meaning that only one gets through forcing the device in Hubitat always to that state.

If for example your device shows OFF all the time. Alter it to ON in the Hubitat UI and you will see it can change back to OFF when a state update arrives but can't change back to ON (and vv.)

Just trying to understand the cmd, state and particularly set_state interactions and state history storage at the moment. Is set_state a HomeAssistant nuance ?

Also not sure if a device that is managed by Hubitat behaves differently to a device that is owned elsewhere and updates via MQTT or a device in Hubitat that only displays status (no cmd's).

It's a shame MQTT doesn't have a quick way to ascertain which client caused the latest topic update.

xAPPO commented 5 years ago

What I’ve realised now is that code to drop duplicate messages is very much based around a HomeAssistant/MQTT pairing. I’m trying to use the Hubitat MQTT integration more generally with several MQTT savvy applications , controllers and standalone devices so I need to adapt that code accordingly to avoid potential race conditions. All is working for me currently, although it might go ‘loopy’ anytime.