esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

shelly_dimmer doesn't set up without wifi #5225

Open harmptor opened 8 months ago

harmptor commented 8 months ago

The problem

Whenever my Shelly Dimmer 2 boots and cannot connect to WiFi, it seems to not set up the shelly_dimmer platform correctly. I have a lightswitch connected to GPIO14 and when the device boots while the wifi is turned off, hitting the switch doesn't toggle the light. (it does when there is a wifi connection at boot, obviously) I suspect it is because when setting up the component, it checks for the latest STM firmware and that fails without wifi. I think this should be fairly easy to reproduce, but if there's anything missing let me know :)

Which version of ESPHome has the issue?

2023.11.6

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP8266

Board

shelly dimmer 2

Component causing the issue

shelly_dimmer

Example YAML snippet

# output from `esphome config jimmy.yaml`:
light:
- platform: shelly_dimmer
  id: dimmer
  name: Jimmy
  internal: false
  restore_mode: RESTORE_DEFAULT_OFF
  default_transition_length: 500ms
  power:
    id: dimmer_power
    internal: true
    name: Jimmy Power
    entity_category: diagnostic
    state_class: ''
    disabled_by_default: true
    force_update: false
    unit_of_measurement: W
    accuracy_decimals: 1
    device_class: power
  voltage:
    id: dimmer_voltage
    internal: true
    name: Jimmy Voltage
    entity_category: diagnostic
    state_class: ''
    disabled_by_default: true
    force_update: false
    unit_of_measurement: V
    accuracy_decimals: 1
    device_class: voltage
  current:
    id: dimmer_current
    internal: true
    name: Jimmy Current
    entity_category: diagnostic
    state_class: ''
    disabled_by_default: true
    force_update: false
    unit_of_measurement: A
    accuracy_decimals: 2
    device_class: current
  leading_edge: false
  min_brightness: 160
  max_brightness: 1000
  gamma_correct: 2.8
  warmup_brightness: 0
  firmware:
    version: '51.5'
    update: false
    url: https://github.com/jamesturton/shelly-dimmer-stm32/releases/download/v51.5/shelly-dimmer-stm32_v51.5.bin
    sha256: 553fc1d78ed113227af7683eaa9c26189a961c4ea9a48000fb5aa8f8ac5d7b60
  disabled_by_default: false
  flash_transition_length: 0s
  nrst_pin:
    number: 5
    mode:
      output: true
      analog: false
      input: false
      open_drain: false
      pullup: false
      pulldown: false
    inverted: false
  boot0_pin:
    number: 4
    mode:
      output: true
      analog: false
      input: false
      open_drain: false
      pullup: false
      pulldown: false
    inverted: false
  update_interval: 10s

Anything in the logs that might be useful for us?

No response

Additional information

This discord thread is how I found out that it must be an issue with the shelly_dimmer component. https://discord.com/channels/429907082951524364/1184940799784394832

github-actions[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ssieb commented 4 months ago

The component priority is very low, below wifi, because it wants to be able to check for firmware updates. I think that needs to be reconsidered.

edge90 commented 1 day ago

TL;DR: The component will be marked as failed if update is set to false.

Following the flow of the light.py:

https://github.com/esphome/esphome/blob/e882cea47e76c50db674baf8dae0fa8744aabc4c/esphome/components/shelly_dimmer/shelly_dimmer.cpp#L81C8-L81C29

Means: if it doesn't have the firmware data, the component will be marked as failed.

https://github.com/esphome/esphome/blob/e882cea47e76c50db674baf8dae0fa8744aabc4c/esphome/components/shelly_dimmer/light.py#L190

Means: Only set the firmware data if the hex is not None.

https://github.com/esphome/esphome/blob/e882cea47e76c50db674baf8dae0fa8744aabc4c/esphome/components/shelly_dimmer/light.py#L78

Means: if update is set to false we will return None.

To solve this; the python code must forward that update to the c++ code / skip the update loop if the data is undefined.

Would be interesting to se what the following log line says on your setup "STM32 current firmware version: %d.%d, desired version: %d.%d".

Edit: Made some changes. Would be great if you could test them: https://github.com/esphome/esphome/pull/7407 You could also set update: true, boot everything once and then reset update to false.