lubeda / EspHoMaTriXv2

A simple DIY status display with a 8x32 RGB LED matrix, implemented with esphome.io and Home Assistant.
MIT License
277 stars 25 forks source link

[BUG] del_screen with wildcard not working #42

Closed jdohnstad closed 1 year ago

jdohnstad commented 1 year ago

Bug report

Describe the bug

When calling the del_screen service through home assistant with a icon_name wildcard (i.e. weather_*) it doesn't actually delete any screens. When calling the same service with a fully specified icon_name, screen (i.e. weather_partlycloudy is deleted as expected.

Additional information

To Reproduce

Configure an icon such as weather_partlycloudy. Add an icon_screen to the queue with with esphome.<DEVICENAME>_icon_screen service. Attempt to delete it via the esphome.<DEVICENAME>_del_screen service using a wildcard that should match such as weather_*.

  - service: esphome.ulanzi_icon_screen
    data:
      icon_name: weather_partlycloudy
      text: some text
      default_font: true
      lifetime: 180
      screen_time: 2
      r: 255
      g: 255
      b: 255
    enabled: true
  - service: esphome.ulanzi_del_screen
    data:
      icon_name: weather_*
      mode: 5

Expected behavior

Screen should be removed from queue.

Configuration

Full esphome.yaml ```yaml --- wifi: ssid: !secret wifi_ssid password: !secret wifi_password manual_ip: static_ip: 10.0.0.227 gateway: !secret gateway subnet: !secret subnet ap: ssid: "$devicename Fallback Hotspot" password: !secret ap_password captive_portal: logger: ota: password: !secret ota_password substitutions: devicename: ulanzi matrix_pin: GPIO32 buzzer_pin: GPIO15 battery_pin: GPIO34 ldr_pin: GPIO35 left_button_pin: GPIO26 mid_button_pin: GPIO27 right_button_pin: GPIO14 scl_pin: GPIO22 sda_pin: GPIO21 external_components: - source: type: git url: https://github.com/lubeda/EspHoMaTriXv2 ref: "2023.6.4" components: [ehmtxv2] esphome: comment: "EHMTXv2 from LuBeDa" name: $devicename on_boot: then: - ds1307.read_time: switch: - platform: template name: "Auto-Adjust Brightness" id: switch_autobrightness icon: mdi:brightness-auto restore_mode: RESTORE_DEFAULT_ON lambda: |- if (id(aab_enable)) { return true; } else { return false; } turn_on_action: lambda: |- id(aab_enable) = true; turn_off_action: lambda: |- id(aab_enable) = false; - platform: template name: "$devicename Display" icon: "mdi:power" restore_mode: ALWAYS_ON lambda: |- return id(rgb8x32)->show_display; turn_on_action: lambda: |- id(rgb8x32)->set_display_on(); turn_off_action: lambda: |- id(rgb8x32)->set_display_off(); globals: # aab = auto-adjustable brightness - id: aab_enable type: "bool" restore_value: true initial_value: "true" - id: aab_add type: int initial_value: '10' - id: aab_max type: int initial_value: '220' - id: aab_min type: int initial_value: '20' output: - platform: ledc pin: $buzzer_pin id: rtttl_out rtttl: output: rtttl_out esp32: board: esp32dev font: - file: fonts/EHMTXv2.ttf size: 16 id: default_font glyphs: | !?"%()+*=,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnÖÄÜöäüopqrstuvwxyz@<>ߧ€/ binary_sensor: - platform: status name: "$devicename Status" - platform: gpio pin: number: $left_button_pin inverted: true name: "Left button" - platform: gpio pin: inverted: true number: $mid_button_pin mode: INPUT_PULLUP name: "Middle button" - platform: gpio pin: number: $right_button_pin inverted: true name: "Right button" number: - platform: template name: "$devicename Brightness" min_value: 0 max_value: 255 step: 1 lambda: |- return id(rgb8x32)->get_brightness(); set_action: lambda: |- id(rgb8x32)->set_brightness(x); api: encryption: key: !secret encryption_key services: - service: tune variables: tune: string then: - rtttl.play: rtttl: !lambda 'return tune;' sensor: - platform: sht3xd temperature: name: "$devicename Temperature" humidity: name: "$devicename Relative Humidity" update_interval: 60s - platform: adc pin: $battery_pin name: "$devicename Battery" id: battery_voltage update_interval: 10s device_class: battery accuracy_decimals: 0 attenuation: auto filters: - sliding_window_moving_average: window_size: 15 send_every: 15 send_first_at: 1 - multiply: 1.6 - lambda: |- auto r = ((x - 3) / 0.69 * 100.00); if (r >= 100) return 100; if (r > 0) return r; if (r <= 0) return 1; return 0; unit_of_measurement: '%' - platform: adc id: light_sensor name: "$devicename Illuminance" pin: $ldr_pin update_interval: 10s attenuation: auto unit_of_measurement: lx device_class: illuminance accuracy_decimals: 0 filters: - lambda: |- return (x / 10000.0) * 2000000.0 - 15 ; on_value: then: - lambda: |- if ( id(aab_enable) ) { int n = x / 4 + id(aab_add); // new_value if (n > id(aab_max)) n = id(aab_max); if (n < id(aab_min)) n = id(aab_min); int c = id(rgb8x32)->get_brightness(); // current value c = c>0?c:1 ; int d = (n - c) * 100 / c; // diff in % if ( abs(d) > 2 ) id(rgb8x32)->set_brightness(n); } i2c: sda: $sda_pin scl: $scl_pin scan: true id: i2cbus light: - platform: neopixelbus id: ehmtx_light type: GRB internal: true variant: WS2812 pin: $matrix_pin num_leds: 256 color_correct: [30%, 30%, 30%] gamma_correct: 2.0 name: "$devicename Light" restore_mode: ALWAYS_OFF time: - platform: homeassistant timezone: !secret timezone on_time_sync: then: ds1307.write_time: - platform: ds1307 timezone: !secret timezone update_interval: never id: ehmtx_time display: - platform: addressable_light id: ehmtx_display addressable_light_id: ehmtx_light width: 32 height: 8 pixel_mapper: |- if (y % 2 == 0) { return (y * 32) + x; } return (y * 32) + (31 - x); rotation: 0° update_interval: 16ms auto_clear_enabled: true lambda: |- id(rgb8x32)->tick(); id(rgb8x32)->draw(); ehmtxv2: id: rgb8x32 icons2html: true matrix_component: ehmtx_display time_component: ehmtx_time time_format: "%I:%M" date_format: "%m.%d" show_seconds: false default_font_id: default_font special_font_id: default_font icons: - id: home_assistant file: icons/47693_home_assistant.gif - id: error file: icons/40530_error.gif - id: temperature file: icons/2056_temp.png # https://developers.home-assistant.io/docs/core/entity/weather/#recommended-values-for-state-and-condition - id: weather_cloudy file: icons/52159_cloudy.png - id: weather_partlycloudy file: icons/52173_partly_cloudy.png - id: weather_fog file: icons/52167_fog.png - id: weather_sunny file: icons/52156_sunny.png - id: weather_rainy file: icons/52160_rainy.png - id: weather_snowy file: icons/52168_snowy.png - id: weather_hail file: icons/52158_hail.png - id: weather_clear_night file: icons/52163_clear_night.png - id: weather_pouring file: icons/52161_pouring.png - id: weather_snowy_rainy file: icons/52166_snowy_rainy.png - id: weather_windy file: icons/52169_windy.png - id: weather_windy_variant file: icons/52169_windy.png - id: weather_lightning file: icons/52170_lightning.png - id: weather_lightning_rainy file: icons/52171_lightning_rainy.png - id: weather_exceptional file: icons/52172_weather_warning.png on_next_screen: - homeassistant.event: event: esphome.new_screen data_template: iconname: !lambda "return icon.c_str();" text: !lambda "return text.c_str();" ```
Full Home Assistant Automation yaml ```yaml alias: Ulanzi Weather description: Ulanzi clock weather trigger: - platform: state entity_id: - sensor.openweathermap_condition - platform: state entity_id: - sensor.openweathermap_temperature condition: [] action: - service: esphome.ulanzi_del_screen data: icon_name: weather_* mode: 5 - service: esphome.ulanzi_icon_screen data: icon_name: >- weather_{{ states('sensor.openweathermap_condition') | replace('-', '_')}} text: >- {{ states('sensor.openweathermap_temperature', rounded=True, with_unit=True) }} default_font: true lifetime: 180 screen_time: 2 r: 255 g: 255 b: 255 enabled: true mode: single ```

