substitutions: device_name: "mydevice" descriptive_devicename: My Device board: esp01_1m logger_level: DEBUG esphome: name: $device_name esp8266: board: $board logger: level: $logger_level api: ota: wifi: networks: - ssid: !secret wifi_ssid password: !secret wifi_password ap: ssid: $descriptive_devicename captive_portal: web_server: port: 80 # Prepare for sending HTTP requests http_request: id: http_request_data useragent: esphome/device timeout: 10s switch: - platform: gpio pin: GPIO2 id: relay name: "Relay" inverted: true restore_mode: ALWAYS_OFF binary_sensor: - platform: gpio id: input_command name: "Input Command" pin: number: GPIO3 mode: input: true inverted: true publish_initial_state: true on_state: then: - if: condition: - binary_sensor.is_on: input_command then: - switch.turn_on: relay else: - switch.turn_off: relay # Call script to post status on remote url - script.execute: post_device_state # We need time component to be able to send time when statises are collected time: - platform: sntp id: local_time update_interval: 24h script: # Actual HTTP request is done by this script - id: post_device_state then: - http_request.post: url: http://mydomain.com/sensorapi/ verify_ssl: false json: |- root["time"] = id(local_time).now().strftime("%Y-%m-%d %H:%M:%S"); root["device"] = to_string("${device_name}"); root["input_command"] = id(input_command) ? "ON" : "OFF"; root["relay"] = id(relay).state ? "ON" : "OFF"; root["IP"] = WiFi.localIP().toString(); root["MAC"] = WiFi.macAddress(); root["timestamp"] = id(local_time).now().timestamp; on_response: then: - lambda: |- if (status_code == 200) { ESP_LOGI ("http_post", "HTTP POST sucessfull"); } else { ESP_LOGI ("http_post", "HTTP POST failed"); }