syssi/esphome-jbd-bms

Force wait value before api / mqtt available

Opened this issue ยท 3 comments

Hi men, is there is a way to force the esp to wait some or all sensor / switch to be avalaible before making the api or the mqtt available ?
I ask this because in my HA, everytime i go deepsleep this appends
image

But when i disable it > working without any problem ๐Ÿ˜…

This could be so great when i leave with my scooter no error message on HA and when i am back to home, just update of value when the value is ready and not before or in some part like now ๐Ÿ˜…

SORRY for my english ๐Ÿซ ๐Ÿซ ๐Ÿซ ๐Ÿซ 

My full config :

substitutions:
  name: scooter-battery
  bms0: "BMS0"
  bms1: "BMS1"
  device_description: "Monitor and control a Xiaoxiang Battery Management System (JBD-BMS) via BLE"
  external_components_source: github://syssi/esphome-jbd-bms@main
  bms0_mac_address: # BMS 0
  bms1_mac_address: # BMS 1

esphome:
  name: ${name}
  comment: ${device_description}
  project:
    name: "syssi.esphome-jbd-bms"
    version: 1.5.0

esp32:
  board: esp32dev
  framework:
    type: arduino

external_components:
  - source: ${external_components_source}
    refresh: 0s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.0.61
    gateway: 192.168.0.254
    subnet: 255.255.255.0
  reboot_timeout: 0s

ota:
  password: !secret esp_scooter_ota

api:
  encryption:
    key: !secret esp_scooter_api
  reboot_timeout: 0s

deep_sleep:
  id: deep_sleep0
  run_duration: 2min
  sleep_duration: 10min

esp32_ble_tracker:
  on_ble_advertise:
    then:
      - lambda: |-
          if (x.get_name().rfind("xiaoxiang", 0) == 0) {
            ESP_LOGI("ble_adv", "New JBD-BMS found");
            ESP_LOGI("ble_adv", "  Name: %s", x.get_name().c_str());
            ESP_LOGI("ble_adv", "  MAC address: %s", x.address_str().c_str());
            ESP_LOGD("ble_adv", "  Advertised service UUIDs:");
            for (auto uuid : x.get_service_uuids()) {
              ESP_LOGD("ble_adv", "    - %s", uuid.to_string().c_str());
            }
          }

ble_client:
  - mac_address: ${bms0_mac_address}
    id: client0
  - mac_address: ${bms1_mac_address}
    id: client1

jbd_bms_ble:
  - id: bms0
    ble_client_id: client0
    update_interval: 5s
  - id: bms1
    ble_client_id: client1
    update_interval: 5s

binary_sensor:
  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms0
    balancing:
      name: "${bms0} balancing"
    charging:
      name: "${bms0} charging"
    discharging:
      name: "${bms0} discharging"
    online_status:
      name: "${bms0} online status"
  
  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms1
    balancing:
      name: "${bms1} balancing"
    charging:
      name: "${bms1} charging"
    discharging:
      name: "${bms1} discharging"
    online_status:
      name: "${bms1} online status"

switch:
  - platform: ble_client
    ble_client_id: client0
    name: "${bms0} enable bluetooth connection"

  - platform: ble_client
    ble_client_id: client1
    name: "${bms1} enable bluetooth connection"

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms0
    charging:
      name: "${bms0} charging"
      id: charging0
    discharging:
      name: "${bms0} discharging"

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms1
    charging:
      name: "${bms1} charging"
      id: charging1
    discharging:
      name: "${bms1} discharging"

