Blackymas / NSPanel_HA_Blueprint

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

`Bug` hw_button_state fails to turn "led" off without short delay #1933

Closed MichaelHeimann closed 3 months ago

MichaelHeimann commented 3 months ago

TFT Version

4.3

ESPHome Version

4.3

Blueprint Version

4.3

Panel Model

EU

What is the bug?

An automation that disables a hw_button_state fails to turn the state off but the "led" bar just flickers and stays on.

Adding a 100ms delay fixes it (!).

Automation is this:

alias: Küche Unterschrank Anzeige im NSPanel
description: >-
  Wenn Küche Unterschrank an ist soll im NSPanel der blaue Balken über der
  linken Taste leuchten
trigger:
  - platform: device
    type: turned_on
    device_id: b111fe8e3bbfcdc4adee4e6d59a1836a
    entity_id: 9df71ee72db9fad674de6d6fb027d88c
    domain: switch
    id: an
  - platform: device
    type: turned_off
    device_id: b111fe8e3bbfcdc4adee4e6d59a1836a
    entity_id: 9df71ee72db9fad674de6d6fb027d88c
    domain: switch
    id: aus
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 100
  - choose:
      - conditions:
          - condition: trigger
            id:
              - an
        sequence:
          - if:
              - condition: state
                entity_id: light.kuche_decke
                state: "on"
            then:
              - service: esphome.nskueche_hw_button_state
                data:
                  left: true
                  right: true
                alias: Beide an
            else:
              - alias: Links an Rechts aus
                service: esphome.nskueche_hw_button_state
                data:
                  left: true
                  right: false
      - conditions:
          - condition: trigger
            id:
              - aus
        sequence:
          - if:
              - condition: state
                entity_id: light.kuche_decke
                state: "on"
            then:
              - alias: Links aus, Rechts an
                service: esphome.nskueche_hw_button_state
                data:
                  left: false
                  right: true
            else:
              - alias: Beide aus
                service: esphome.nskueche_hw_button_state
                data:
                  left: false
                  right: false
mode: single

Steps to Reproduce

config:

1) Have an automation assigned to a hw button 2) set the blueprint to trigger automations and not toggle them on/off. 3) have another automation to control the "led-bar" via new hw_button_state service

reproduce steps: 1) use the hw-button, which triggers a lightgroup to turn off 2) see the led-bar to flicker instead of turning off 3) add delay of 100ms before hw_button_state service to actually turn it off

Your Panel's YAML

No response

ESPHome Logs

logs_nskueche_logs.txt esphome log - I cannot see a difference

Home Assistant Logs

I don't know how to gather the relevant bit's here. Please help.

edwardtfn commented 3 months ago

I believe this is solved in DEV and will be included in a new release soon.

MichaelHeimann commented 3 months ago

I believe this is solved in DEV and will be included in a new release soon.

It's not fixed but still remains. Here's a video of the flicker with the 100ms step removed in the automation:

https://github.com/Blackymas/NSPanel_HA_Blueprint/assets/3189562/06b85290-8aa4-4edc-b413-45ad8814215f

sorry for the slow video: I needed to do it in slow motion to actually make it visible

So it's: bad: button press -> automation triggered to turn off light -> light turns off -> automation triggered to set hw_button_state -> turn off hw_state

good: button press -> automation triggered to turn off light -> light turns off -> automation triggered to set hw_button_state -> wait 100ms -> turn off hw_state

edwardtfn commented 3 months ago

How is the state of this entity on Developers Tools > State?

MichaelHeimann commented 3 months ago

You mean the trigger for the automation that sets the hw_button_state? It's off or on.

I actually used the "device" platform first, but now I also used the "state" with no difference. The device is a shelly 1PM integrated with the shelly addon.

I did doublecheck - the automation is not triggered again to set the indicator back to on:

https://github.com/Blackymas/NSPanel_HA_Blueprint/assets/3189562/a0921d1e-0c6c-4c8f-b0d9-232a42a564bd

edwardtfn commented 3 months ago

So, you are saying you don't have any entity assigned to that button with the Blueprint and all the control is done outside in your automation?

I'm a bit lost here.

