Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing Ephome is prone to death #5789

Open
lozn00 opened this issue May 15, 2024 · 2 comments
Open

Writing Ephome is prone to death #5789

lozn00 opened this issue May 15, 2024 · 2 comments

Comments

@lozn00
Copy link

lozn00 commented May 15, 2024

The problem

It's very easy to die, which means I have to dismantle my socket. If I want to upgrade it in,
it needs to be soldered, The operation is very complicated
which is very painful for me. There are two reasons why it dies directly because I changed the configuration. The socket light is not on, nor does it display hotspot WiFi. There is also one light that is on, but I scanned the port and did not find that the web service was created. I hope there is a mechanism to prevent it from dying, otherwise it will be very painful for me. In addition, there is a mechanism that is newly flashed in, and I usually need WE. If it is not accessed for a long time for the first time, it will automatically restore to the initial state. I remember filling in the static IP, and then the IP and WiFi are not in the same network segment. How does it recognize conversions in this situation?

Which version of ESPHome has the issue?

2024.3.0

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2024.12.3

What platform are you using?

ESP8266

Board

other

Component causing the issue

misc

Example YAML snippet

globals:
  - id: global_counter
    type: int
    restore_value: yes
substitutions:
  name: "thinkswitch_company"
  friendly_name: "thinkswitch_company"
  plug_name: powerpc-v4-esp07
  use_address: 192.168.90.27
  wol_mac: E9:48:B8:CA:58:A1
esphome:
  name: "${name}"
  # Friendly names are used where appropriate in Home Assistant
  friendly_name: "${friendly_name}"
  name_add_mac_suffix: true
  platformio_options:
    board_build.ldscript: eagle.flash.2m.ld
    
  on_boot:
        priority: 600
        # ...
        then:
          - switch.turn_on: relay2
          - lambda: |-
              id(output_component12).set_level(0); 
              id(output_component14).set_level(0); 
              //id(GPIO12).turn_off();
              //id(GPIO14).turn_on();
  on_loop:
        then:
          - lambda: |-
                delay(5); 
                    if(id(relay2).state==0){
                     // id(output_component12).set_level(120); 
                      //id(output_component14).set_level(0);
                    }else{
                     // id(output_component12).set_level(120); 
                     // id(output_component14).set_level(0);
                    }
                    //delay(5);  // 延迟 1 秒
            
      # do something
esp8266:
  board: esp_wroom_02
  #flash_size: 2MB
  #esp01_1m esp102e nodemcuv2 esp01
mqtt:
  broker: "XXX.XXX.top" # 或者是 IP 地址
  port: 8126 #1883
  username: "XXX"
  password: "XXX"
  discovery: true # 开启自动发现功能,这样 ESPHome 设备会被自动添加到 Home Assistant 中

button:
  - platform: wake_on_lan
    name: "WakeHOMEPC"
    target_mac_address: 50:C2:E8:D3:B4:E3
  - platform: wake_on_lan
    name: "WoL1"
    target_mac_address: "${wol_mac}"
  - platform: template
    name: "Switch12LightOn"
    on_press:
      then:
        - logger.log: Button Pressed on
        - lambda: |-
              id(output_component12).set_level(0); 
  - platform: template
    name: "Switch12LightOff"
    on_press:
      then:
        - logger.log: Button Pressed off
        - lambda: |-
              id(output_component12).set_level(50); 

  - platform: template
    name: "Switch14LightOn"
    on_press:
      then:
        - logger.log: Button Pressed 14 on
        - lambda: |-
              id(output_component14).set_level(0); 
  - platform: template
    name: "Switch14LightOff"
    on_press:
      then:
        - logger.log: Button Pressed 14 off
        - lambda: |-
              id(output_component14).set_level(50); 

logger:

# Enable Home Assistant API
api:
  encryption:
    key: "dAEK8OdJYfoJpsijDep8J9MQWofRsRs7KSZ8w16v2F4="

ota:
  password: "8dece5d42a7deea70d6ff20f1071d83e"

