mikekap / wink-mqtt-rs

MQTT Relay for the Jailbroken Wink Hub v1, with Home Assistant MQTT autodiscovery support
Other
14 stars 0 forks source link

Z-Wave dimmer switch #14

Closed undrwater closed 3 years ago

undrwater commented 4 years ago

I've got most everything working, just a couple of issues with a Z-Wave dimmer switch. I can turn it on and off, but when it's "off", it's completely dimmed, so if I try to physically turn it on, I have to hold and press to increase brightness. Rather than tap once to turn on to last dimmer setting (full on for example).

Next, I can't seem to find the correct command to actually do the dimming. The "Bathroom" device below is the dimmer switch.

The mqtt command topic i have is:

home/wink/2/3/set

For the "Absolute Minimum" I have '1', and for the "Absolute Maximum" I have '255'. I don't recall where I got those numbers, but they seem to work.

[root@Wink ~]# aprontest -l
Found 2 devices in database...
MASTERID |     INTERCONNECT |                         USERNAME
       1 |            ZWAVE |                         Entrance
       2 |            ZWAVE |                         Bathroom
[root@Wink ~]# aprontest -l -m3
No such master ID: 3
[root@Wink ~]# aprontest -l -m2 -l
Gang ID: 0x00000003
Generic/Specific device types: 0x11/0x01
Manufacturer ID: 0x0039 Product Type: 0x4944 Product Number: 0x3235
Device is ONLINE, 0 failed tx attempts, 10 seconds since last msg rx'ed, polling period 10 seconds
Device has 3 attributes...
Bathroom
   ATTRIBUTE |                         DESCRIPTION |   TYPE | MODE |                              GET |                              SET
           3 |                               Level |  UINT8 |  R/W |                                0 |                                0
           4 |                             Up_Down |   BOOL |    W |                                  |                            FALSE
           5 |                        StopMovement |   BOOL |    W |                                  |                                 

Here's the config from homeassistant/light/wink_2/config (The dimmer) I can see from MQTT explorer

{
  "brightness_command_topic": "home/wink/2/3/set",
  "brightness_scale": 255,
  "brightness_state_topic": "home/wink/2/status",
  "brightness_value_template": "{{value_json.Level}}",
  "command_topic": "home/wink/2/3/set",
  "name": "Bathroom",
  "on_command_type": "brightness",
  "payload_off": "0",
  "payload_on": "1",
  "platform": "mqtt",
  "state_topic": "home/wink/2/status",
  "state_value_template": "{% if value_json.Level > 0 %}1{% else %}0{% endif %}",
  "unique_id": "home/wink//2"
}
mikekap commented 4 years ago

So unfortunately this is "working as intended" - where the intention was by me - I have a dimmer switch that turns on a fan and I never tested it with anything else. Let's see if we can fix that!

The last message you posted is actually quite useful - that's how home assistant sees your bulb. The docs for what each of those things mean are at https://www.home-assistant.io/integrations/light.mqtt - on_command_type specifies to just set the brightness to turn it on - which just sets the brightness and does nothing else. To turn the bulb off, payload_off is sent to command_topic - which in this case, just sets the brightness to 0. I presume that your switch somehow remembers this and when you physically turn it on, it just turns on to 0 brightness. Very unfortunate.

I tried finding a different way to turn my dimmer on/off with aprontest but haven't managed to get it working - even setting StopMovement (in my case - as aprontest -u -m 2 -t 5 -v TRUE) didn't do anything. Only setting the Level to 0 did anything.

I'm not 100% sure I understood your original question correctly though - are you using mqtt auto-discovery or are you configuring the light yourself? The Absolute Minimum you mentioned might be an issue - if you're configuring yourself, you may want to set it to 0. 1 might be a infinitesimally on configuration.

undrwater commented 4 years ago

Hi!

I'm configuring the light manually. Actually, 0 is working fine, so I can turn off and on just fine now. The issue is dimming, so we can focus on that for this report.

Here's the aprontest command I can use to get different levels of dimming: aprontest -m2 -u -t3 -v <some level between 0-255>

I assumed the StopMovement command would be a kind of "press and hold" to increase or decrease dimming. "Letting go" would be the StopMovement.

mikekap commented 3 years ago

Got it - yea that makes more sense for the stop movement stuff. I think you have everything configured correctly - a number between 0-255 in the set command will dim to N/255 percent. So around 127 should be halfway.

At the end of the day - wink-mqtt-rs will run the exact aprontest command that you posted above. Are you seeing a different command or a different effect?

One thing I noticed is that you have the Up_Down set to false and that might be messing with some things. I had to fix this too and it required changing a SQLite db and restarting wink. Let me see if I can recreate it...

mikekap commented 3 years ago

Here's a recreation of what cleared the weirdness for me.

ssh root@wink
# cd /tmp/database/
# ls
apron-2.db
# sqlite3 apron-2.db
sqlite> .headers on
sqlite> .mode column
sqlite> update zwaveDeviceState set value_set=null where attributeId=4;
sqlite> select * from zwaveDeviceState;
nodeId      endpoint    attributeId  value_get   value_set   setValueChangedFlag  lastUpdate
----------  ----------  -----------  ----------  ----------  -------------------  ----------
6           0           2            FALSE       FALSE       FALSE                1606723014
5           0           2            TRUE        TRUE        FALSE                1606723016
3           0           1            1           1           FALSE                1606723012
3           0           3            0           0           FALSE                1606723012
3           0           4                                    FALSE                0
3           0           5                                    FALSE                0
sqlite> .exit
# reboot
undrwater commented 3 years ago

I tried your sqlite command, and up_down is now true. I still haven't discovered how to get the light to turn to a particular brightness value. If yours is working, would you mind posting your mqtt command for brightness level?

Thanks!

mikekap commented 3 years ago

What you posted above is what I use. To be precise, Sending 128 to home/wink/2/3/set sets my brightness halfway and sending 0 or 255 sets it to off & 100% respectively.

undrwater commented 3 years ago

So, I installed HA on an rPi yesterday, and once I added the mqtt entity(?), everything was auto-discovered.

The dim switch works too! I saw a post somewhere wondering if it were possible to see the brightness change in the light as the slider is being moved (as opposed to after the slider stops). I'm not sure what magic is involved in that.

Anyway, I would consider this issue as closed, since everything is working as expected. I just need to figure out how to do on OpenHab what Homeassistant. is doing. I'll look on the mqtt explorer to see what it's doing.

Thanks again!