zha-device-handlers icon indicating copy to clipboard operation
zha-device-handlers copied to clipboard

[Device Support Request] Sonoff SWV-BSP Smart Water Valve

Open andy-81 opened this issue 1 year ago • 36 comments

Problem description

Currently only opening and closing the valve is possible however the Sonoff hub and Zigbee2MQTT support pulling in if there is an issue with the valve and the flow data from the valve which would be fantastic to be able to use in ZHA.

Solution description

It would be great if a custom quirk could be created however I have struggled to follow along with the details of how to create the custom device handlers. I was hoping the work from Z2M may help point to how to pull the information but the information does not look similar to the Zwave standard where you require the address details which has further complicated me understanding how to write the custom driver. Any help in someone creating this custom handler would be appreciated.

Screenshots/Video

Screenshots/Video

https://youtu.be/ofzIoxliNJo?si=9JpD2oPFi9j76muC

this video shows the details of what is shown in ZHA vs what is shown in Zigbee2MQTT

Device signature

Device signature
[Paste the device signature here]

Diagnostic information

Diagnostic information
[Paste the diagnostic information here]

Logs

Logs
[Paste the logs here]

Custom quirk

Custom quirk
[Paste your custom quirk here]

Additional information

No response

andy-81 avatar Aug 11 '24 16:08 andy-81

Just got one of these and can provide some of the info missing above:

Signature:

{
  "node_descriptor": {
    "logical_type": 2,
    "complex_descriptor_available": 0,
    "user_descriptor_available": 0,
    "reserved": 0,
    "aps_flags": 0,
    "frequency_band": 8,
    "mac_capability_flags": 128,
    "manufacturer_code": 4742,
    "maximum_buffer_size": 82,
    "maximum_incoming_transfer_size": 255,
    "server_mask": 11264,
    "maximum_outgoing_transfer_size": 255,
    "descriptor_capability_field": 0
  },
  "endpoints": {
    "1": {
      "profile_id": "0x0104",
      "device_type": "0x0002",
      "input_clusters": [
        "0x0000",
        "0x0001",
        "0x0003",
        "0x0006",
        "0x0020",
        "0x0404",
        "0x0b05",
        "0xfc11",
        "0xfc57"
      ],
      "output_clusters": [
        "0x000a",
        "0x0019"
      ]
    }
  },
  "manufacturer": "SONOFF",
  "model": "SWV",
  "class": "zigpy.device.Device"
}

Diagnostic info attached. zha-a1c1fa629b838dd9fa7a401ddd69c026-SONOFF SWV-a6d24191ccfc18b346afd34da19b81e7 (1).json

Let me know if there's more info I can provide

AKTheKnight avatar Aug 12 '24 20:08 AKTheKnight

Cluster 0xfc11 seems to be known by zigbee2mqtt project: https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/devices/sonoff.ts#L52-L71

brodock avatar Aug 13 '24 00:08 brodock

schedule seems to be handled as part of the custom cluster above in the following attribute 0x5008:

the logic to serialize/de-serialize its content can be seen here: https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/devices/sonoff.ts#L297-L370

brodock avatar Aug 19 '24 19:08 brodock

I did find reference in the zigbee2mqtt handler about the SWV valve.

It does mention in the list about the water flow and the status which shows if it is leaking, no pressure...

It can be found here: https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/devices/sonoff.ts#L1104-L1138

andy-81 avatar Aug 22 '24 15:08 andy-81

