Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Husb238 USB PD controller #6693

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from
Draft

Husb238 USB PD controller #6693

wants to merge 17 commits into from

Conversation

latonita
Copy link
Contributor

@latonita latonita commented May 7, 2024

What does this implement/fix?

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes esphome/feature-requests#2674

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml

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"

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link

probot-esphome bot commented May 7, 2024

Hey there @latonita,
Thanks for submitting this pull request! Can you add yourself as a codeowner for this integration? This way we can notify you if a bug report for this integration is reported.
In __init__.py of the integration, please add:

CODEOWNERS = ["@latonita"]

And run script/build_codeowners.py

(message by NeedsCodeownersLabel)

@codecov-commenter
Copy link

codecov-commenter commented May 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.21%. Comparing base (4d8b5ed) to head (d4bd0f2).
Report is 588 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #6693      +/-   ##
==========================================
+ Coverage   53.70%   54.21%   +0.50%     
==========================================
  Files          50       50              
  Lines        9408     9594     +186     
  Branches     1654     1691      +37     
==========================================
+ Hits         5053     5201     +148     
- Misses       4056     4069      +13     
- Partials      299      324      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lboue
Copy link
Contributor

lboue commented May 8, 2024

It seems that the HUSB238 chip is a little longer than the 30 ms time limit. I suppose it come from calling Husb238Component::read_all_() method. This generates permanent alerts in the logs:

[08:54:41][C][i2c.arduino:071]: I2C Bus:
[08:54:41][C][template.select:071]:   Restore Value: NO
[08:54:41][C][husb238:176]: HUSB238:
[08:54:41][C][husb238:179]:   PD Attached 'PD Attached'
[08:54:41][C][husb238:184]:   Source Voltage 'Contracted Voltage'
[08:54:41][C][husb238:184]:     Device Class: 'voltage'
[08:54:41][C][husb238:184]:     State Class: 'measurement'
[08:54:41][C][husb238:184]:     Unit of Measurement: 'V'
[08:54:41][C][husb238:184]:     Accuracy Decimals: 0
[08:54:41][C][husb238:185]:   Source Current 'Contracted Current'
[08:54:41][C][husb238:185]:     Device Class: 'current'
[08:54:41][C][husb238:185]:     State Class: 'measurement'
[08:54:41][C][husb238:185]:     Unit of Measurement: 'A'
[08:54:41][C][husb238:185]:     Accuracy Decimals: 2
[08:54:41][C][husb238:186]:   Selected Voltage 'Selected Voltage'
[08:54:41][C][husb238:186]:     Device Class: 'voltage'
[08:54:41][C][husb238:186]:     State Class: 'measurement'
[08:54:50][D][sensor:094]: 'Contracted Voltage': Sending state 0.00000 V with 0 decimals of accuracy
[08:54:50][D][sensor:094]: 'Contracted Current': Sending state 0.50000 A with 2 decimals of accuracy
[08:54:50][D][sensor:094]: 'Selected Voltage': Sending state 0.00000 V with 0 decimals of accuracy
[08:54:50][D][text_sensor:064]: 'Last request status': Sending state 'No response'
[08:54:50][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'
[08:54:50][W][component:237]: Component husb238 took a long time for an operation (52 ms).
[08:54:50][W][component:238]: Components should block for at most 30 ms.
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238
[08:55:36][E][husb238:223]: Error reading HUSB238

@latonita Is it possible to increase the request interval?

@latonita
Copy link
Contributor Author

latonita commented May 8, 2024

It seems that the HUSB238 chip is a little longer than the 30 ms time limit. I suppose it come from calling Husb238Component::read_all_() method. This generates permanent alerts in the logs:

@latonita Is it possible to increase the request interval?

okay, I took a look there

  1. error all over the the logs is my mistake :) logic shall be turned around :)
  2. for operation there is no real need to read_all, i will make it just reading status registers
  3. read_all is only needed to request capabilities.

this shall help to minimize the latency

@latonita
Copy link
Contributor Author

latonita commented May 8, 2024

@lboue try current version.
i removed read_all from update, however 52ms for the component can come from publishing of the data.
if it is still the case i can rework it to publish data one by one in a state machine

@lboue
Copy link
Contributor

lboue commented May 11, 2024

@lboue try current version. i removed read_all from update, however 52ms for the component can come from publishing of the data. if it is still the case i can rework it to publish data one by one in a state machine

@latonita
It's much better with the latest changes. I don't see error messages scrolling all the time any more.
Thank you for that.