sensor:
  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms0
    battery_strings:
      name: "${bms0} cells"
    charging_power:
      name: "${bms0} charging power"
    state_of_charge:
      name: "${bms0} pourcentage"
      id: state_of_charge0
      on_value:
        # Enable charging if the state of charge is below 80%
        - if:
            condition:
              and:
                - switch.is_off: charging0
                - sensor.in_range:
                    id: state_of_charge0
                    below: 79.0
            then:
              - switch.turn_on: charging0
        # Stop charging if the state of charge is above 80%
        - if:
            condition:
              and:
                - switch.is_on: charging0
                - sensor.in_range:
                    id: state_of_charge0
                    above: 80.0
            then:
              - switch.turn_off: charging0
        # Suspend deep sleep at the end of a charge cycle to stop on point (optional!)
        - if:
            condition:
              and:
                - switch.is_on: charging0
                - sensor.in_range:
                    id: state_of_charge0
                    above: 75.0
            then:
              - deep_sleep.prevent: deep_sleep0
    nominal_capacity:
      name: "${bms0} nominal capacity"
    charging_cycles:
      name: "${bms0} charging cycles"
    battery_cycle_capacity:
      name: "${bms0} cycle capacity"
    total_voltage:
      name: "${bms0} total voltage"
    average_cell_voltage:
      name: "${bms0} average cell voltage"
    delta_cell_voltage:
      name: "${bms0} delta cell voltage"
    temperature_1:
      name: "${bms0} temperature 1"
    temperature_2:
      name: "${bms0} temperature 2"
    temperature_3:
      name: "${bms0} temperature 3"
    cell_voltage_1:
      name: "${bms0} cell voltage 1"
    cell_voltage_2:
      name: "${bms0} cell voltage 2"
    cell_voltage_3:
      name: "${bms0} cell voltage 3"
    cell_voltage_4:
      name: "${bms0} cell voltage 4"
    cell_voltage_5:
      name: "${bms0} cell voltage 5"
    cell_voltage_6:
      name: "${bms0} cell voltage 6"
    cell_voltage_7:
      name: "${bms0} cell voltage 7"
    cell_voltage_8:
      name: "${bms0} cell voltage 8"
    cell_voltage_9:
      name: "${bms0} cell voltage 9"
    cell_voltage_10:
      name: "${bms0} cell voltage 10"
  
  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms1
    battery_strings:
      name: "${bms1} cells"
    charging_power:
      name: "${bms1} charging power"
    state_of_charge:
      name: "${bms1} pourcentage"
      id: state_of_charge1
      on_value:
        # Enable charging if the state of charge is below 80%
        - if:
            condition:
              and:
                - switch.is_off: charging1
                - sensor.in_range:
                    id: state_of_charge1
                    below: 79.0
            then:
              - switch.turn_on: charging1
        # Stop charging if the state of charge is above 80%
        - if:
            condition:
              and:
                - switch.is_on: charging1
                - sensor.in_range:
                    id: state_of_charge1
                    above: 80.0
            then:
              - switch.turn_off: charging1
        # Suspend deep sleep at the end of a charge cycle to stop on point (optional!)
        - if:
            condition:
              and:
                - switch.is_on: charging1
                - sensor.in_range:
                    id: state_of_charge1
                    above: 75.0
            then:
              - deep_sleep.prevent: deep_sleep0
    nominal_capacity:
      name: "${bms1} nominal capacity"
    charging_cycles:
      name: "${bms1} charging cycles"
    battery_cycle_capacity:
      name: "${bms1} cycle capacity"
    total_voltage:
      name: "${bms1} total voltage"
    average_cell_voltage:
      name: "${bms1} average cell voltage"
    delta_cell_voltage:
      name: "${bms1} delta cell voltage"
    temperature_1:
      name: "${bms1} temperature 1"
    temperature_2:
      name: "${bms1} temperature 2"
    temperature_3:
      name: "${bms1} temperature 3"
    cell_voltage_1:
      name: "${bms1} cell voltage 1"
    cell_voltage_2:
      name: "${bms1} cell voltage 2"
    cell_voltage_3:
      name: "${bms1} cell voltage 3"
    cell_voltage_4:
      name: "${bms1} cell voltage 4"
    cell_voltage_5:
      name: "${bms1} cell voltage 5"
    cell_voltage_6:
      name: "${bms1} cell voltage 6"
    cell_voltage_7:
      name: "${bms1} cell voltage 7"
    cell_voltage_8:
      name: "${bms1} cell voltage 8"
    cell_voltage_9:
      name: "${bms1} cell voltage 9"
    cell_voltage_10:
      name: "${bms1} cell voltage 10"
syssi commented

I must admit I don't understand the screenshot above. First of all: The entity names of the sensor at the YAML are a bit different to the entity names at the screenshot. Is the screenshot out of sync to the YAML configuration or did you rename the entities?

What happens to the measurements if your node goes into deep sleep? Do you see the last measurement or something like unavailable at the right column? If you reboot Home Assistant and the ESPHome node isn't available because of deep sleep the yellow triangle warnings does show up? Could you try to provide some more details about the issue?

Hello, i just rename my sensor ๐Ÿ˜…

I have try to restart HA, same problem ๐Ÿซ 

What happens to the measurements if your node goes into deep sleep

The data stay here without problem when deep sleep is on but few deep sleep loop the esp start to send data to home assistant without having the true data and then the esp send "unvailable" (see screenshot)

Could you try to provide some more details about the issue?

It's simple : Is there is a way to NOT send data to HA until when esp is connected to a bms battery scooter and retrieve true data and not "unvailable" ?