This is the CL that added much of the code. Notice that they also had to edit the fromZigbee.ts file to add the msFlowMeasurement... uh... "thing" (I don't know much about zigbee). Not sure if equivalent work would need to be done here.

jamesshannon avatar Aug 23 '24 03:08 jamesshannon

I am also interested in this device support. I own the device and can provide any information or perform any test if needed. Thanks!

soyxan avatar Aug 28 '24 08:08 soyxan

Hi all,

I've just created PR https://github.com/zigpy/zha/pull/187 for zha, which implements at least the flow rate sensor part of this request. I plan to look at implementing a device handler for 0xfc11 cluster features (i.e. issue status) next if I have some time in coming days/weeks, unless somebody else has already made some progress here?

benbancroft avatar Aug 30 '24 14:08 benbancroft

I've just pushed up https://github.com/zigpy/zha-device-handlers/pull/3340 and https://github.com/zigpy/zha/pull/189, which implements device quirk and Home Assistant sensors for valve leak status and water supply status. Other than some device weirdness around having to ensure manufacturer_specific is not set on attribute read, this wasn't too bad to add in the end.

This is working nicely for my irrigation setup so far: Screenshot 2024-08-31 201915

That should hopefully be everything that was initially requested for this request. There are however other features supported in Zigbee2MQTT (scheduling, shutoff timer etc) that probably could be added as a future enhance, which again I might look at if I get some time.

benbancroft avatar Aug 31 '24 19:08 benbancroft

Thanks a lot, that is a good improvement. Now a newbie question, when will this quirck be available in Home Assistant? Can I manually upgrade ZHA or do I have to wait for a new HA release?

On the other hand, regarding the other features available in Zigbee2MQTT like scheduling (timed and quantitative), I think that is quite important to have them available. Rely in HA for scheduling the irrigation maybe is not the best option as any failure will affect our plants wellbeing :) Been able to define and save the schedules in the SWV device will keep the irrigation working even if HA or the Zigbee network is completely dead. I do not have the skills to do it by my own, but I am available for testing as I own the SWV.

soyxan avatar Sep 01 '24 09:09 soyxan

Is there any chance to get the amount of water (total liters)? That would be super usefull :D

aaronegger avatar Sep 02 '24 20:09 aaronegger

My two cents regarding scheduling, specifically turn-on scheduling. The device will be fairly simple (e.g., time of day, though it might have another way to schedule). It definitely won't have sun-based scheduling, forecast-based scheduling, etc. So it's kinda a weird User Experience if it supports some on-device scheduling but not others.

Now... if you're talking about "time / flow limits" then yes, I agree that's super important. When I turn on the faucet (via HA) then I want to be able to send a "turn off in X" parameter as part of the "on" message. That way if something happens to the network then the device still turns off. I'm a little concerned about my plants, but very concerned about my water running for days. The issue could be something as simple as me rebooting HA at the time that my "turn off" automation is supposed to run.

jamesshannon avatar Sep 03 '24 04:09 jamesshannon

nice! but how do we get updates for the ZHA in Hass? i don't see these options in my list

TeDeVPrime avatar Sep 12 '24 21:09 TeDeVPrime

guys anyone who can tell us how to get the latest updates?

TeDeVPrime avatar Sep 24 '24 07:09 TeDeVPrime

it seems the related PRs haven't been merged yet

brodock avatar Sep 24 '24 10:09 brodock

Any idea when this pr will be merged?

Would be great to gain access to the features @benbancroft added already. 😊

andy-81 avatar Sep 30 '24 06:09 andy-81

yeah i have been checking with every update but no luck. i already had a lot of issues with my water valve left open. i really need to be able to use the on-device timer.

i don't know how ZHA works with HASS, but shouldn't it be able to update on it's own?

TeDeVPrime avatar Sep 30 '24 08:09 TeDeVPrime

guys the new version from HASS came up but still my Sonoff Smart Water Valve just shows on / off switch. nothing more.

no i need to do something?

TeDeVPrime avatar Oct 06 '24 14:10 TeDeVPrime

The pull requests haven't been approved. After they're approved and merged into the production branch then the updated version of zigpy will need to be included in ZHA, and then ZHA will need to be included in HA. In theory, all these things could happen quickly, but they require approval and merging.

jamesshannon avatar Oct 09 '24 17:10 jamesshannon

i find it crazy that a pull request would need months. ZHA should be able to be updated on it's own and not as part of HA. what if we need a hotfix?

we have had two HA releases since this was fixed. now i have to wait for November (if i am lucky) in order to be able to control my watering safely.

two times it has failed me until now and the water left running.

TeDeVPrime avatar Oct 09 '24 19:10 TeDeVPrime

I can't speak to the approval process. It might have just gotten forgotten about.

I don't know why you're having so many problems. If you have an HA automation set up that turns it on, then waits, then turns it off, you should only get failures if: a) The zigbee connection is really flaky. But if that's the case then you probably have failed turn-ons, too? b) HA dies (or gets restarted, etc) during the on time and then the automation doesn't finish to turn it off.

For: a) I believe that Zigbee has a bi-directional mechanism and includes confirmation, right? In which case you should be able to build a check-and-retry into your automation. Ie, "repeat: turn off. wait 10 seconds. if it's off then exit"

