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

`Bug` fan oscillate button not working #1873

Closed shing6326 closed 6 months ago

shing6326 commented 6 months ago

TFT Version

4.3dev4

ESPHome Version

4.3dev4

Blueprint Version

4.3dev4

Panel Model

EU

What is the bug?

fan oscillate button not working

Steps to Reproduce

  1. go to button page
  2. click the fan entity which has the oscillate function
  3. press the bt_oscillate
  4. the icon turns blue but no effect

I suspect the error may comes from esphome/nspanel_esphome_core.yaml line 880, the detailed_entity->state.c_str() returns the panel id instead of my fan's entity id. I tried to troubleshoot it but seems I do not have enough skills to fix it :).

            case 22:  // fan
              switch (component_id) {
                case 17:  // bt_oscillate
                  if (!touch_event) {  // Release
                    ha_call_service->execute("fan.oscillate", "", "", detailed_entity->state.c_str());
                  }
                  break;
              }
          }

Your Panel's YAML

substitutions:
  # Settings - Editable values
  device_name: "sg_panel"
  friendly_name: "SG Panel"
  wifi_ssid: !secret wifi_ssid
  wifi_password: !secret wifi_password
  api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  nextion_update_url: "https://raw.githubusercontent.com/Blackymas/NSPanel_HA_Blueprint/dev/advanced/hmi/nspanel_CJK_eu.tft"
  # Add-on configuration (if needed)
  # heater_relay: "1"  # Possible values: "1" or "2"

# Customization area
##### My customization - Start #####
api:
  encryption:
    key: ${api_key}

logger:

ota:
  password: !secret ota_password

wifi:
  use_address: 10.186.9.115

time:
  - id: !extend time_provider
    platform: sntp
    timezone: SGT-8

##### My customization - End #####

# Core and optional configurations
packages:
  remote_package:
    url: https://github.com/Blackymas/NSPanel_HA_Blueprint
    ref: dev
    files:
      - nspanel_esphome.yaml # Core package
      # Optional advanced and add-on configurations
      # - advanced/esphome/nspanel_esphome_advanced.yaml
      # - nspanel_esphome_addon_climate_cool.yaml
      # - nspanel_esphome_addon_climate_heat.yaml
      # - nspanel_esphome_addon_climate_dual.yaml
    refresh: 0s

esp32:
  framework:
    type: esp-idf

ESPHome Logs

no logs during the key press

Home Assistant Logs

Logger: homeassistant.components.automation.sg_nspanel
Source: components/automation/__init__.py:687
integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 1:54:32 AM (9 occurrences)
Last logged: 1:54:38 AM

Error while executing automation automation.sg_nspanel: required key not provided @ data['oscillating']

Logger: homeassistant.components.automation.sg_nspanel
Source: helpers/script.py:1805
integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 1:54:32 AM (36 occurrences)
Last logged: 1:54:38 AM

SG Panel: Main choices: NSPanel event: Choose at step 2: NSPanel service call: If at step 1: Error executing script. Invalid data for call_service at pos 1: required key not provided @ data['oscillating']
SG Panel: Main choices: NSPanel event: Choose at step 2: NSPanel service call: Error executing script. Invalid data for if at pos 1: required key not provided @ data['oscillating']
SG Panel: Main choices: NSPanel event: Error executing script. Invalid data for choose at pos 2: required key not provided @ data['oscillating']
SG Panel: Error executing script. Invalid data for choose at pos 2: required key not provided @ data['oscillating']
shing6326 commented 6 months ago

this is the attributes of my fan

preset_modes: 
oscillating: false
percentage: 25
percentage_step: 25
preset_mode: 
friendly_name: Lemo FW2 1c21ab 
supported_features: 3
edwardtfn commented 6 months ago

On the device's page under Settings > Devices & Services > ESPHome, there's a sensor named "Detailed Entity". What do you see on that sensor when the fan page is open with the entity where you want to control the oscillating?

Also, could you please, with that page open, go to Developer Tools, select the tab "Template" and paste the following, then let me know the results when the page fan is open with that same entity?

{% set entity_id = states("sensor.sg_panel_detailed_entity") %}
entity_id: {{ entity_id }}
oscillating: {{ state_attr(entity_id, "oscillating") }} / {{ state_attr(entity_id, "oscillating") | default("true") }}
new oscillating: {{ not (state_attr(entity_id, "oscillating") | default("true")) }}
shing6326 commented 6 months ago

hello @edwardtfn , thanks for helping, here is the result

SG Panel Detailed Entity:

fan.lemo_fw2_1c21ab_lemo_fw2_1c21ab

Template, when the oscillating is off

entity_id: fan.lemo_fw2_1c21ab_lemo_fw2_1c21ab
oscillating: False / False
new oscillating: True

when the oscillating is on

entity_id: fan.lemo_fw2_1c21ab_lemo_fw2_1c21ab
oscillating: True / True
new oscillating: False

actually the oscillating icon from fan page displays correctly with the state, just no response when clicking it.

edwardtfn commented 6 months ago

I couldn't find the error, but have changed a bit that service call and just pushed a new code to dev. Could you please update you blueprint and let me know if you still have that same issue (including that error on HA logs)? No need to update ESPHome or TFT, only the blueprint was changed for now, and it's version number haven't changed.

