packages: - !include common/wifi.yaml substitutions: name: sthome-ut3 friendly_name: "sthome-ut3" esphome: name: "${name}" friendly_name: "${friendly_name}" includes: - source # copies folder with files to relevant to be included in esphome compile - # angle brackets ensure file is included above globals in main.cpp. Make sure to use include GUARDS in the file to prevent double inclusion - - - - - - globals: - id: geyser_relay_status type: bool restore_value: yes initial_value: 'false' debug: update_interval: 10s esp32: board: nodemcu-32s #esp32dev framework: type: arduino #esp-idf # Enable logging logger: level: VERY_VERBOSE initial_level: DEBUG logs: uart: VERY_VERBOSE modbus: VERBOSE modbus_controller: VERBOSE # Enable Home Assistant API api: encryption: key: "AIoquKPjpcHa2pcJ0aKxvtpM3mwgZuZhpCPtdVitP2Q=" ota: - platform: esphome password: "879012af7180c8700cee65fbf18704d1" wifi: manual_ip: static_ip: 10.0.2.3 # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "${name} Fallback Hotspot" password: "cGXb2DqkwaOr" captive_portal: #preferences: # flash_write_interval: 30s sun: id: sun_sensor latitude: !secret latitude longitude: !secret longitude time: - platform: homeassistant text_sensor: - platform: debug device: name: "Device Info" reset_reason: name: "Reset Reason" # human readable update text sensor from sensor:uptime - platform: template name: Uptime id: uptime_human icon: mdi:clock-start update_interval: 10s switch: - platform: restart name: "${name} Restart" id: "restart_switch" - platform: gpio pin: number: GPIO16 inverted: true id: relay1 name: "Floodlights Backyard" icon: "mdi:light-flood-down" restore_mode: RESTORE_DEFAULT_OFF # the backyard floodlight auto turns off in 4min 14 sec. So we need to switch relay off just before or at this time # TODO: remove or extend auto turn off to >= 10min on_turn_on: - delay: 250s - switch.turn_off: relay1 - platform: gpio pin: number: GPIO17 inverted: true id: relay2 name: "Relay 2" icon: "mdi:run-fast" restore_mode: RESTORE_DEFAULT_OFF on_turn_on: - delay: 1000ms - switch.turn_off: relay2 - platform: gpio pin: number: GPIO18 inverted: true id: relay3 name: "Relay 3" icon: "mdi:run-fast" restore_mode: RESTORE_DEFAULT_OFF on_turn_on: - delay: 1000ms - switch.turn_off: relay3 - platform: gpio pin: number: GPIO19 inverted: true id: relay4 name: "Alarm Zone 4" icon: "mdi:alarm-light-outline" restore_mode: RESTORE_DEFAULT_OFF on_turn_on: - if: condition: - lambda: |- double sun_elevation = id(sun_sensor).elevation(); return (sun_elevation <= -6); // -6° = civil twilight, -12° = nautical twilight, -18° = astronomical twilight #- sun.is_below_horizon: then: - switch.turn_on: relay1 - if: condition: - binary_sensor.is_on: floodlight_test then: - switch.turn_on: relay1 - delay: 30s - switch.turn_off: relay4 # define DIGITAL_D1 04 binary_sensor: - platform: gpio # device_class: light id: floodlight_test pin: number: GPIO04 mode: input: true pullup: true filters: - delayed_off: 100ms name: "Floodlights Test Mode" icon: "mdi:lightbulb-on-outline" sensor: - platform: adc pin: 35 name: "Alarm Signal" id: alarm_signal update_interval: 2000ms attenuation: 12db sampling_mode: avg filters: - lambda: if (x >= 3.11) { return x * 1.60256; } else if (x <= 0.25) { return 0; } else { return x * 1.51; } on_value: then: # switch on floodlights lambda: |- if (id(alarm_signal).state > 1.5) { id(relay1).turn_on(); } # human readable uptime sensor output to the text sensor above - platform: uptime name: Uptime in Days id: uptime_sensor_days update_interval: 10s on_raw_value: then: - text_sensor.template.publish: id: uptime_human state: !lambda |- int seconds = round(id(uptime_sensor_days).raw_state); int days = seconds / (24 * 3600); seconds = seconds % (24 * 3600); int hours = seconds / 3600; seconds = seconds % 3600; int minutes = seconds / 60; seconds = seconds % 60; auto days_str = std::to_string(days); auto hours_str = std::to_string(hours); auto minutes_str = std::to_string(minutes); auto seconds_str = std::to_string(seconds); return ( (days ? days_str + "d " : "") + (hours ? hours_str + "h " : "") + (minutes ? minutes_str + "m " : "") + (seconds_str + "s") ).c_str();