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

Huawei AC Charger is missing on MQTT HA Auto-Discovery #1491

Open
4 tasks done
scharrrfi opened this issue Dec 30, 2024 · 10 comments
Open
4 tasks done

Huawei AC Charger is missing on MQTT HA Auto-Discovery #1491

scharrrfi opened this issue Dec 30, 2024 · 10 comments
Assignees
Labels
acknowledged enhancement New feature or request

Comments

@scharrrfi
Copy link

What happened?

It seems, that the Huawei AC Charger is missing in Home Assistant MQTT Auto-Discovery Topic.

Screenshot 2024-12-30 181238 Screenshot 2024-12-30 181218 Screenshot 2024-12-30 181151

To Reproduce Bug

Unmark the Auto-Discovery option, save an mark it again.

Expected Behavior

Home Assistant should create a Huawei AC Charger device.

Install Method

Pre-Compiled binary from GitHub releases

What git-hash/version of OpenDTU-OnBattery?

2024.11.20

What firmware variant (PIO Environment)?

generic_esp32_4mb_no_ota

Relevant log/trace output

No response

Anything else?

No response

Please confirm the following

  • I believe this issue is a bug that affects all users of OpenDTU-OnBattery, not something specific to my installation.
  • I have already searched for relevant existing issues and discussions before opening this report.
  • I have updated the title field above with a concise description.
  • I have double checked that my inverter does not contain a W in the model name (like HMS-xxxW) as they are not supported.
@scharrrfi scharrrfi added the bug Something isn't working label Dec 30, 2024
@schlimmchen schlimmchen self-assigned this Dec 31, 2024
@schlimmchen
Copy link
Member

Is disabling and re-enabling HASS Autodiscovery neccesary to see the issue? In other words: Have you ever seen the AC charger in HASS at all?

@scharrrfi
Copy link
Author

scharrrfi commented Dec 31, 2024

I thought, that re-enabling does start a new Auto-Discovery with all devices. I have added the AC charger later in the OpenDTU setup. I have never seen the AC charger in Home Assistant at all.

But the states will published over MQTT correctly:
Screenshot 2024-12-31 161930

@AndreasBoehm
Copy link
Member

@scharrrfi could you check if you can find AC charger related topics under the homeassistant topic?
Screenshot 2025-01-10 at 18 20 39

@scharrrfi
Copy link
Author

It is not under the homeassistant topic.

Copy link

github-actions bot commented Feb 1, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Feb 1, 2025
@schlimmchen
Copy link
Member

I will eventually look at this more closely. Right now it looks like there is no HASS auto-discovery at all for the Huawei grid charger.

@schlimmchen schlimmchen added enhancement New feature or request acknowledged and removed bug Something isn't working stale labels Feb 2, 2025
@boennemann
Copy link

I'm observing the exact same behavior.

@boennemann
Copy link

I'm not familiar enough with the code base to contribute this directly, but I used my friendly neighborhood LLM to help me come up with this script. It sets the auto discovery values accordingly and everything shows up on HA.

Image
#!/bin/bash

MQTT_BROKER="localhost"
MQTT_PORT=1883
MQTT_USER="mqtt"
MQTT_PASS="password"

DEVICE_ID="huawei_r4850g2_0001"
DEVICE_NAME="Huawei R4850G2"
MQTT_BASE_TOPIC="homeassistant"

TOPIC_PREFIX="huawei/huawei"