MichaelHeimann commented 3 months ago

I'll try to make it clearer:

bluprint: "left hardware button - entity (otpional)" is assigned to an automation. (which besides others, switches some light on or off.)

other automation triggers on one of the lights changing to on or off and sets the button state accordingly.

edwardtfn commented 3 months ago

Ok, so in the blueprint, what is set for "System settings - Button action for automation entities"?

edwardtfn commented 3 months ago

We have an issue here... for automations, that indicator is normally "off", and it will be "on" for 800msec when you press the button, then it will turn the indicator "off" again. This is probably the issue here, although this was always like that.

MichaelHeimann commented 3 months ago

Ah. Maybe an option to detach automation state from indicator would help.

MichaelHeimann commented 3 months ago

We have an issue here... for automations, that indicator is normally "off", and it will be "on" for 800msec when you press the button, then it will turn the indicator "off" again. This is probably the issue here, although this was always like that.

But that is broken then, too. Because when I turn on the lightgroup (by pushing the button that triggers the automation) the indicator stays on. And is not turned off (after 800ms)

edwardtfn commented 3 months ago

But this is incorrect fr8k the beginning. An automation isn't expecting that bar to be on when you click the button.

edwardtfn commented 3 months ago

Ah. Maybe an option to detach automation state from indicator would help.

You can not assign anything to the button, and use the Binary sensor related to the button as a trigger in an external automation.

MichaelHeimann commented 3 months ago

But this is incorrect fr8k the beginning. An automation isn't expecting that bar to be on when you click the button.

Well, why should the automation care? But OK. I'll workaround that.

Ah. Maybe an option to detach automation state from indicator would help.

You can not assign anything to the button, and use the Binary sensor related to the button as a trigger in an external automation.

Tried that - didn't work. With nothing assigned, the indicator wouldn't turn on.

But I found a way: I've created a input_boolean helper and assigned it to the hw-button in the blueprint. When I switch that one on of off, the indicator on the nspanel reflects that.

Summary:

Works for me. Still don't understand the indicator behavior when an automation is assigned. Is that documented somewhere? I couldn't find it.

edwardtfn commented 3 months ago

Well, why should the automation care? But OK. I'll workaround that.

That is like this since before I got in contact with this project, so I don’t know what it is like this, but they probably got a good reason and I don’t think they considered someone playing with the bars outside the project.

edwardtfn commented 3 months ago

So, why don’t you detail your use case so we can work in a solution and not just mitigating the symptoms. What is this automation? Why you need this controlled outside the blueprint? Why not assigning the group of lights directly to the button in the blueprint? How you determine the state of that button bar?

edwardtfn commented 3 months ago

not assigning any entity also disabled the indicator (not turning on with hw_button_state service)

This is probably quite easy to solve. 😂

MichaelHeimann commented 3 months ago

So, why don’t you detail your use case so we can work in a solution and not just mitigating the symptoms. What is this automation? Why you need this controlled outside the blueprint? Why not assigning the group of lights directly to the button in the blueprint? How you determine the state of that button bar?

The blueprint can assign an entity and switch it on or off, right? I need more: Use case1: I want to not only turn on but also specify dimming to 25% and light-temperature. If the values are changed in the app, the next time I want the defaults again and not what someone changed when the devices were on the last time.

Use case2: I use one button to "turn on" the radio which is turning the receiver on, setting input to net_radio and setting volume to 30%. The receiver is also used for tv/nvidia shield etc. so the panel should only show the indicator as on if the receiver is on and input is set to net_radio. The receiver can also be on with another inputs and then the button should do nothing - because of possible dependencies. When I watch a movie, the radio-button is off since the receiver is on but input is tv or nvidia shield. The button shall do nothing then since it would have to turn off the tv and maybe also some lights etc. There is not a single entity that reflects that state - it' simply a little more logic that needs to run when the button is pressed.

MichaelHeimann commented 3 months ago

Well, keep the button a button.

Enable detaching the indicator from the entity of the button.

edwardtfn commented 3 months ago

I've added this option in dev as an input in the blueprint, so no changes (no additional service = no additional memory) required on that side.