shing6326 commented 6 months ago

hi @edwardtfn, thanks for the help. I have tried the latest blueprint, and the error persists. 

Logger: homeassistant.components.automation.sg_nspanel
Source: components/automation/__init__.py:687
integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 9:48:09 PM (15 occurrences)
Last logged: 9:48:18 PM

Error while executing automation automation.sg_nspanel: required key not provided @ data['oscillating']
Logger: homeassistant.components.automation.sg_nspanel
Source: helpers/script.py:1805
integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 9:48:09 PM (60 occurrences)
Last logged: 9:48:18 PM

SG Panel: Main choices: NSPanel event: Choose at step 2: NSPanel service call: If at step 1: Error executing script. Invalid data for call_service at pos 1: required key not provided @ data['oscillating']
SG Panel: Main choices: NSPanel event: Choose at step 2: NSPanel service call: Error executing script. Invalid data for if at pos 1: required key not provided @ data['oscillating']
SG Panel: Main choices: NSPanel event: Error executing script. Invalid data for choose at pos 2: required key not provided @ data['oscillating']
SG Panel: Error executing script. Invalid data for choose at pos 2: required key not provided @ data['oscillating']

Logs from ESPHome when I entered to the fan page and press the oscillating button twice

[22:00:41][D][nextion_textsensor:014]: Processed text_sensor "localevent" state "{"page": "buttonpage01", "event": "long_click", "component": "button03"}"
[22:00:41][D][text_sensor:064]: 'Detailed Entity': Sending state 'fan.lemo_fw2_1c21ab_lemo_fw2_1c21ab'
[22:00:41][D][nextion:464]: Got new page: 22
[22:00:41][D][text_sensor:064]: 'Current Page': Sending state 'fan'
[22:00:41][D][script.page_changed:2129]: New page: fan
[22:00:41][D][script.page_changed:2131]: Entity shown: fan.lemo_fw2_1c21ab_lemo_fw2_1c21ab
[22:00:41][D][script:077]: Script 'timer_dim' restarting (mode: restart)
[22:00:41][D][script:077]: Script 'timer_sleep' restarting (mode: restart)
[22:00:41][D][sensor:094]: 'Page Id': Sending state 22.00000  with 0 decimals of accuracy
[22:00:43][D][nextion:446]: Got touch event:
[22:00:43][D][nextion:447]:   page_id:      22
[22:00:43][D][nextion:448]:   component_id: 17
[22:00:43][D][nextion:449]:   event type:   PRESS
[22:00:43][D][script:077]: Script 'timer_dim' restarting (mode: restart)
[22:00:43][D][script:077]: Script 'timer_sleep' restarting (mode: restart)
[22:00:43][D][nextion:446]: Got touch event:
[22:00:43][D][nextion:447]:   page_id:      22
[22:00:43][D][nextion:448]:   component_id: 17
[22:00:43][D][nextion:449]:   event type:   RELEASE
[22:00:43][D][script:077]: Script 'timer_dim' restarting (mode: restart)
[22:00:43][D][script:077]: Script 'timer_sleep' restarting (mode: restart)
[22:00:43][D][sensor:094]: 'Display Current brightness': Sending state 100.00000 % with 0 decimals of accuracy
[22:00:44][D][nextion:446]: Got touch event:
[22:00:44][D][nextion:447]:   page_id:      22
[22:00:44][D][nextion:448]:   component_id: 17
[22:00:44][D][nextion:449]:   event type:   PRESS
[22:00:44][D][script:077]: Script 'timer_dim' restarting (mode: restart)
[22:00:44][D][script:077]: Script 'timer_sleep' restarting (mode: restart)
[22:00:44][D][nextion:446]: Got touch event:
[22:00:44][D][nextion:447]:   page_id:      22
[22:00:44][D][nextion:448]:   component_id: 17
[22:00:44][D][nextion:449]:   event type:   RELEASE
[22:00:44][D][script:077]: Script 'timer_dim' restarting (mode: restart)
[22:00:44][D][script:077]: Script 'timer_sleep' restarting (mode: restart)
shing6326 commented 6 months ago

I tried to add some logs output but didn't get any messages.


diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml
index 30a0eab..7017ec2 100644
--- a/nspanel_blueprint.yaml
+++ b/nspanel_blueprint.yaml
@@ -7722,6 +7722,10 @@ action:
                             conditions:
                               - '{{ nspanel_event.service == "fan.oscillate" }}'
                             sequence:
+                              - service: system_log.write
+                                data:
+                                  message: "Fan oscillate automation triggered. Entity: {{ nspanel_event.entity }}, Service: {{ nspanel_event.service }}"
+                                  level: warning
                               - variables:
                                   oscillating: '{{ state_attr(nspanel_event.entity, "oscillating") | default(true) }}'
                               - service: fan.oscillate```
edwardtfn commented 6 months ago

Could you please try again with v4.3.0b2?

edwardtfn commented 6 months ago

I could finally duplicate the issue and I can see it persists with b2. Will work in a fix.

shing6326 commented 6 months ago

yes the issue still persists in b2

shing6326 commented 6 months ago

Thanks @edwardtfn , the commit fixes the issue, much appreciated.