I need advice and assistance with some YAML code for ESPHome, please?
First some background:
I have an external motorised roller blind on a west facing window, that through an automation, comes down at 2:00pm and goes back up at sundown. However, if the day is overcast, the blind does not need to come down. So, I have built a “sun intensity” sensor with a small solar panel (from a garden light) and an ESP8266. It is battery powered, so I want it to boot from a deep sleep, measure the current (proportional to the sun’s intensity) from the solar panel and then go back to deep sleep for 10 minutes. The solar panel is also used to keep the rechargable battery topped up.
I plan to use the average current data from the prevoius couple of hours to decide (at 2:00pm) if the blind should be lowered that day. If the current is high, it is likely bright and sunny. If the current is low, it is likely overcast and cloudy.
Anyway, I have built the sensor/module and I am now trying to program it with ESPHome YAML. But I cannot figure out how to get the ADC to take a reading after a reboot. This is the code that I have so far:
esphome:
name: "sunlight-sensor"
friendly_name: Sunlight sensor
on_boot:
- priority: -100
then:
- output.turn_on: shunt_switch
- delay: 100ms
# what do I put here to read the voltage at GPIO17 (ADC) ?
- delay: 100ms
- output.turn_off: shunt_switch
esp8266:
board: d1_mini
logger:
api:
encryption:
key: "********"
ota:
- platform: esphome
password: "********"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Sunlight-Sensor Fallback Hotspot"
password: "********"
captive_portal:
output:
- platform: gpio
id: shunt_switch
pin: GPIO5
sensor:
- platform: adc
id: solar_current
pin: GPIO17
name: "Sun Brightness"
update_interval: never
# deep_sleep:
# id: deep_sleep_1
# run_duration: 10s
# sleep_duration: 10min
#
# binary_sensor:
# - platform: homeassistant
# id: prevent_deep_sleep
# name: "Prevent Deep Sleep"
# entity_id: input_boolean.prevent_deep_sleep
If you look at line 10, I want to take a reading of the voltage across the current shunt and make that available to HA. Could you please advise how I go about doing that with YAML code?