Hi struggling to get this code correct, so any pointers would be gratefully received.
Im trying to get standard household toggle wall switches to appear in home assistant as a switch so the can be controlled in automations switch scenes, or just be standard light switches etc. The switches do not have any lights attached physically and are wired to d1 mini pin and back to ground pin.
i don’t mind which what the toggle is so happy that state change toggles the HA switch.
I have it set up as a binary sensor but the doesn’t let me switch it in HA frontend. So i’m trying to get it to switch a template switch and make the binary sensor internal.
This is where i have got to;
esphome:
name: lsc2
on_boot:
priority: 600
then:
- binary_sensor.template.publish:
id: template_sw1
state: ON
- binary_sensor.template.publish:
id: template_sw2
state: OFF
esp8266:
board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "t################="
ota:
password: "#####################"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Lsc2 Fallback Hotspot"
password: "##############"
captive_portal:
# Physical wall switch sensor automation
binary_sensor:
- platform: gpio
pin:
number: 5
mode: INPUT_PULLUP
name: Wall Switch 1
id: wallswitch1
internal: true
filters:
- delayed_on: 10ms
- delayed_off: 10ms
#Automation
on_state:
then:
- lambda: |-
lambda: 'return id(template_sw1).state;'
then:
- switch.template.publish:
id: template_sw1
state: OFF
else:
- switch.template.publish:
id: template_sw1
state: ON
# Virtual switches
- platform: template
name: "left bed switch 1"
id: template_sw1
- platform: template
name: "left bed switch 2"
id: template_sw2