Panamalar Plug Button not working

HI, I need help with the ESP Config for my Panamalar Plugs. I used the config template from here. But that did not work after translating it to the GPIO Values. Also GPIO config from here did not work. But after using the default sample from here at the page bottom most of the plug worked. I could switch the relay on and off, the LED worked, ok the second was to much. So I removed the other LED, renamed it and that was ok.

But I tried to add an automation to make the physical button work to switch the relay on/off by hand. But I can not get it working, tried every open GPIO but nothing worked. Maybe my automation is wrong?

Hope someone can help me get the button work.

Here is the ESP Config I use

substitutions:
  plug_name: energy_switch_01
  # Higher value gives lower watt readout
  current_res: "0.00221"
  # Lower value gives lower voltage readout
  voltage_div: "955"
esphome:
  name: ${plug_name}
  platform: ESP8266
  board: esp8285
wifi:
  ssid: 'my_ssid'
  password: 'wifi_password'
# Enable logging
logger:
# Enable Web server
web_server:
  port: 80
# Enable Home Assistant API
api:
  password: 'pass'
ota:
  password: 'pass'
time:
  - platform: homeassistant
    id: homeassistant_time
    
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO3
      inverted: True
    name: "${plug_name}_button"
    on_press:
      then:
        - switch.toggle: ${plug_name}_Relay_1
        - switch.toggle: ${plug_name}_LED_Pink
    
switch:
- platform: gpio
  name: "${plug_name}_Relay"
  pin: GPIO14
  restore_mode: ALWAYS_ON
  id: ${plug_name}_Relay_1
- platform: gpio
  name: "${plug_name}_LED_Pink"
  id: ${plug_name}_LED_Pink
  pin: GPIO13
  inverted: True
  restore_mode: ALWAYS_OFF
sensor:
  - platform: hlw8012
    sel_pin:
      number: GPIO12
      inverted: True
    cf_pin: GPIO04
    cf1_pin: GPIO05
    current_resistor: ${current_res}
    voltage_divider: ${voltage_div}
    current:
      name: "${plug_name}_Amperage"
      unit_of_measurement: A
    voltage:
      name: "${plug_name}_Voltage"
      unit_of_measurement: V
    power:
      name: "${plug_name}_Wattage"
      unit_of_measurement: W
      id: "${plug_name}_Wattage"
    change_mode_every: 8
    update_interval: 10s
  - platform: total_daily_energy
    name: "${plug_name}_Total Daily Energy"
    power_id: "${plug_name}_Wattage"
    filters:
        # Multiplication factor from W to kW is 0.001
        - multiply: 0.001
    unit_of_measurement: kWh
      
# Extra sensor to keep track of plug uptime
  - platform: uptime
    name: ${plug_name}_Uptime Sensor

Sorry but your explanations are very confusing :thinking: If you have found the good GPIO for the LED and the relay then it’s only an automation issue after ! Your logic for button is wrong, you should not use toggle like that ! I advise you to check cookbooks supplied on esphome as some of then are exactly your case :wink:

I think my automation is the problem but can not find the error :slight_smile:

Makes a simple one instead of using all these substitutions at first to check how it reacts :wink: When you say relay and button were working, do you mean you had status correctly updated in HA when changing their state ?
Side note: toggle for two circuits like you did won’t work well as if one of the switch is not in expected state you’ll get the two relays in opposite state :wink:

Only relay is working, button does nothing. Thats why I tough maybe the GPIO Config for button is wrong.

Oki but you go against what you said previously about GPIO config being sure and only problem was logic !! So please first check your GPIO is fully accurate then start on automation ! If you try to do everything together you’ll spend triple time to debug it !
Also use regular name instead of using substitution everywhere, it’ll make it a lot easier to debug at begin !

That is the problem I can not check. The info from the linked websites about this plug is both not correct. So I do not know if I really have the correct GPIO for the button. I am looking for someone with this Plug who can help me with the GPIO for the button. If you check the config in my first post you can see that the GPIO config is different then in the links where this button is posted. But everything work expect the button.

Wrong :wink: You can check if when you press button you see the change of state in HA :wink: till you find the correct GPIO ! If you had checked a little more on website you linked (wiki of Tasmosta firmware) you would have found all explanations needed to get all GPIO config of that device !! GitHub - arendst/Tasmota: Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at You would have been able then to discover that Button1 is on GPIO 13 !

Logger is your best friend debugging.
If you have a known working device, see how logging shows what you already know.
Anyway set logger level to debug, verbose or very_verbose, then when you press the button you should see some log about something happening, otherwise pin number is not correct.

According to the documentation the button is GPIO13.

And that is my problem, the documentation is wrong. If you check my config you see that GPIO 13 is used by LED. But LED should be a different GPIO.

Well then do some testing. Set up esphome to expose every GPIO as a button. Then observe which one reacts to the button press. Or do what @glmnet suggested and turn up your logging.

You are brave to say that online docs are incorrect when they are repeated in two places. Of course I do not discount the possibilty that the error might have carried through from one to the other.

Another possibility is that you do not actually have the same device, or that they have changed the device in a new release, but not told anyone (which is the same thing).

Ok know I did something wrong and broke it. I can no longer reach the plug over wifi. Any chance to fix it? Re upload a new firmware anyhow?