wifi:
  networks:

  - ssid: LOZN_PAY
    password: "XXX"
  on_connect:
    - switch.turn_on: relay2
    - logger.log: WiFi is connected!
    - lambda: |-
         id(output_component14).set_level(50); 
  on_disconnect:
    - switch.turn_on: relay2
    - lambda: |-
        id(output_component14).set_level(0); 


    
  # manual_ip:
  #   static_ip: 192.168.1.125
  #   gateway: 192.168.1.1
  #   subnet: 255.255.255.0
  #   dns1: 192.168.1.1
  #   dns2: 8.8.8.8
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "LOZN Hotspot"
    password: "35068264"
    
web_server:                                          ## 这个是web控制,添加了这2行,就可以打开设备iweb页面
  port: 80
  auth:
    username: "lozn"
    password: "lozn"

                              ## inverted 参数,表示低电平有效,即继电器是低电平触发
#int kg=5;//继电器输出
#int de=12;//灯输出 14 0 2
#int key=4 ;//按键 


captive_portal:

switch:
  - platform: gpio
    pin: GPIO5
    name: "switch"
    id: relay2
    inverted: False

  # - platform: gpio
  #   pin: GPIO12
  #   name: "GPIO12blue"
  #   id: GPIO12
  #   inverted: True
  # - platform: gpio
  #   pin: GPIO14
  #   name: "GPIO14red"
  #   id: GPIO14
  #   inverted: True

output:
  - platform: esp8266_pwm
    id: output_component14
    pin: GPIO14          
  - platform: esp8266_pwm
    id: output_component12
    pin: GPIO12 
interval:
  - interval: 1s
    then:
text_sensor:
  - platform: wifi_info
    ip_address:
      name: IP
    ssid:
      name: SID
    bssid:
      name: SSID
    mac_address:
      name: Mac


binary_sensor:
  - platform: gpio
    pin: GPIO4
    name: "press_switch_lib1"
    device_class: opening
    
   # on_release  on_press on_click on_double_click on_multi_click  #  id(output_component12).set_level(0); blue light on  #      id(output_component14).set_level(50); red light off
    on_release: 
      then:
        - switch.toggle: relay2
        - lambda: |-
            int counter_value = id(global_counter);
            ESP_LOGD("custom", "Counter Value: %d", counter_value);
            static int state = 0;
            auto switchstatus = id(relay2).state;
            ESP_LOGW("custom", "STATUS %s", switchstatus==0?"low":"high");
            if (switchstatus == 1) {
              id(output_component12).set_level(0);
              id(output_component14).set_level(50);
              ESP_LOGW("custom", "open light");
            } else if (switchstatus == 0) {
              id(output_component12).set_level(50); 
              id(output_component14).set_level(0); 
              ESP_LOGW("custom", "close light");
            } 
    
    filters:
      - delayed_on: 100ms


### Anything in the logs that might be useful for us?

_No response_

### Additional information

_No response_
@lozn00
Copy link
Author

lozn00 commented May 15, 2024

There are currently two types of crashes,

  1. Unable to upgrade firmware through web, unable to light up, unable to control socket adapter by pressing switch
  2. There is also a situation where it is not dead, but the web cannot be opened, pressing the switch adapter button responds, and there is no connection to WiFi (since it is not in the company, it cannot be determined whether it is connected). After scanning the IP port, it was found that there is indeed no connection. In this case, I may switch to a location where I cannot connect to WiFi and it will generate a hotspot, and then I can upgrade.

I hope there is a mechanism to prevent complete death,
For example, if there is a Forced power outage and restart three times within one minute, it will default and generate a hotspot for me to connect to Esphome. The generated hotspot will facilitate me to upgrade to OTA and fix the problem.
Also, is it possible that there was no try catch exception within the system, and some code errors caused the web functionality to malfunction.

@lozn00
Copy link
Author

lozn00 commented May 15, 2024

Can a long press continuous click mode be added to a pin port to trigger a reset function.
However, what is currently more painful than the problem is that it died after burning and underwent a web upgrade. Then, I heard the sound of the relay closing, the light went out, and pressing the button did not respond. I unplugged the socket and reinserted it, and it completely died. I bought 5 sockets, but currently 3 of them are broken due to configuration changes. I need to spend some time dismantling them and re flashing them in through the data cable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant