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

Clear display values if nothing recieved #88

Open
BurlyOaf opened this issue Jan 6, 2025 · 5 comments
Open

Clear display values if nothing recieved #88

BurlyOaf opened this issue Jan 6, 2025 · 5 comments

Comments

@BurlyOaf
Copy link

BurlyOaf commented Jan 6, 2025

This is awesome, love your work!
I was wondering though, it may be simple and something I just haven't discovered / learnt.

If say we went out of bluetooth range, could the values displayed go blank until new values are received?

@Fabian-Schmidt
Copy link
Owner

Fabian-Schmidt commented Jan 6, 2025

There is no out of the box way in ESPHome. But it could be added either via a script or into this component.

The idea is you have a script which sets a flag:

script:
  - id: victron_present_reset
    then:
      - delay: 60s
      - globals.set:
          id: victron_present
          value: 'false'

globals:
  - id: victron_present
    type: bool
    restore_value: false
    initial_value: 'false'

And in the on_message event you reset it.

victron_ble:
  - id: MySmartShunt
    mac_address: ${smart_shunt_mac_address}
    bindkey: ${smart_shunt_encryption_key}
    on_message:
      then:
        - lambda: |-
            id(victron_present) = true;
            id(victron_present_reset).stop();
            id(victron_present_reset).execute();

And in the display you check the global variable:

if (!id(victron_present)) {
  // Victron device stale
} else {
  // Victron device fresh
}

@BurlyOaf
Copy link
Author

BurlyOaf commented Jan 7, 2025

Awesome thanks, I'll give it a whirl, I think I understand the first 3 bits,

but I am not sure on how to use the display bit, does it go straight after (below)
u_int16_t y = first_pad;
?

@Fabian-Schmidt
Copy link
Owner

The third bit is in the individual display elements. E.g.

Instead of:

      // shunt_AUX_VOLTAGE
      it.printf(x1i, y, id(font_icons_small), TextAlign::BASELINE_CENTER, "\U000F010C");  // mdi-car-battery
      if (!std::isnan(id(shunt_AUX_VOLTAGE).state)) {
        it.printf(x1i + icon_pad, y, id(font_value), TextAlign::BASELINE_LEFT, "%.2f V", id(shunt_AUX_VOLTAGE).state);
      }

You add the victron_present validation:

      // shunt_AUX_VOLTAGE
      it.printf(x1i, y, id(font_icons_small), TextAlign::BASELINE_CENTER, "\U000F010C");  // mdi-car-battery
      if (!std::isnan(id(shunt_AUX_VOLTAGE).state) && id(victron_present)) {
        it.printf(x1i + icon_pad, y, id(font_value), TextAlign::BASELINE_LEFT, "%.2f V", id(shunt_AUX_VOLTAGE).state);
      }

So then the number is only displayed if some value is there and it is not stale.

@BurlyOaf
Copy link
Author

BurlyOaf commented Jan 7, 2025

Thank you so much for that!
So far it looks to be working, i think :) I added the script: global: and victron_ble: sections you posted, and added " && id(victron_present)" into the display elements, as above.

But, I haven't added this anywhere..?

if (!id(victron_present)) {
// Victron device stale
} else {
// Victron device fresh
}

@Fabian-Schmidt
Copy link
Owner

This part is a simpler version of the other.
You could instead write: They are functionally identical.

      if (id(victron_present)) {
        if (!std::isnan(id(shunt_AUX_VOLTAGE).state)) {
          it.printf(x1i + icon_pad, y, id(font_value), TextAlign::BASELINE_LEFT, "%.2f V", id(shunt_AUX_VOLTAGE).state);
        }
      }

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

No branches or pull requests

2 participants