feature-requests icon indicating copy to clipboard operation
feature-requests copied to clipboard

Add support for Hynetek HUSB238 USB Power Delivery (PD) controller

Open lboue opened this issue 1 year ago • 13 comments

Describe the problem you have/What new integration you would like

Add support for Hynetek HUSB238 USB Power Delivery (PD) controller. The Hynetek HUSB238 is a highly integrated USB Power Delivery (PD) controller as sink role for up to 100W power rating. The HUSB238 is compatible with PD3.0 and Type-C V1.4, and it can also support Apple Divider 3, BC1.2 SDP, CDP and DCP while the source is attached.

Please describe your use case for this integration and alternatives you've tried:

Remote control of a circuit's supply voltage with Adafruit USB Type C Power Delivery Dummy Breakout board.

Additional context

Arduino libraries

  • Adafruit_HUSB238
  • https://github.com/Duckle29/HUSB238
  • https://github.com/luoluomeng/HUSB238Driver

lboue avatar Apr 04 '24 16:04 lboue

+1 ive been designing a project for a month thinking it was supported already naurrr

jjx932 avatar Apr 17 '24 16:04 jjx932

so how do you want to use it? what features you want from the component?

latonita avatar Apr 28 '24 17:04 latonita

so how do you want to use it?

what features you want from the component?

I would set the desired PD voltage and current using i2c bus.

lboue avatar Apr 28 '24 17:04 lboue

so how do you want to use it?

what features you want from the component?

I would set the desired PD voltage and current using i2c bus.

Please elaborate) Is it one time pre pre-built in yaml or some dynamic?

Please propose config of your dream. :)

Any data this device produces so we need to show it as sensor?

latonita avatar Apr 28 '24 18:04 latonita

so how do you want to use it?

what features you want from the component?

I would set the desired PD voltage and current using i2c bus.

Please elaborate) Is it one time pre pre-built in yaml or some dynamic?

Please propose config of your dream. :)

Any data this device produces so we need to show it as sensor?

I'd like to use a selector to dynamically choose the voltage value.

Values can be read back for display.

https://learn.adafruit.com/adafruit-husb238-usb-type-c-power-delivery-breakout/arduino

lboue avatar Apr 28 '24 18:04 lboue

I found 2 other libraries for that chip:

  • https://github.com/Duckle29/HUSB238
  • https://github.com/luoluomeng/HUSB238Driver

lboue avatar May 07 '24 06:05 lboue

OK, good. I had no time yet to look deeper into this, but already manage to make base for the componenet

latonita avatar May 07 '24 06:05 latonita

OK, good. I had no time yet to look deeper into this, but already manage to make base for the componenet

@latonita Thank you for your time. Don't hesitate to make the branch public so that I can contribute too.

lboue avatar May 07 '24 07:05 lboue

@lboue you may try what is there so far


external_components:
  - source: github://pr#6693
    refresh: 10s
    components:
      - husb238

husb238:
  id: husb_01

binary_sensor:
  - platform: husb238
    attached: "PD Attached"

sensor:
  - platform: husb238
    voltage: "Contracted Voltage"
    current: "Contracted Current"
    selected_voltage: "Selected Voltage"

text_sensor:
  - platform: husb238
    status: "Last request status"
    capabilities: "Capabilities"

latonita avatar May 07 '24 15:05 latonita

@latonita Thanks. I'll try it out straight away.

lboue avatar May 07 '24 16:05 lboue

@latonita Here are the test results for husb238 component:

image

I am getting this error: Error reading HUSB238 in the log file.

ESPHome husb238 component

