syssi / esphome-jk-bms

ESPHome component to monitor and control a Jikong Battery Management System (JK-BMS) via UART-TTL or BLE
Apache License 2.0
442 stars 148 forks source link

Sensor "online_status" available from Home Assistant ? #304

Closed rfenouil closed 1 year ago

rfenouil commented 1 year ago

Hi :)

Apologies for opening a second issue in a day, I love how your lib integrates to Home assistant but I think I misunderstand something.

In recent commits, you added a binary_sensor named online_status, but I cannot find it in home assistant.

I would like to use it for a conditional card in lovelace UI, so I get an alternative presentation when the device is not available (instead of having all values showing 'unavailable').

Is it exported to mqtt or only designed for internal/web interface ?

On the same flavor (using recent updates), should I be able to access to a web interface when connecting to the eps32 ip adress with a browser ? If so, I probably don't compile the most up to date version because I can't access it... Or maybe it is served on a specific port ?

Thank you again for your help.

rfenouil commented 1 year ago

For the conditional card, I can actually test for value 'unavailable' but a more direct value would be easier to integrate (in timelines for instance).

For now, this works:

- type: conditional
    conditions:
      - entity: sensor.jk_bms_total_runtime_formatted
        state: 'unavailable'
    card:
      ...
syssi commented 1 year ago

Is the binary sensor online_status the entity you are looking for? It is part of your YAML already?

syssi commented 1 year ago

Per default your are using the @main branch so you should benefit from all changes / recently added features. There is a new entity called online_status which should be available in HA too if it's part of your YAML. If you update the YAML + compile & flash your ESP the changes should be available instantly. Is there a reason why you prefer MQTT over the native api?

rfenouil commented 1 year ago

Thank you for your message,

There was a reason to use MQTT in a separate container at some point, but I cannot remember why :) Maybe because my Home assistant is in a docker too, because of some Tasmota sensors, or external access required.

The native API is a MQTT server hosted and managed by HA itself ? Is it a better option ?

online_status is indeed part of the YAML, and I can actually see it published in MQTT explorer. It just does not appear as an entity on home assistant... Not sure why. Everything else is listed automatically (including other binary_sensor elements 'balancing' 'charging' and 'discharging').

I tried flushing eveyrhing related to jk-bms in MQTT and HA to force a rediscovery, with same result.

binary_sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    balancing:
      name: "${bms0} balancing"
    charging:
      name: "${bms0} charging"
    discharging:
      name: "${bms0} discharging"
    online_status:
      name: "${bms0} online status"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    balancing:
      name: "${bms1} balancing"
    charging:
      name: "${bms1} charging"
    discharging:
      name: "${bms1} discharging"
    online_status:
      name: "${bms1} online status"
syssi commented 1 year ago

The ESPHome Integration of Home Assistant is able to talk to the native api of the ESPHome node directly. It's the recommended way to talk to ESPHome devices if Home Assistant is in use. In this case no MQTT broker is required anymore.

I assume the MQTT auto-discovery of the exposed entities didn't work well here. If you switch to the native api I'm pretty sure you will find the "online status" sensor entities this time.

rfenouil commented 1 year ago

It does work with api insead of MQTT... Still a bit frustrated not to understand what happened but I'll switch to api, seems simpler.

Thank you !!