Screenshots

If applicable, add screenshots to help explain your problem.

Logs

Esphome Logs ```text INFO ESPHome 2023.5.5 INFO Reading configuration ulanzi.yaml... WARNING WARNING Please check the documentation and wiki https://github.com/lubeda/EspHoMaTriXv2 WARNING WARNING GPIO15 is a Strapping PIN and should be avoided. Attaching external pullup/down resistors to strapping pins can cause unexpected failures. See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins INFO Starting log output from 10.0.0.227 using esphome API INFO Successfully connected to 10.0.0.227 [02:44:45][I][app:102]: ESPHome version 2023.5.5 compiled on Jun 14 2023, 02:36:05 [02:44:45][C][wifi:505]: WiFi: [02:44:45][C][wifi:363]: Local MAC: XX [02:44:45][C][wifi:364]: SSID: 'iot' [02:44:45][C][wifi:365]: IP Address: 10.0.0.227 [02:44:45][C][wifi:367]: BSSID: XXX [02:44:45][C][wifi:368]: Hostname: 'ulanzi' [02:44:45][C][wifi:370]: Signal strength: -65 dB ▂▄▆█ [02:44:45][C][wifi:374]: Channel: 11 [02:44:45][C][wifi:375]: Subnet: 255.255.255.0 [02:44:45][C][wifi:376]: Gateway: 10.0.0.1 [02:44:45][C][wifi:377]: DNS1: 0.0.0.0 [02:44:45][C][wifi:378]: DNS2: 0.0.0.0 [02:44:45][C][logger:301]: Logger: [02:44:45][C][logger:302]: Level: DEBUG [02:44:45][C][logger:303]: Log Baud Rate: 115200 [02:44:45][C][logger:305]: Hardware UART: UART0 [02:44:45][C][i2c.arduino:053]: I2C Bus: [02:44:45][C][i2c.arduino:054]: SDA Pin: GPIO21 [02:44:45][C][i2c.arduino:055]: SCL Pin: GPIO22 [02:44:45][C][i2c.arduino:056]: Frequency: 50000 Hz [02:44:45][C][i2c.arduino:059]: Recovery: bus successfully recovered [02:44:45][I][i2c.arduino:069]: Results from i2c bus scan: [02:44:45][I][i2c.arduino:075]: Found i2c device at address 0x44 [02:44:45][I][i2c.arduino:075]: Found i2c device at address 0x68 [02:44:45][C][template.switch:068]: Template Switch 'Auto-Adjust Brightness' [02:44:45][C][template.switch:070]: Icon: 'mdi:brightness-auto' [02:44:45][C][template.switch:091]: Restore Mode: restore defaults to ON [02:44:45][C][template.switch:060]: Restore State: NO [02:44:45][C][template.switch:061]: Optimistic: NO [02:44:45][C][template.switch:068]: Template Switch 'ulanzi Display' [02:44:45][C][template.switch:070]: Icon: 'mdi:power' [02:44:45][C][template.switch:091]: Restore Mode: always ON [02:44:45][C][template.switch:060]: Restore State: NO [02:44:45][C][template.switch:061]: Optimistic: NO [02:44:45][C][ledc.output:160]: LEDC Output: [02:44:45][C][ledc.output:161]: Pin GPIO15 [02:44:45][C][ledc.output:162]: LEDC Channel: 0 [02:44:45][C][ledc.output:163]: PWM Frequency: 1000.0 Hz [02:44:45][C][ledc.output:164]: Bit depth: 16 [02:44:45][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Left button' [02:44:45][C][gpio.binary_sensor:016]: Pin: GPIO26 [02:44:45][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Middle button' [02:44:45][C][gpio.binary_sensor:016]: Pin: GPIO27 [02:44:45][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Right button' [02:44:45][C][gpio.binary_sensor:016]: Pin: GPIO14 [02:44:45][C][template.number:050]: Template Number 'ulanzi Brightness' [02:44:45][C][template.number:051]: Optimistic: NO [02:44:45][C][template.number:052]: Update Interval: 60.0s [02:44:46][C][light:103]: Light 'ulanzi Light' [02:44:46][C][light:105]: Default Transition Length: 1.0s [02:44:46][C][light:106]: Gamma Correct: 2.00 [02:44:46][C][rtttl:018]: Rtttl [02:44:46][C][status:034]: Status Binary Sensor 'ulanzi Status' [02:44:46][C][status:034]: Device Class: 'connectivity' [02:44:46][C][sht3xd:029]: SHT3xD: [02:44:46][C][sht3xd:030]: Address: 0x44 [02:44:46][C][sht3xd:034]: Update Interval: 60.0s [02:44:46][C][sht3xd:036]: Temperature 'ulanzi Temperature' [02:44:46][C][sht3xd:036]: Device Class: 'temperature' [02:44:46][C][sht3xd:036]: State Class: 'measurement' [02:44:46][C][sht3xd:036]: Unit of Measurement: '°C' [02:44:46][C][sht3xd:036]: Accuracy Decimals: 1 [02:44:46][C][sht3xd:037]: Humidity 'ulanzi Relative Humidity' [02:44:46][C][sht3xd:037]: Device Class: 'humidity' [02:44:46][C][sht3xd:037]: State Class: 'measurement' [02:44:46][C][sht3xd:037]: Unit of Measurement: '%' [02:44:46][C][sht3xd:037]: Accuracy Decimals: 1 [02:44:46][C][adc:087]: ADC Sensor 'ulanzi Battery' [02:44:46][C][adc:087]: Device Class: 'battery' [02:44:46][C][adc:087]: State Class: 'measurement' [02:44:46][C][adc:087]: Unit of Measurement: '%' [02:44:46][C][adc:087]: Accuracy Decimals: 0 [02:44:46][C][adc:097]: Pin: GPIO34 [02:44:46][C][adc:099]: Attenuation: auto [02:44:46][C][adc:126]: Update Interval: 10.0s [02:44:46][C][adc:087]: ADC Sensor 'ulanzi Illuminance' [02:44:46][C][adc:087]: Device Class: 'illuminance' [02:44:46][C][adc:087]: State Class: 'measurement' [02:44:46][C][adc:087]: Unit of Measurement: 'lx' [02:44:46][C][adc:087]: Accuracy Decimals: 0 [02:44:46][C][adc:097]: Pin: GPIO35 [02:44:46][C][adc:099]: Attenuation: auto [02:44:46][C][adc:126]: Update Interval: 10.0s [02:44:46][C][ds1307:022]: DS1307: [02:44:46][C][ds1307:023]: Address: 0x68 [02:44:46][C][ds1307:027]: Timezone: 'CST6CDT,M3.2.0,M11.1.0' [02:44:46][C][homeassistant.time:010]: Home Assistant Time: [02:44:46][C][homeassistant.time:011]: Timezone: 'CST6CDT,M3.2.0,M11.1.0' [02:44:46][C][captive_portal:088]: Captive Portal: [02:44:46][C][mdns:108]: mDNS: [02:44:46][C][mdns:109]: Hostname: ulanzi [02:44:46][C][ota:093]: Over-The-Air Updates: [02:44:46][C][ota:094]: Address: 10.0.0.227:3232 [02:44:46][C][ota:097]: Using Password. [02:44:46][C][api:138]: API Server: [02:44:46][C][api:139]: Address: 10.0.0.227:6053 [02:44:46][C][api:141]: Using noise encryption: YES [02:44:46][C][EHMTXv2:953]: EspHoMatriXv2 version: 2023.6.4 [02:44:46][C][EHMTXv2:954]: Icons: 18 of 90 [02:44:46][C][EHMTXv2:955]: Clock interval: 0 s [02:44:46][C][EHMTXv2:956]: Date format: %m.%d [02:44:46][C][EHMTXv2:957]: Time format: %I:%M [02:44:46][C][EHMTXv2:958]: Interval (ms) scroll: 80 [02:44:46][C][EHMTXv2:961]: show day of week [02:44:46][C][EHMTXv2:965]: show date [02:44:46][C][EHMTXv2:972]: weekstart: monday [02:44:54][D][EHMTXv2:033]: queue: date for: 5 sec [02:44:55][D][sensor:094]: 'ulanzi Illuminance': Sending state 231.68910 lx with 0 decimals of accuracy [02:45:00][D][EHMTXv2:030]: queue: clock for: 10 sec [02:45:05][D][sensor:094]: 'ulanzi Illuminance': Sending state 231.90056 lx with 0 decimals of accuracy [02:45:11][D][EHMTXv2:033]: queue: date for: 5 sec [02:45:14][D][number:012]: 'ulanzi Brightness': Sending state 67.000000 [02:45:15][D][sensor:094]: 'ulanzi Illuminance': Sending state 231.72728 lx with 0 decimals of accuracy [02:45:15][D][sht3xd:060]: Got temperature=29.88°C humidity=33.18% [02:45:15][D][sensor:094]: 'ulanzi Temperature': Sending state 29.88136 °C with 1 decimals of accuracy [02:45:15][D][sensor:094]: 'ulanzi Relative Humidity': Sending state 33.17922 % with 1 decimals of accuracy [02:45:17][D][EHMTXv2:030]: queue: clock for: 10 sec [02:45:19][D][EHMTXv2:206]: icon: weather_partlycloudy found id: 4 [02:45:19][D][EHMTXv2:851]: free_screen: found by endtime 0 [02:45:19][D][EHMTXv2:378]: calc_scroll_time: mode: 5 text: "some text" pixels 32 calculated: 10 defined: 2 max_steps: 56 [02:45:19][D][EHMTXv2:672]: icon screen icon: 4 iconname: weather_partlycloudy text: some text lifetime: 180 screen_time: 2 [02:45:19][D][EHMTXv2:039]: queue: icon screen: "weather_partlycloudy" text: some text for: 10 sec [02:45:25][D][sensor:094]: 'ulanzi Illuminance': Sending state 231.98325 lx with 0 decimals of accuracy [02:45:28][D][EHMTXv2:039]: queue: icon screen: "weather_partlycloudy" text: some text for: 10 sec [02:45:35][D][sensor:094]: 'ulanzi Illuminance': Sending state 232.50621 lx with 0 decimals of accuracy [02:45:39][D][EHMTXv2:033]: queue: date for: 5 sec [02:45:40][W][EHMTXv2:623]: del_screen: icon weather_* in position: 0 mode 5 [02:45:45][D][sensor:094]: 'ulanzi Illuminance': Sending state 231.39478 lx with 0 decimals of accuracy [02:45:45][D][EHMTXv2:030]: queue: clock for: 10 sec [02:45:55][D][sensor:094]: 'ulanzi Illuminance': Sending state 234.53830 lx with 0 decimals of accuracy [02:45:56][D][EHMTXv2:039]: queue: icon screen: "weather_partlycloudy" text: some text for: 10 sec [02:46:05][D][sensor:094]: 'ulanzi Illuminance': Sending state 232.25241 lx with 0 decimals of accuracy [02:46:07][D][EHMTXv2:033]: queue: date for: 5 sec [02:46:08][W][EHMTXv2:623]: del_screen: icon weather_partlycloudy in position: 0 mode 5 [02:46:08][W][EHMTXv2:633]: del_screen: force [02:46:13][D][EHMTXv2:030]: queue: clock for: 10 sec [02:46:14][D][number:012]: 'ulanzi Brightness': Sending state 67.000000 [02:46:15][D][sensor:094]: 'ulanzi Illuminance': Sending state 232.16005 lx with 0 decimals of accuracy [02:46:15][D][sht3xd:060]: Got temperature=29.94°C humidity=33.07% [02:46:15][D][sensor:094]: 'ulanzi Temperature': Sending state 29.93744 °C with 1 decimals of accuracy [02:46:15][D][sensor:094]: 'ulanzi Relative Humidity': Sending state 33.06630 % with 1 decimals of accuracy [02:46:24][D][EHMTXv2:033]: queue: date for: 5 sec [02:46:25][D][sensor:094]: 'ulanzi Illuminance': Sending state 231.83841 lx with 0 decimals of accuracy ```

Services calls

These correspond to the logs above:

- service: esphome.ulanzi_icon_screen
  data:
    icon_name: weather_partlycloudy
    text: some text
    default_font: true
    lifetime: 180
    screen_time: 2
    r: 255
    g: 255
    b: 255

# observe "weather_partlycloudy" screen has been added

- service: esphome.ulanzi_del_screen
  data:
    icon_name: weather_*
    mode: 5 

# observe "weather_partlycloudy" screen has not been deleted

- service: esphome.ulanzi_del_screen
  data:
    icon_name: weather_partlycloudy
    mode: 5

# observe "weather_partlycloudy" screen has finally been deleted
lubeda commented 1 year ago

I will check

lubeda commented 1 year ago

Fixed in the "develop" branch

jdohnstad commented 1 year ago

I can confirm. Nice job!