22:15:33][I][app:100]: ESPHome version 2024.5.0-dev compiled on May  7 2024, 22:14:18
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][C][logger:185]: Logger:
[22:15:33][C][logger:186]:   Level: VERBOSE
[22:15:33][C][logger:188]:   Log Baud Rate: 115200
[22:15:33][C][logger:189]:   Hardware UART: UART0
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][C][i2c.arduino:071]: I2C Bus:
[22:15:33][C][i2c.arduino:072]:   SDA Pin: GPIO26
[22:15:33][C][i2c.arduino:073]:   SCL Pin: GPIO32
[22:15:33][C][i2c.arduino:074]:   Frequency: 50000 Hz
[22:15:33][C][i2c.arduino:086]:   Recovery: bus successfully recovered
[22:15:33][I][i2c.arduino:096]: Results from i2c bus scan:
[22:15:33][I][i2c.arduino:102]: Found i2c device at address 0x08
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][C][husb238:176]: HUSB238:
[22:15:33][C][husb238:179]:   PD Attached 'PD Attached'
[22:15:33][C][husb238:184]:   Source Voltage 'Contracted Voltage'
[22:15:33][C][husb238:184]:     Device Class: 'voltage'
[22:15:33][C][husb238:184]:     State Class: 'measurement'
[22:15:33][C][husb238:184]:     Unit of Measurement: 'V'
[22:15:33][C][husb238:184]:     Accuracy Decimals: 0
[22:15:33][C][husb238:185]:   Source Current 'Contracted Current'
[22:15:33][C][husb238:185]:     Device Class: 'current'
[22:15:33][C][husb238:185]:     State Class: 'measurement'
[22:15:33][C][husb238:185]:     Unit of Measurement: 'A'
[22:15:33][C][husb238:185]:     Accuracy Decimals: 2
[22:15:33][C][husb238:186]:   Selected Voltage 'Selected Voltage'
[22:15:33][C][husb238:186]:     Device Class: 'voltage'
[22:15:33][C][husb238:186]:     State Class: 'measurement'
[22:15:33][C][husb238:186]:     Unit of Measurement: 'V'
[22:15:33][C][husb238:186]:     Accuracy Decimals: 0
[22:15:33][C][husb238:190]:   Last Request Status 'Last request status'
[22:15:33][C][husb238:191]:   Capabilities 'Capabilities'
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][C][captive_portal:088]: Captive Portal:
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][C][web_server:173]: Web Server:
[22:15:33][C][web_server:174]:   Address: husb238.local:80
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][C][ota:096]: Over-The-Air Updates:
[22:15:33][C][ota:097]:   Address: husb238.local:3232
[22:15:33][C][ota:100]:   Using Password.
[22:15:33][C][ota:103]:   OTA version: 2.
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][C][api:139]: API Server:
[22:15:33][C][api:140]:   Address: husb238.local:6053
[22:15:33][C][api:142]:   Using noise encryption: YES
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:33][E][husb238:223]: Error reading HUSB238
[22:15:34][E][husb238:223]: Error reading HUSB238
[22:15:34][E][husb238:223]: Error reading HUSB238
[22:15:34][E][husb238:223]: Error reading HUSB238
...
[22:15:34][V][sensor:043]: 'Contracted Voltage': Received new state 0.000000
[22:15:34][D][sensor:094]: 'Contracted Voltage': Sending state 0.00000 V with 0 decimals of accuracy
[22:15:34][V][sensor:043]: 'Contracted Current': Received new state 3.000000
[22:15:34][D][sensor:094]: 'Contracted Current': Sending state 3.00000 A with 2 decimals of accuracy
[22:15:34][V][sensor:043]: 'Selected Voltage': Received new state 0.000000
[22:15:34][D][sensor:094]: 'Selected Voltage': Sending state 0.00000 V with 0 decimals of accuracy
[22:15:34][V][text_sensor:013]: 'Last request status': Received new state Success
[22:15:34][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[22:15:34][V][text_sensor:013]: 'Capabilities': Received new state 5V: 0.00A, 9V: 0.00A, 12V: 0.00A, 15V: 0.00A, 18V: 0.00A, 20V: 0.00A
[22:15:34][D][text_sensor:064]: 'Capabilities': Sending state '5V: 0.00A, 9V: 0.00A, 12V: 0.00A, 15V: 0.00A, 18V: 0.00A, 20V: 0.00A'
[22:15:34][W][component:237]: Component husb238 took a long time for an operation (102 ms).
[22:15:34][W][component:238]: Components should block for at most 30 ms.

Adafruit_HUSB238 library By way of comparison, here is the example of the Adafuit library: HUSB238_test.ino

22:29:02.366 -> ----------------------------------------------
22:30:15.578 -> Attachment Status: Attached
22:30:15.578 -> CC Direction: CC1 connected
22:30:15.578 -> USB PD query response: Success
22:30:15.578 -> 5V Contract Voltage: 5V & Current: 3A
22:30:15.578 -> Source Voltage: 5V
22:30:15.578 -> Source Current: 3.0A 
22:30:15.578 -> Available PD Voltages and Current Detection Test:
22:30:15.578 -> 5V Available - Max current: 3.0A 
22:30:15.578 -> 9V Available - Max current: 3.0A 
22:30:15.578 -> 12V Available - Max current: 5.0A 
22:30:15.578 -> 15V Available - Max current: 4.0A 
22:30:15.578 -> 18V Unavailable
22:30:15.578 -> 20V Available - Max current: 3.25A 
22:30:15.613 -> Currently Selected PD Output: 5V
22:30:16.572 -> ----------------------------------------------

lboue avatar May 07 '24 20:05 lboue

@jjx932 This component now works.

lboue avatar May 25 '24 04:05 lboue