ESPHOME switch template unexpected off

604 / 5000

Risultati della traduzione

Hi everyone I have a problem that I have been trying to solve for a while and understand where I am wrong but without solution I have an ESP32 programmed with ESPHOME.
On it I have a dallas temperature sensor that opens a vasistas window more or less depending on the temperature. I’m trying to create a switch for the “Manual” command if turned on, the script with the function of opening or closing does not work.
Everything works except the simple “virtual” switch my template switch is this

switch:
#------------------- VASISTAS MANUALE -----------
  - platform: template
    name: Vasistas Manuale
    id: cover_vasistas_manual
    disabled_by_default: false
    optimistic: false
    assumed_state: false
    restore_state: true

in HA, once turned on, it switches off automatically after about 1 sec and an off message does not appear in the log:
switch activation

[21:53:25][D][switch:021]: 'Vasistas Manuale' Turning ON.

unexpected switch deactivation without exit log

Shouldn’t this be:

restore_state: yes

“yes” is equal to “true” indifferent, but I tested by term
without having a solution

Hi, did you find the issue or solution? Thanks

forget it, this was my issue

optimistic: true

Hi, yes I found how to make it work, I’ve been using it for a long time and it’s ultra stable.
The bug is found in the publication of the change of state which, unlike other buttons etc in the case of the switch, is published at the end, but in our case it does not allow maintaining the position.
I fixed it by posting manually right away

  - platform: template
    id: cover_vasistas_manual
    name: Vasistas Manuale
    turn_on_action:
      - switch.template.publish: 
          id: cover_vasistas_manual
          state: ON
      - cover.stop: cover_vasistas
      - ............
    turn_off_action:
      - switch.template.publish: 
          id: cover_vasistas_manual
          state: OFF
      - ............
    icon: "mdi:gesture-swipe"
    optimistic: false
2 Likes