Blackymas / NSPanel_HA_Blueprint

This allows you to configure your complete NSPanel via Blueprint with UI and without changing anything in the code
1.4k stars 253 forks source link

Hardware button bars #1920

Closed ademobile closed 6 months ago

ademobile commented 6 months ago

TFT Version

4.3.0

ESPHome Version

2024.2.2

Blueprint Version

4.3.0

Panel Model

EU

What is the bug?

As I use hue light scenes that can be multistates, I used to set the bars by a service call to allow someone to know lights were on or off, espically lights that cannot be seen. In this update the 'feature' has been removed.

Code I used that now does not work:

turn a bar on service: esphome.nspanel_86_lr_send_command_printf data: cmd: home.right_bt_pic.val=1

turn a bar off service: esphome.nspanel_86_lr_send_command_printf data: cmd: home.right_bt_pic.val=0

I have found the following service, however it is no use as you need BOTH left and right and I will not know the state of the other bar when making the call:

service: esphome._hw_button_state data: left: true # Turns the left button's indication bar on right: false # Turns the right button's indication bar off

However calling the sevice does not seem to make the bars come 'on'

Steps to Reproduce

No response

Your Panel's YAML

No response

ESPHome Logs

No response

Home Assistant Logs

No response

edwardtfn commented 6 months ago

I'm not close to my panels now, so I cannot run tests, but adding this customization to your panel's yamls should expose switches entities representing each of the bars in the screen.

switch:
  - id: hw_bt_bar_left
    platform: template
    name: Hardware Button Bar - Left
    internal: false
    lambda: return (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State);
    optimistic: true
    turn_on_action:
      - logger.log: Turning left bar "on"
      - lambda: |-
          update_bitwise_setting(id(buttons_settings), true, ButtonSettings::ButtonLeft_State);
          refresh_hardware_buttons_bars->execute();
    turn_off_action:
      - logger.log: Turning left bar "off"
      - lambda: |-
          update_bitwise_setting(id(buttons_settings), false, ButtonSettings::ButtonLeft_State);
          refresh_hardware_buttons_bars->execute();
  - id: hw_bt_bar_right
    platform: template
    name: Hardware Button Bar - Right
    internal: false
    lambda: return (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State);
    turn_on_action:
      - logger.log: Turning right bar "on"
      - lambda: |-
          update_bitwise_setting(id(buttons_settings), true, ButtonSettings::ButtonRight_State);
          refresh_hardware_buttons_bars->execute();
    turn_off_action:
      - logger.log: Turning right bar "off"
      - lambda: |-
          update_bitwise_setting(id(buttons_settings), false, ButtonSettings::ButtonRight_State);
          refresh_hardware_buttons_bars->execute();

script:
  - id: !extend refresh_hardware_buttons_bars
    then:
      - lambda: |-
          if (hw_bt_bar_left->state != (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State))
            hw_bt_bar_left->publish_state(id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State);
          if (hw_bt_bar_right->state != (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State))
            hw_bt_bar_right->publish_state(id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State);

Please let me know your results. 😉

ademobile commented 6 months ago

Interesting, although this has now given me two switches, nothing is displayed on the display! There are NO bars, dimmed grey or blue. Is this because I do not have an entity assigned to the hardware button?

I pick up the event in home assistant to allow the hardware do different things depending on context. E.g. the left button controlls the outside light colour by a single press and toggles between white and blue on each press. If you long press it turns the outside lights off

EDIT

To test the theory out, I added a temporay entity to a hardware button, and the bar appeared. I could also control the bar state with the two new switches.

edwardtfn commented 6 months ago

There are NO bars, dimmed grey or blue. Is this because I do not have an entity assigned to the hardware button?

That's correct. The information to show of not those buttons are send during boot and is defined by an entity assigned to the button. You can force it also with a customization. Just change the previous code I sent on the script area like this:

script:
  - id: !extend refresh_hardware_buttons_bars
    then:
      - lambda: |-
          update_bitwise_setting(id(buttons_settings), true, ButtonSettings::ButtonLeft_Enabled);
          update_bitwise_setting(id(buttons_settings), true, ButtonSettings::ButtonRight_Enabled);
          if (hw_bt_bar_left->state != (id(buttons_settings) & ButtonSettings::ButtonLeft_State))
            hw_bt_bar_left->publish_state(id(buttons_settings) & ButtonSettings::ButtonLeft_State);
          if (hw_bt_bar_right->state != (id(buttons_settings) & ButtonSettings::ButtonRight_State))
            hw_bt_bar_right->publish_state(id(buttons_settings) & ButtonSettings::ButtonRight_State);
ademobile commented 6 months ago

Brillitant - that works!!! Thank you