[07:35:21][C][i2c.arduino:071]: I2C Bus:
[07:35:21][C][i2c.arduino:072]:   SDA Pin: GPIO26
[07:35:21][C][i2c.arduino:073]:   SCL Pin: GPIO32
[07:35:21][C][i2c.arduino:074]:   Frequency: 50000 Hz
[07:35:21][C][i2c.arduino:086]:   Recovery: bus successfully recovered
[07:35:21][I][i2c.arduino:096]: Results from i2c bus scan:
[07:35:21][I][i2c.arduino:102]: Found i2c device at address 0x08
[07:35:21][C][husb238:184]: HUSB238:
[07:35:21][C][husb238:187]:   PD Attached 'PD Attached'
[07:35:21][C][husb238:192]:   Source Voltage 'Contracted Voltage'
[07:35:21][C][husb238:192]:     Device Class: 'voltage'
[07:35:21][C][husb238:192]:     State Class: 'measurement'
[07:35:21][C][husb238:192]:     Unit of Measurement: 'V'
[07:35:21][C][husb238:192]:     Accuracy Decimals: 0
[07:35:22][C][husb238:193]:   Source Current 'Contracted Current'
[07:35:22][C][husb238:193]:     Device Class: 'current'
[07:35:22][C][husb238:193]:     State Class: 'measurement'
[07:35:22][C][husb238:193]:     Unit of Measurement: 'A'
[07:35:22][C][husb238:193]:     Accuracy Decimals: 2
[07:35:22][C][husb238:194]:   Selected Voltage 'Selected Voltage'
[07:35:22][C][husb238:194]:     Device Class: 'voltage'
[07:35:22][C][husb238:194]:     State Class: 'measurement'
[07:35:22][C][husb238:194]:     Unit of Measurement: 'V'
[07:35:22][C][husb238:194]:     Accuracy Decimals: 0
[07:35:22][C][husb238:198]:   Last Request Status 'Last request status'
[07:35:22][C][husb238:199]:   Capabilities 'Capabilities'
[07:35:37][D][sensor:094]: 'Contracted Voltage': Sending state 5.00000 V with 0 decimals of accuracy
[07:35:37][D][sensor:094]: 'Contracted Current': Sending state 1.25000 A with 2 decimals of accuracy
[07:35:37][D][sensor:094]: 'Selected Voltage': Sending state 0.00000 V with 0 decimals of accuracy
[07:35:37][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[07:35:37][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[07:36:37][D][sensor:094]: 'Contracted Voltage': Sending state 5.00000 V with 0 decimals of accuracy
[07:36:37][D][sensor:094]: 'Contracted Current': Sending state 1.25000 A with 2 decimals of accuracy
[07:36:37][D][sensor:094]: 'Selected Voltage': Sending state 0.00000 V with 0 decimals of accuracy
[07:36:37][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[07:36:37][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[07:37:37][D][sensor:094]: 'Contracted Voltage': Sending state 5.00000 V with 0 decimals of accuracy
[07:37:37][D][sensor:094]: 'Contracted Current': Sending state 1.25000 A with 2 decimals of accuracy
[07:37:37][D][sensor:094]: 'Selected Voltage': Sending state 0.00000 V with 0 decimals of accuracy
[07:37:37][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[07:37:37][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'

@lboue
Copy link
Contributor

lboue commented May 13, 2024

@latonita
I think the next step will be to implement voltage selection: ‘Selected Voltage’.

@latonita
Copy link
Contributor Author

@latonita I think the next step will be to implement voltage selection: ‘Selected Voltage’.

Didn't i make it? :)) ahaha. Okay. There is a public function which can be called from lambda, but I haven't tried to use it yet.
command_request_pdo

I will also make a yaml parameter for voltage selection.

@lboue
Copy link
Contributor

lboue commented May 13, 2024

@latonita I think the next step will be to implement voltage selection: ‘Selected Voltage’.

Didn't i make it? :)) ahaha. Okay. There is a public function which can be called from lambda, but I haven't tried to use it yet. command_request_pdo

I will also make a yaml parameter for voltage selection.

This function takes a ‘SrcVoltageSelection’ type as a parameter:

static float selected_voltage_to_float(SrcVoltageSelection voltage) {

I think we'll need a function to convert a string to this type and called command_request_pdo from lambda

binary_sensor:
  - platform: gpio
    id: set_voltage_button
    pin: 39
    on_click: 
      then:
        - lambda: 
            id(husb_01).command_request_pdo("9V");

Otherwise it returns an error during compilation:

Compiling .pioenvs/husb238/src/main.cpp.o
/config/esphome/husb238.yaml: In lambda function:
/config/esphome/husb238.yaml:66:40: error: no matching function for call to 'esphome::husb238::Husb238Component::command_request_pdo(const char [3])'
 
                                        ^
In file included from src/esphome.h:23,
                 from src/main.cpp:3:
src/esphome/components/husb238/husb238.h:146:8: note: candidate: 'bool esphome::husb238::Husb238Component::command_request_pdo(esphome::husb238::SrcVoltageSelection)'
   bool command_request_pdo(SrcVoltageSelection voltage);
        ^~~~~~~~~~~~~~~~~~~
src/esphome/components/husb238/husb238.h:146:8: note:   no known conversion for argument 1 from 'const char [3]' to 'esphome::husb238::SrcVoltageSelection'
*** [.pioenvs/husb238/src/main.cpp.o] Error 1

Like this one:

static float string_to_voltage(char *const string_voltage) {
  switch (string_voltage) {
    case "5V":
      return SrcVoltage::PD_5V;
    case "9V":
      return SrcVoltage::PD_9V;
    case "12V":
      return SrcVoltage::PD_12V;
    case "15V":
      return SrcVoltage::PD_15V;
    case "18V":
      return SrcVoltage::PD_18V;
    case "20V":
      return SrcVoltage::PD_20V;
    default:
      ESP_LOGW(TAG, "Invalid or no string voltage selected");
  }
}

@latonita
Copy link
Contributor Author

@lboue for now try this
id(husb_01).command_request_pdo(husb238::SrcVoltageSelection::SRC_PDO_12V);
ugly, but shall work

i will think of something easier :))

@latonita
Copy link
Contributor Author

latonita commented May 13, 2024

@lboue okay, i have added simpler function :))))
just pass an integer - 5, 9, 12, 15, 18, or 20 somewhere in lambda

        - lambda: |-
            id(husb_01).command_request_voltage(12);

@lboue
Copy link
Contributor

lboue commented May 13, 2024

@lboue okay, i have added simpler function :)))) just pass an integer - 5, 9, 12, 15, 18, or 20 somewhere in lambda

        - lambda: |-
            id(husb_01).command_request_voltage(12);

