I had a template cover sensor:
cover:
- platform: template
name: "Garage Door"
lambda: |-
if (id(attached_garage_door).state) {
return COVER_OPEN;
} else {
return COVER_CLOSED;
}
open_action:
- switch.turn_on: attached_garage_switch
close_action:
- switch.turn_on: attached_garage_switch
stop_action:
- switch.turn_on: attached_garage_switch
optimistic: true
This wasn’t a great experience since I had 3 buttons that all got mapped to the single door switch and it was confusing. So I thought I’d try to simplify it to just have a switch. And it’s largely working and better than before with one glaring problem. When the esphome device starts it activates the garage door (opens if closed, closes if open) which did not happen with the cover:
switch:
- platform: gpio
pin:
number: D1
id: attached_garage_switch
name: "Door"
icon: "mdi:door"
on_turn_on:
- delay: 500ms
- switch.turn_off: attached_garage_switch
- platform: template
name: "Garage Door Template"
id: attached_garage_door_template
lambda: |-
if (id(attached_garage_door).state) {
id(attached_garage_door_template).set_icon("mdi:garage-open");
return true;
} else {
id(attached_garage_door_template).set_icon("mdi:garage");
return false;
}
turn_on_action:
- switch.turn_on: attached_garage_switch
turn_off_action:
- switch.turn_on: attached_garage_switch
optimistic: true
It seems that on startup for a template switch, the switch is being triggered by initializing it’s state?
Also I was trying to update the icon based on the garage door state, per another old post but that doesn’t work as described so looking for ideas on how to do that too.