DEVICE_INFO='"dev": {
    "name": "Huawei R4850G2",
    "ids": "'"$DEVICE_ID"'",
    "mf": "Huawei",
    "mdl": "R4850G2"
}'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/data_age/config" \
  -m '{
    "name": "Data Age",
    "stat_t": "'"$TOPIC_PREFIX/data_age"'",
    "uniq_id": "'"$DEVICE_ID"_data_age'",
    "unit_of_meas": "s",
    "dev_cla": "duration",
    "stat_cla": "total",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/efficiency/config" \
  -m '{
    "name": "Efficiency",
    "stat_t": "'"$TOPIC_PREFIX/efficiency"'",
    "uniq_id": "'"$DEVICE_ID"_efficiency'",
    "unit_of_meas": "%",
    "stat_cla": "measurement",
    "val_tpl": "{{ (value | float * 100) | round(1) }}",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/output_voltage/config" \
  -m '{
    "name": "Output Voltage",
    "stat_t": "'"$TOPIC_PREFIX/output_voltage"'",
    "uniq_id": "'"$DEVICE_ID"_output_voltage'",
    "unit_of_meas": "V",
    "dev_cla": "voltage",
    "stat_cla": "measurement",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/input_voltage/config" \
  -m '{
    "name": "Input Voltage",
    "stat_t": "'"$TOPIC_PREFIX/input_voltage"'",
    "uniq_id": "'"$DEVICE_ID"_input_voltage'",
    "unit_of_meas": "V",
    "dev_cla": "voltage",
    "stat_cla": "measurement",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/output_current/config" \
  -m '{
    "name": "Output Current",
    "stat_t": "'"$TOPIC_PREFIX/output_current"'",
    "uniq_id": "'"$DEVICE_ID"_output_current'",
    "unit_of_meas": "A",
    "dev_cla": "current",
    "stat_cla": "measurement",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/max_output_current/config" \
  -m '{
    "name": "Max Output Current",
    "stat_t": "'"$TOPIC_PREFIX/max_output_current"'",
    "uniq_id": "'"$DEVICE_ID"_max_output_current'",
    "unit_of_meas": "A",
    "dev_cla": "current",
    "stat_cla": "measurement",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/input_current/config" \
  -m '{
    "name": "Input Current",
    "stat_t": "'"$TOPIC_PREFIX/input_current"'",
    "uniq_id": "'"$DEVICE_ID"_input_current'",
    "unit_of_meas": "A",
    "dev_cla": "current",
    "stat_cla": "measurement",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/output_power/config" \
  -m '{
    "name": "Output Power",
    "stat_t": "'"$TOPIC_PREFIX/output_power"'",
    "uniq_id": "'"$DEVICE_ID"_output_power'",
    "unit_of_meas": "W",
    "dev_cla": "power",
    "stat_cla": "measurement",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/input_power/config" \
  -m '{
    "name": "Input Power",
    "stat_t": "'"$TOPIC_PREFIX/input_power"'",
    "uniq_id": "'"$DEVICE_ID"_input_power'",
    "unit_of_meas": "W",
    "dev_cla": "power",
    "stat_cla": "measurement",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/input_temp/config" \
  -m '{
    "name": "Input Air Temperature",
    "stat_t": "'"$TOPIC_PREFIX/input_temp"'",
    "uniq_id": "'"$DEVICE_ID"_input_temp'",
    "unit_of_meas": "°C",
    "dev_cla": "temperature",
    "stat_cla": "measurement",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/sensor/$DEVICE_ID/output_temp/config" \
  -m '{
    "name": "Output Air Temperature",
    "stat_t": "'"$TOPIC_PREFIX/output_temp"'",
    "uniq_id": "'"$DEVICE_ID"_output_temp'",
    "unit_of_meas": "°C",
    "dev_cla": "temperature",
    "stat_cla": "measurement",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/number/$DEVICE_ID/limit_online_voltage/config" \
  -m '{
    "name": "Online Voltage Limit",
    "cmd_t": "'"$TOPIC_PREFIX/cmd/limit_online_voltage"'",
    "min": 48,
    "max": 58.5,
    "step": 0.1,
    "unit_of_meas": "V",
    "uniq_id": "'"$DEVICE_ID"_limit_online_voltage'",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/number/$DEVICE_ID/limit_online_current/config" \
  -m '{
    "name": "Online Current Limit",
    "cmd_t": "'"$TOPIC_PREFIX/cmd/limit_online_current"'",
    "min": 0,
    "max": 50,
    "step": 0.1,
    "unit_of_meas": "A",
    "uniq_id": "'"$DEVICE_ID"_limit_online_current'",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/number/$DEVICE_ID/limit_offline_voltage/config" \
  -m '{
    "name": "Offline Voltage Limit",
    "cmd_t": "'"$TOPIC_PREFIX/cmd/limit_offline_voltage"'",
    "min": 48,
    "max": 58.5,
    "step": 0.1,
    "unit_of_meas": "V",
    "uniq_id": "'"$DEVICE_ID"_limit_offline_voltage'",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/number/$DEVICE_ID/limit_offline_current/config" \
  -m '{
    "name": "Offline Current Limit",
    "cmd_t": "'"$TOPIC_PREFIX/cmd/limit_offline_current"'",
    "min": 0,
    "max": 50,
    "step": 0.1,
    "unit_of_meas": "A",
    "uniq_id": "'"$DEVICE_ID"_limit_offline_current'",
    '"$DEVICE_INFO"'
  }'

mosquitto_pub -r -h "$MQTT_BROKER" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t "$MQTT_BASE_TOPIC/select/$DEVICE_ID/charger_mode/config" \
  -m '{
    "name": "Charger Mode",
    "cmd_t": "'"$TOPIC_PREFIX/cmd/mode"'",
    "stat_t": "'"$TOPIC_PREFIX/mode"'",
    "options": ["0", "1", "2", "3"],
    "uniq_id": "'"$DEVICE_ID"_charger_mode'",
    '"$DEVICE_INFO"'
  }'

echo "✅ MQTT Auto-Discovery messages sent. Restart Home Assistant to apply changes."

@schlimmchen
Copy link
Member

Hm, yeah, feel free to use this, however beware that I don't know what happens when the canonical HA auto-discovery is ready, which will probably look different than the config this script provides. I guess the entities will be different then, so once the canonical ones are auto-discovered and should be used, they are different entities than these. Not sure whether I explained this well enough...

@boennemann
Copy link

@schlimmchen Yeah, no, perfectly makes sense. I'm very aware that I'm setting myself up for some migration fun later. Thank you for the warning!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants