Integration to Delta VoiceIQ

Got a Delta VoiceIQ a while back which integrates to Alexa, and thanks to a script that @vitaliy_kh found and help from ChatGPT and @tomw, a driver has been developed that will work with Hubitat.

Comments and feedback are welcome!

How to get 2 Secrets:

Method 1:
Both can be retrieved from Home | Delta

* delta_device_id - click on usage - it will be in the URL https://device.legacy.deltafaucet.com/#/device/usage/<your_device_id_here>
    delta_device_id: <your device id>
* delta_token 
    Go to inspector (Ctrl + Shift + I) -> Console;
    Type window.localStorage.auth_token a long string will come up. delta_token should be compiled as follows: 
       delta_token: Bearer <the string from above without quoted>

Method 2:

  1. Using Google Chrome, navigate to https://device.legacy.deltafaucet.com/
  2. Click Login with Amazon
  3. From the Chrome View menu at the top of the screen, select Developer > JavaScript Console
  4. At the top of the console window, click on the Network tab.
  5. On the Delta faucet page, click on the blue button labelled Water Usage - This Week
  6. Expand the left side of the inspector window.
  7. On the Name column, click on the result that starts with UsageReport?deviceId=
  8. On the Headers column, under Request Headers you will find the required deviceId (also shown in the URL address bar after usage/) and the full Authorization token needed.

NOTE: Copy the entire authorization token after the word Bearer. It ends with and must include =

Code in GitHub:

Here is the original script that works in HA: Delta VoiceIQ API for homeassistant · GitHub

4 Likes

I am learning how to deal with HA configuration.
After multiple trial/error attempts finally I got it working in HA.
Here is working version of the above HA configuration script (only on/off commands are tested):

input_text:
  delta_device_id:
    name: delta_device_id
    initial: !secret delta_device_id

rest_command: 
  delta_water_on:
    method: POST
    url: >
      https://device.legacy.deltafaucet.com/api/device/toggleWater?deviceId={{states.input_text.delta_device_id.state}}&toggle=on
    headers:
      Authorization: !secret delta_token
      User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
      Referer: https://device.legacy.deltafaucet.com/
  delta_water_off:
    method: POST
    url: >
      https://device.legacy.deltafaucet.com/api/device/toggleWater?deviceId={{states.input_text.delta_device_id.state}}&toggle=off
    headers:
      Authorization: !secret delta_token
      User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
      Referer: https://device.legacy.deltafaucet.com/

Bye, bye Alexa! (One cloud less.)

I am sure, the same HTTPS POST could be implemented in HE.
Most likely not directly from the RM but simple custom Driver or App could be created for sure.

2 Likes

How did you get the token? I tried the method on GitHub but I don't find "window.localStorage.auth_token". I'm only able to find my device ID in the URL.

Also tried the instructions from the HomeBridge plugin, but they don't make sense to me and don't yield a result I recognize as the secret I need for my faucet.

Any help would be much appreciated. I've wanted to have something like this working for several years now.

Please check the very first post in this thread.
You have to click on "show original" in order to see the entire document.
The instruction is on top under README section.

The HA configuration in the above document is not working but I got it right.

1 Like

I just ask ChatGPT to translate the script to a driver for Hubitat, and tried to update it to allow it to work with the token. The driver saves, but I get an error when pressing one of the buttons:

Edit - Updated the following on 2023-06-04 at 16:24 AST

import groovy.json.JsonSlurper
import groovy.transform.Field

metadata {
    definition(name: "Delta Faucet Driver", namespace: "your.namespace", author: "Author Name") {
        capability "Switch"
    }
}

preferences {
    input("delta_device_id", "string", title: "Delta Device ID", description: "Enter Delta Device ID", defaultValue: "", required: true, displayDuringSetup: true)
    input("delta_token", "string", title: "Delta Token", description: "Enter Delta Token", defaultValue: "", required: true, displayDuringSetup: true)
}

def installed() {
    log.debug "Installed"
}

def updated() {
    log.debug "Updated"
}

def on() {
    toggleWater("on")
}

def off() {
    toggleWater("off")
}

private toggleWater(String toggle) {
    def deviceId = delta_device_id
    def deltaToken = "Bearer ${delta_token}"
    def apiUrl = "https://device.legacy.deltafaucet.com/api/device/toggleWater?deviceId=${deviceId}&toggle=${toggle}"
    def headers = [
        'Authorization': deltaToken,
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
        'Referer': 'https://device.legacy.deltafaucet.com/'
    ]
    
    try {
        def response = httpPost(
            uri: apiUrl,
            headers: headers
        )
        
        if (response.status == 200) {
            def parsedResponse = new JsonSlurper().parseText(response.data)
            if (parsedResponse.success) {
                log.debug "Toggle water ${toggle} successful"
            } else {
                log.error "Toggle water ${toggle} failed: ${parsedResponse.error}"
            }
        } else {
            log.error "Toggle water ${toggle} failed: ${response.status}"
        }
    } catch (Exception e) {
        log.error "Error toggling water: ${e.message}"
    }
}

Progress... but we may need someone with actual Groovy experience to chime in... @thebearmay maybe...?

Also, I would want to put the proper author author and name space... not sure what belongs there since it is based on a script from "velaar" that ChatGPT converted and that I unsuccessfully updated to try to make work, and that hopefully, someone will be able to help fix...?

Error is:

Update 2023-06-04 at 16:24 AST:
Now, I'm getting an Error 500 when attempting to save the token with "Save Preferences"... :frowning:

Wow! Nice try.
Original "velaal" scripts did not work "as is". I was able to get them working.
At this time everything is working in HA and I am finishing integration with HE via HADB.
So, Alexa is gone. Everything is working with HE-HA integration (plus and unfortunately
Delta Cloud). But sure, it will be very nice even to bypass HA.

1 Like

Do I understand you had to change the script for it to work? If so, could you share the version that worked in case that may make a difference?

Also, when getting my token, it seems to be truncated (ends with ...) - do you also see this?

Finally, I don't yet understand the proper format for the token in the script/Grovee... Is this what should be passed (just typed random letters for the example...):

Bearer lsfjkewjkflwjfkle...

Yes. I had to split single "toggle" command into two separate On/Off commands because
the original was missing "payload".
Here is just tested positive configuration from my HA YAML file:

rest_command: 
  delta_water_on:
    method: POST
    url: >
      https://device.legacy.deltafaucet.com/api/device/toggleWater?deviceId={{states.input_text.delta_device_id.state}}&toggle=on
    headers:
      Authorization: !secret delta_token
      User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
      Referer: https://device.legacy.deltafaucet.com/
  delta_water_off:
    method: POST
    url: >
      https://device.legacy.deltafaucet.com/api/device/toggleWater?deviceId={{states.input_text.delta_device_id.state}}&toggle=off
    headers:
      Authorization: !secret delta_token
      User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
      Referer: https://device.legacy.deltafaucet.com/

For the beginning I removed "delta_dispense_mills" command but it should work as well as
all other commands available from Delta Faucet Control web page.
(Frankly, I am using only On/Off commands in my automations.)

Yes. But actual TOKEN is about 500 characters long. You have to hit "enter" in the console
window and it will show up entirely. You can use a "network" window. It has a lot more info.
That is how I figured out the original script was not right.

1 Like

Thanks! That's what I was missing. Still getting the Error 500 when I try to "Save Preferences" - not sure why yet... Will likely not be able to go much further on this before I need to go walk the dog...

When I don't make the token mandatory and leave the field blank, it works, so likely an issue with the variable type...?

I see my mistake. Was trying to 'find' in the console instead of typing that in the console. I have my token, but I seem to be too dense to work from the limited instructions for both HA and the HomeBridge plugin.

I'll just watch and wait until something emerges that I can understand how to configure and use. :v:

1 Like

For the HA you can use my modified config script right now
(currently and for the beginning only on/off commands are implemented).
I am not using HomeBridge and have no idea what it is.

1 Like

Please make sure final TOKEN is constructed as a string: "Bearer <extracted_token_value>",
quotes are a must (at least for the HA configuration).

UPDATE
I double checked the code and TOKEN construction seems to be right.

1 Like

The Govee integration has allot of examples of HTTP calls that could possibly be used to facilitate this as a driver in HE.

What you may want to do is look at the driver that is for Plugs and switches. It could provide the basis for a he driver for this.

I don't have the delta faucet otherwise I would give it a shot.

2 Likes

HomeBridge gives you HomeKit capability. Not relevant to this thread though.

I'm not super versed in HA automation because I prefer HE automation and use Home Assistant Device Bridge to that end.

Would you mind sharing a screen shot your HA automation yaml

I'm useless for coding, but willing to test development builds with my faucet.

1 Like

This is exactly my setup.
Everything is on C8 (ZWave + Zigbee + All_Automations). In addition hub-meshed C7 handles
all LAN and Cloud Devices. And HA via HADB brings in Bluetooth Devices plus whatever is
not available on HE.

1 Like

No worries! I’ll take a look at the Plugs and switches driver to compare. Any chance you might know what would cause a 500 error when I try to save the very, very long Token?

I tried removing the "input" string and just hard coding the Token and didn't get the 500 error, so I think that maybe there is too much data for a "text" type variable...?

Still stuck at the other error though, and don't have enough knowledge/background to know where to start debugging it...

Cool. I could use some help with how to use this in the HA automation if you can spare the time.

What would likely make it clear enough for me to follow would be to see exactly how my configuration.yaml should look with this, and exactly how my On and Off automation yaml should look. :slightly_smiling_face:

Sure, I will share all this info but a bit later.
I am leaving for party now ...

2 Likes

Thanks. No rush of course. I’ve been waiting for years already, I can wait some more. Enjoy the party!