#This ESPHome plug.yaml file configures the ESP8266 TYWE2S boards inside ARLEC Grid Connect Smartplugs #The smartplug has a pressbutton switch (GPIO14), red LED (GPIO13), blue LED (GPIO04) and a relay (GPIO12) #A flashing red LED is used to indicate a network or MQTT problem or when booting #A solid blue LED is used to indicate that the relay is on #No LEDs are illuminated when there is no problem and the relay is off #It publishes and subscribes to MQTT topics over the WiFi network via the MQTT broker on the Home Automation System. #It publishes MQTT topics "p0" to "p5" and subscribes to MQTT topics "s0" to "s5" for 5 power zones respectively. #The published MQTT messages are "on" and "off". #The subscribed MQTT message "state" will trigger a published response. #The subscribed MQTT message "toggle" will toggle the relay and trigger a published response. #To upload set the zone and IP address: esphome -s zone 0 -s ip_address 192.168.2.6 run plug.yaml #To upload set the zone and IP address: esphome -s zone 1 -s ip_address 192.168.2.7 run plug.yaml #To upload set the zone and IP address: esphome -s zone 2 -s ip_address 192.168.2.8 run plug.yaml #To upload set the zone and IP address: esphome -s zone 3 -s ip_address 192.168.2.9 run plug.yaml #Set up constants substitutions: #Uncomment the name and ip_address of the Smart Plug to be programmed or use the command line -s directive zone: '0' #PC Smartplug ip_address: '192.168.2.6' # zone: '1' #Radio Smartplug # ip_address: '192.168.2.7' # zone: '2' #Kettle Smartplug # ip_address: '192.168.2.8' # zone: '3' #Cars Smartplug # ip_address: '192.168.2.9' name: 'plug${zone}' from_server: 'p${zone}' #The topic for receiving messages from the server to_server: 's${zone}' #The topic for sending messages to the server on_message: '1' off_message: '0' toggle_message: 'x' state_message: '?' #Set up core functionality esphome: name: ${name} #The name of this device compile_process_limit: 2 #Reduce the number of cores to use. Necessary for RPi 3 #Set up processor and board esp8266: #Use the ESP8266 platform board: esp01_1m #The Black ESP-01 board with 1MB of ram #Set up WiFi wifi: ssid: A #This network is isolated from the Internet, but has an MQTT broker password: manual_ip: static_ip: ${ip_address} gateway: 192.168.2.1 subnet: 255.255.255.0 #Enable a fallback access point in case the WiFi connection fails ap: ssid: ${name} #Use the device name as the SSID #Enable the captive portal for the WiFi access point captive_portal: #Enable logging logger: logs: mqtt.component: DEBUG #Enable programming Over The Air ota: - platform: esphome #Enable Message Queuing Telemetry Transport mqtt: broker: 192.168.2.2 #The IP Address of the MQTT broker port: 1883 #The port number of the MQTT broker on_message: #When a message is received from the MQTT broker - topic: ${from_server} #When a message is received from the server payload: ${on_message} #When an on message is received then: switch.turn_on: relay #Turn on the relay - topic: ${from_server} #When a message is received from the server payload: ${off_message} #When an off message is received then: switch.turn_off: relay #Turn off the relay - topic: ${from_server} #When a message is received from the server payload: ${toggle_message} #When a toggle message is received then: switch.toggle: relay #Togggle the relay - topic: ${from_server} #When a message is received from the server publishing topic payload: ${state_message} #When a state message is received then: mqtt.publish: #Publish an MQTT message topic: ${to_server} #Publish the input state to the server payload: !lambda |- return to_string(id(relay).state); status_led: #Use a status LED component to flash the red LED until WiFi and MQTT are working pin: number: GPIO13 inverted: True binary_sensor: #Use a binary sensor component for the press-button switch - platform: gpio id: pressbutton pin: number: GPIO14 inverted: True mode: INPUT_PULLUP filters: delayed_on_off: 100ms #Delay the on and off events for 100ms to debounce the switch on_press: then: - switch.toggle: relay #Toggle the relay on and off whenever the switch is pressed output: - platform: gpio #The blue LED is used to indicate that the power in on id: blue_led pin: number: GPIO04 inverted: True switch: - platform: gpio id: relay restore_mode: always off pin: number: GPIO12 inverted: False on_turn_on: #When the relay is tuned on - output.turn_on: blue_led #Turn on the blue LED - mqtt.publish: #Publish an MQTT message topic: ${to_server} #Publish a message to the server payload: ${on_message} #Publish the on message on_turn_off: #When the relay is turned off - output.turn_off: blue_led #Turn off the blue led - mqtt.publish: #Publish an MQTT message topic: ${to_server} #Publish a message to the server payload: ${off_message} #Publish the off message