Thanks. Now I can select the voltage with a select componant:

image

But contracted Voltage stays at 5V.

    # 5V: 0.00A, 9V: 0.00A, 12V: 0.00A, 15V: 0.00A, 18V: 0.00A, 20V: 0.00A
  - platform: template
    name: Selected Voltage
    id: husb238_voltage
    options:
     - "5"
     - "9"
     - "12"
     - "15"
     - "18"
     - "20"
    initial_option: "5"
    optimistic: true
    on_value: 
      then:
        - lambda: |-
            int voltage =  atoi(x.c_str());
            id(husb_01).command_request_voltage(voltage);
            
    set_action:
      - logger.log:
          format: "Selected option: %s"
          args: ["x.c_str()"]

Logs

[14:09:01][D][select:015]: 'Selected Voltage': Sending state 20 (index 5)
[14:09:07][D][sensor:094]: 'Contracted Voltage': Sending state 5.00000 V with 0 decimals of accuracy
[14:09:07][D][sensor:094]: 'Contracted Current': Sending state 1.25000 A with 2 decimals of accuracy
[14:09:07][D][sensor:094]: 'Selected Voltage': Sending state 20.00000 V with 0 decimals of accuracy
[14:09:07][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[14:09:07][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[14:09:37][D][sensor:094]: 'Contracted Voltage': Sending state 5.00000 V with 0 decimals of accuracy
[14:09:37][D][sensor:094]: 'Contracted Current': Sending state 1.25000 A with 2 decimals of accuracy
[14:09:37][D][sensor:094]: 'Selected Voltage': Sending state 20.00000 V with 0 decimals of accuracy
[14:09:37][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[14:09:37][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[14:09:58][D][select:062]: 'Selected Voltage' - Setting
[14:09:58][D][select:115]: 'Selected Voltage' - Set selected option to: 18
[14:09:58][D][main:104]: Selected option: 18
[14:09:58][D][select:015]: 'Selected Voltage': Sending state 18 (index 4)
[14:10:07][D][sensor:094]: 'Contracted Voltage': Sending state 5.00000 V with 0 decimals of accuracy
[14:10:07][D][sensor:094]: 'Contracted Current': Sending state 1.25000 A with 2 decimals of accuracy
[14:10:07][D][sensor:094]: 'Selected Voltage': Sending state 18.00000 V with 0 decimals of accuracy
[14:10:07][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[14:10:07][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'

@latonita
Copy link
Contributor Author

@lboue i added some more logging. please enable verbose log level, build new version and post log results

@lboue
Copy link
Contributor

lboue commented May 13, 2024

@lboue i added some more logging. please enable verbose log level, build new version and post log results

Thansk. I am facing a build issue against last commit:

In file included from src/esphome/components/sensor/sensor.h:3,
                 from src/esphome/components/husb238/husb238.h:7,
                 from src/esphome/components/husb238/husb238.cpp:1:
src/esphome/components/husb238/husb238.cpp: In member function 'bool esphome::husb238::Husb238Component::select_pdo_voltage_(esphome::husb238::SrcVoltageSelection)':
src/esphome/components/husb238/husb238.cpp:340:74: error: too few arguments to function 'float esphome::husb238::voltage_to_float(esphome::husb238::SrcVoltage)'
   ESP_LOGV(TAG, "Setting PDO voltage selector to %.0f", voltage_to_float());
                                                                          ^
src/esphome/core/log.h:86:91: note: in definition of macro 'esph_log_v'
   esp_log_printf_(ESPHOME_LOG_LEVEL_VERBOSE, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
                                                                                           ^~~~~~~~~~~
src/esphome/components/husb238/husb238.cpp:340:3: note: in expansion of macro 'ESP_LOGV'
   ESP_LOGV(TAG, "Setting PDO voltage selector to %.0f", voltage_to_float());
   ^~~~~~~~
src/esphome/components/husb238/husb238.cpp:66:14: note: declared here
 static float voltage_to_float(SrcVoltage voltage) {
              ^~~~~~~~~~~~~~~~
*** [.pioenvs/husb238/src/esphome/components/husb238/husb238.cpp.o] Error 1
========================= [FAILED] Took 30.30 seconds =========================

CI build fails too:
https://github.com/esphome/esphome/actions/runs/9064200584/job/24902121030?pr=6693

image

@latonita
Copy link
Contributor Author

Thansk. I am facing a build issue against last commit:
apologies. pushed the files before saving )
try again plz

@lboue
Copy link
Contributor

lboue commented May 13, 2024

Thanks. This time I've got reading errors:

[22:01:26][W][component:237]: Component husb238 took a long time for an operation (83 ms).
[22:01:26][W][component:238]: Components should block for at most 30 ms.
[22:01:36][V][sensor:043]: 'Contracted Voltage': Received new state 5.000000
[22:01:36][D][sensor:094]: 'Contracted Voltage': Sending state 5.00000 V with 0 decimals of accuracy
[22:01:36][V][sensor:043]: 'Contracted Current': Received new state 1.250000
[22:01:36][D][sensor:094]: 'Contracted Current': Sending state 1.25000 A with 2 decimals of accuracy
[22:01:36][V][sensor:043]: 'Selected Voltage': Received new state 0.000000
[22:01:36][D][sensor:094]: 'Selected Voltage': Sending state 0.00000 V with 0 decimals of accuracy
[22:01:36][V][text_sensor:013]: 'Last request status': Received new state Success
[22:01:36][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[22:01:36][V][text_sensor:013]: 'Capabilities': Received new state 5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A
[22:01:36][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[22:01:36][W][component:237]: Component husb238 took a long time for an operation (85 ms).
[22:01:36][W][component:238]: Components should block for at most 30 ms.
[22:01:44][D][select:062]: 'Selected Voltage' - Setting
[22:01:44][D][select:115]: 'Selected Voltage' - Set selected option to: 15
[22:01:44][V][husb238:340]: Setting PDO voltage selector to 15
[22:01:44][V][husb238:283]: Sending command 1
[22:01:44][D][main:103]: Selected option: 15
[22:01:44][D][select:015]: 'Selected Voltage': Sending state 15 (index 3)
[22:01:44][V][husb238:340]: Setting PDO voltage selector to 15
[22:01:44][V][husb238:283]: Sending command 1
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:44][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:45][E][husb238:265]: Error reading HUSB238
[22:01:46][V][sensor:043]: 'Contracted Voltage': Received new state 5.000000
[22:01:46][D][sensor:094]: 'Contracted Voltage': Sending state 5.00000 V with 0 decimals of accuracy
[22:01:46][V][sensor:043]: 'Contracted Current': Received new state 1.250000
[22:01:46][D][sensor:094]: 'Contracted Current': Sending state 1.25000 A with 2 decimals of accuracy
[22:01:46][V][sensor:043]: 'Selected Voltage': Received new state 0.000000
[22:01:46][D][sensor:094]: 'Selected Voltage': Sending state 0.00000 V with 0 decimals of accuracy
[22:01:46][V][text_sensor:013]: 'Last request status': Received new state Success
[22:01:46][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[22:01:46][V][text_sensor:013]: 'Capabilities': Received new state 5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A
[22:01:46][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[22:01:46][W][component:237]: Component husb238 took a long time for an operation (79 ms).
[22:01:46][W][component:238]: Components should block for at most 30 ms.
[22:01:56][V][sensor:043]: 'Contracted Voltage': Received new state 5.000000
[22:01:56][D][sensor:094]: 'Contracted Voltage': Sending state 5.00000 V with 0 decimals of accuracy
[22:01:56][V][sensor:043]: 'Contracted Current': Received new state 1.250000
[22:01:56][D][sensor:094]: 'Contracted Current': Sending state 1.25000 A with 2 decimals of accuracy
[22:01:56][V][sensor:043]: 'Selected Voltage': Received new state 0.000000
[22:01:56][D][sensor:094]: 'Selected Voltage': Sending state 0.00000 V with 0 decimals of accuracy
[22:01:56][V][text_sensor:013]: 'Last request status': Received new state Success
[22:01:56][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[22:01:56][V][text_sensor:013]: 'Capabilities': Received new state 5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A
[22:01:56][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[22:01:56][W][component:237]: Component husb238 took a long time for an operation (86 ms).
[22:01:56][W][component:238]: Components should block for at most 30 ms.

@latonita
Copy link
Contributor Author

@lboue drop me an email to anton.viktorov at live.com or text me in discord, same email there
are you using esp32?

@lboue
Copy link
Contributor

lboue commented May 14, 2024

@latonita
I found the root cause. I was sending the lambda order twice.
It works properly this time. The voltage at the output of the module corresponds to that selected 👍

[06:36:22][D][select:062]: 'Selected Voltage' - Setting
[06:36:22][D][select:115]: 'Selected Voltage' - Set selected option to: 20
[06:36:22][V][husb238:340]: Setting PDO voltage selector to 20
[06:36:22][V][husb238:283]: Sending command 1
[06:36:22][D][main:103]: Selected option: 20
[06:36:22][D][select:015]: 'Selected Voltage': Sending state 20 (index 5)
[06:36:23][V][sensor:043]: 'Contracted Voltage': Received new state 20.000000
[06:36:23][D][sensor:094]: 'Contracted Voltage': Sending state 20.00000 V with 0 decimals of accuracy
[06:36:23][V][sensor:043]: 'Contracted Current': Received new state 3.250000
[06:36:23][D][sensor:094]: 'Contracted Current': Sending state 3.25000 A with 2 decimals of accuracy
[06:36:23][V][sensor:043]: 'Selected Voltage': Received new state 20.000000
[06:36:23][D][sensor:094]: 'Selected Voltage': Sending state 20.00000 V with 0 decimals of accuracy
[06:36:23][V][text_sensor:013]: 'Last request status': Received new state Success
[06:36:23][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[06:36:23][V][text_sensor:013]: 'Capabilities': Received new state 5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A
[06:36:23][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[06:36:23][W][component:237]: Component husb238 took a long time for an operation (88 ms).
[06:36:23][W][component:238]: Components should block for at most 30 ms.
[06:36:33][V][sensor:043]: 'Contracted Voltage': Received new state 20.000000
[06:36:33][D][sensor:094]: 'Contracted Voltage': Sending state 20.00000 V with 0 decimals of accuracy
[06:36:33][V][sensor:043]: 'Contracted Current': Received new state 3.250000
[06:36:33][D][sensor:094]: 'Contracted Current': Sending state 3.25000 A with 2 decimals of accuracy
[06:36:33][V][sensor:043]: 'Selected Voltage': Received new state 20.000000
[06:36:33][D][sensor:094]: 'Selected Voltage': Sending state 20.00000 V with 0 decimals of accuracy
[06:36:33][V][text_sensor:013]: 'Last request status': Received new state Success
[06:36:33][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[06:36:33][V][text_sensor:013]: 'Capabilities': Received new state 5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A
[06:36:33][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[06:36:33][W][component:237]: Component husb238 took a long time for an operation (84 ms).
[06:36:33][W][component:238]: Components should block for at most 30 ms.
[06:36:35][D][select:062]: 'Selected Voltage' - Setting
[06:36:35][D][select:115]: 'Selected Voltage' - Set selected option to: 15
[06:36:35][V][husb238:340]: Setting PDO voltage selector to 15
[06:36:35][V][husb238:283]: Sending command 1
[06:36:35][D][main:103]: Selected option: 15
[06:36:35][D][select:015]: 'Selected Voltage': Sending state 15 (index 3)
[06:36:43][V][sensor:043]: 'Contracted Voltage': Received new state 15.000000
[06:36:43][D][sensor:094]: 'Contracted Voltage': Sending state 15.00000 V with 0 decimals of accuracy
[06:36:43][V][sensor:043]: 'Contracted Current': Received new state 4.000000
[06:36:43][D][sensor:094]: 'Contracted Current': Sending state 4.00000 A with 2 decimals of accuracy
[06:36:43][V][sensor:043]: 'Selected Voltage': Received new state 15.000000
[06:36:43][D][sensor:094]: 'Selected Voltage': Sending state 15.00000 V with 0 decimals of accuracy
[06:36:43][V][text_sensor:013]: 'Last request status': Received new state Success
[06:36:43][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[06:36:43][V][text_sensor:013]: 'Capabilities': Received new state 5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A
[06:36:43][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[06:36:43][W][component:237]: Component husb238 took a long time for an operation (85 ms).
[06:36:43][W][component:238]: Components should block for at most 30 ms.
[06:36:48][D][select:062]: 'Selected Voltage' - Setting
[06:36:48][D][select:115]: 'Selected Voltage' - Set selected option to: 12
[06:36:48][V][husb238:340]: Setting PDO voltage selector to 12
[06:36:48][V][husb238:283]: Sending command 1
[06:36:48][D][main:103]: Selected option: 12
[06:36:48][D][select:015]: 'Selected Voltage': Sending state 12 (index 2)
[06:36:53][V][sensor:043]: 'Contracted Voltage': Received new state 12.000000
[06:36:53][D][sensor:094]: 'Contracted Voltage': Sending state 12.00000 V with 0 decimals of accuracy
[06:36:53][V][sensor:043]: 'Contracted Current': Received new state 5.000000
[06:36:53][D][sensor:094]: 'Contracted Current': Sending state 5.00000 A with 2 decimals of accuracy
[06:36:53][V][sensor:043]: 'Selected Voltage': Received new state 12.000000
[06:36:53][D][sensor:094]: 'Selected Voltage': Sending state 12.00000 V with 0 decimals of accuracy
[06:36:53][V][text_sensor:013]: 'Last request status': Received new state Success
[06:36:53][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[06:36:53][V][text_sensor:013]: 'Capabilities': Received new state 5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A
[06:36:53][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[06:36:53][W][component:237]: Component husb238 took a long time for an operation (85 ms).
[06:36:53][W][component:238]: Components should block for at most 30 ms.
[06:37:03][V][sensor:043]: 'Contracted Voltage': Received new state 12.000000
[06:37:03][D][sensor:094]: 'Contracted Voltage': Sending state 12.00000 V with 0 decimals of accuracy
[06:37:03][V][sensor:043]: 'Contracted Current': Received new state 5.000000
[06:37:03][D][sensor:094]: 'Contracted Current': Sending state 5.00000 A with 2 decimals of accuracy
[06:37:03][V][sensor:043]: 'Selected Voltage': Received new state 12.000000
[06:37:03][D][sensor:094]: 'Selected Voltage': Sending state 12.00000 V with 0 decimals of accuracy
[06:37:03][V][text_sensor:013]: 'Last request status': Received new state Success
[06:37:03][D][text_sensor:064]: 'Last request status': Sending state 'Success'
[06:37:03][V][text_sensor:013]: 'Capabilities': Received new state 5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A
[06:37:03][D][text_sensor:064]: 'Capabilities': Sending state '5V: 3.00A, 9V: 3.00A, 12V: 5.00A, 15V: 4.00A, 20V: 3.25A'
[06:37:03][W][component:237]: Component husb238 took a long time for an operation (84 ms).
[06:37:03][W][component:238]: Components should block for at most 30 ms.

@lboue
Copy link
Contributor

lboue commented May 15, 2024

@latonita
The voltage selection now works with an external selector component in my YAML configuration.
I think the voltage selector should be added directly to the component to simplify its use. And maybe a current selector as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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