b) You could build a "failsafe off" automation to run, e.g., every 15 minutes and turn the water off. The more frequently it runs and the longer your watering period the more likely you are to have issues with this (ie, you'll turn off while it should still be one). If that's a problem, you could add a datetime helper or something as a second check.

jamesshannon avatar Oct 09 '24 20:10 jamesshannon

i had two failures

1 was because my HASS crashed..... lucky eh? and 1 was because the device became "unavailable" for whatever reason.

i also have a friend who had this issue with bad signal

so i don't want to be dependent on critical things like that to HASS. since the device supports natively the solution to my problem.... and since it is fixed... i want that hotfix. because to me... this is a hotfix.

so having all these steps for "approval" for something that i should be able to access as beta or early-release..... it's annoying. especially when HASS has update for every single thing.... except ZHA.

TeDeVPrime avatar Oct 09 '24 20:10 TeDeVPrime

First of all, I totally agree with the comments regarding the long waiting till we get the update, but, in addition to that and AFAIK, the PR https://github.com/zigpy/zha-device-handlers/pull/3340 only covers basic feedback sensors from the device (flow measurement and leakage status) but no specific commands like "turn on with shutdown timer" as some of you are expecting. Please correct me if I am wrong.

soyxan avatar Oct 09 '24 20:10 soyxan

you are correct. i am hoping that someone will soon figure it out. from what i have read, sonoff made it in a way that when you send the turn on command... you can also pass parameters for water flow and time.

the sensors that "exists" at the moment will give me an extra way of checking the system on event changes. it will also give me notifications as to whether i have running water or not at my house (it's a weekend house, so i am not there every single day).

i like the simplicity of ZHA but man.... Z2M had these features since day one.

i have never gotten to the technical details between these two (ZHA and Z2M). i just found the ZHA easier and faster to use. Hopefully we will see updates on this device soon

TeDeVPrime avatar Oct 09 '24 21:10 TeDeVPrime

Can we please move the discussion elsewhere, e.g., GH discussions? If you want to be notified of updates just subscribe to the PR. Protesting here doesn't help.

fgsch avatar Oct 10 '24 11:10 fgsch

I created PR #3930 that adds these features:

  • Water Leakage binary sensor
  • Water Shortage binary sensor
  • on_time attribute, representing the number of seconds after opening before the valve automatically closes.
  • A custom behaviour for the On command:
    1. If on_time == 0 it's a normal On command (0x01)
    2. If on_time != 0 it sends a on_with_timed_off (0x42), with the on_time numbers of seconds sets in the attribute

In my environment everything works, could someone help testing it? Thank you!

micz avatar Mar 04 '25 22:03 micz

Has an “open for” function already been implemented? So that the valve closes again automatically after a set time?

In my opinion, this is a very important safety feature

Stothed775 avatar Mar 20 '25 19:03 Stothed775

With PR #3930, I tried to implement that. It has been labeled "waiting for reviewer response".

I'm setting up the system for the spring and plan to use it as a custom quirk.

micz avatar Mar 20 '25 19:03 micz

it is good seeing someone trying to make this device work properly. ZHA "zigpy" has been a mess around this device since day one. Z2M had full support since day one. 6-7 months after product release and we are still waiting for "approvals".

i must be missing a lot of knowledge or information because the fact that we have to wait for someone's "approval - review"... and then wait for the next version of HASS that will include the changes.... it is simply nuts.

Micz thank you for your effort. I don't know if we are going to magically see the changes when they happen or we have to reconfigure the device but at least you made a progress.

PrimesoftCopilot avatar Mar 20 '25 21:03 PrimesoftCopilot

i took the quirk code from PR #3930 and edited it to hardcode a maximum of 20 minutes valve open time and use it always when the device is turned on, so that even if i forget or connection is lost it turns off after 20 mins. I have this running in my garden with 4 of those devices. it works well for me like this, but the on_time should be a setting in the UI. unfortunately setting the kwargs["on_time"] through the UI did not work in my case.

https://gist.github.com/etienne678/e2670600872c5b4021f9ec390edae661

etienne678 avatar Mar 20 '25 21:03 etienne678

@etienne678 which firmware version do you have on the SWVs?

micz avatar Mar 20 '25 21:03 micz