diff options
author | KaufHA <[email protected]> | 2021-09-23 11:06:38 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2021-09-23 11:06:38 -0700 |
commit | c1fccaf93f8a315454987c0a8a6cd48dd93a2cf6 (patch) | |
tree | dfafb604ef5f4f2b28e494114feb1ea44d148b97 /kauf-plug-factory.yaml | |
parent | fca2548dcc4a8982b004dc356704c1eba9be3ae5 (diff) | |
download | PLF10-c1fccaf93f8a315454987c0a8a6cd48dd93a2cf6.tar.gz PLF10-c1fccaf93f8a315454987c0a8a6cd48dd93a2cf6.zip |
Add factory yaml file
Adding factory yaml file in addition to template yaml file.
Diffstat (limited to 'kauf-plug-factory.yaml')
-rw-r--r-- | kauf-plug-factory.yaml | 308 |
1 files changed, 308 insertions, 0 deletions
diff --git a/kauf-plug-factory.yaml b/kauf-plug-factory.yaml new file mode 100644 index 0000000..09a03b7 --- /dev/null +++ b/kauf-plug-factory.yaml @@ -0,0 +1,308 @@ +substitutions: + + # **** CHANGE FRIENDLY NAME TO SOMETHING UNIQUE PER DEVICE **** + friendly_name: Kauf Plug + + + +esphome: + + # **** CHANGE DEVICE NAME TO SOMETHING UNIQUE PER DEVICE **** + name: kauf-plug # **** RENAME YAML FILE TO SAME NAME **** + + platform: ESP8266 + board: esp01_1m + + esp8266_restore_from_flash: true + + # remove next line if renaming to something unique above + name_add_mac_suffix: true + + + project: + name: "kauf.plf10" + version: "1.5a" + + + + + # checking if wifi has ever been configured. Cranking up ap timeout to a week if so. + on_boot: + then: + - if: + condition: + lambda: |- + return id(wifi_configured_before); + then: + - logger.log: "------------------->>>>>>>>>>>>>>>>> wifi configured before, ap timeout to 2500h" + - lambda: |- + wifi_wificomponent->set_ap_timeout(9000000000ULL); + + else: + - logger.log: "------------------->>>>>>>>>>>>>>>>> wifi not configured before, leaving ap timeout as 25s" + - wait_until: + wifi.connected + - logger.log: "------------------->>>>>>>>>>>>>>>>> wifi connected, setting wifi_configured_before variable and cranking up ap timeout" + - globals.set: + id: wifi_configured_before + value: 'true' + - lambda: |- + wifi_wificomponent->set_ap_timeout(9000000000ULL); + + +globals: + - id: wifi_configured_before + type: bool + restore_value: yes + initial_value: 'false' + + + + + + +wifi: + ssid: initial_ap2 + password: asdfasdfasdfasdf + + # Uncomment below to set a static IP + # manual_ip: + # static_ip: !secret kauf_bulb_ip_address + # gateway: !secret wifi_gateway + # subnet: !secret wifi_subnet + # dns1: !secret wifi_dns1 + + # use_address allows wireless programming through dashboard. remove after programming. + # use_address: 192.168.1.3 + + # default is 20, 17 is recommended. + output_power: 17 + + + ap: + ssid: ${friendly_name} Hotspot + ap_timeout: 25s + + +captive_portal: # for fallback wifi hotspot + +logger: # Enable logging +# baud_rate: 0 # Disable UART logging since TX pad not easily available + +api: # Enable Home Assistant API + # password: !secret api_password # optional password field for Home Assistant API. + +ota: + # password: !secret ota_password # optional password for OTA updates. + + +debug: # outputs additional debug info when logs start + + + +web_server: # web server allows access to device with a web browser + # auth: # optional login details for web interface + # username: admin + # password: !secret web_server_password + + + + +# red led, blink when not connected to wifi or Home Assistant +status_led: + pin: + number: GPIO0 + inverted: true + + + + + +binary_sensor: + + # button input toggles relay and thereby blue led + - platform: gpio + id: button + pin: + number: GPIO13 + mode: INPUT_PULLUP + inverted: true + + on_click: + + - min_length: 35ms + max_length: 2s + then: + - switch.toggle: relay + + # if button is held >5s, restart AP. + - min_length: 5s + max_length: 30s + then: + - logger.log: "------------------->>>>>>>>>>>>>>>>> HELD BUTTON 5 SECONDS, CLEARING VARIABLE AND STARTING AP" + - globals.set: + id: wifi_configured_before + value: 'false' + - lambda: |- + wifi_wificomponent->set_ap_timeout(10000); + - script.execute: blink_led + - wait_until: + wifi.connected + - logger.log: "------------------->>>>>>>>>>>>>>>>> wifi connected, setting wifi_configured_before variable and cranking up ap timeout" + - globals.set: + id: wifi_configured_before + value: 'true' + - lambda: |- + wifi_wificomponent->set_ap_timeout(9000000000ULL); + - while: + condition: + script.is_running: blink_led + then: + script.stop: blink_led + # still need to set blue led to relay state + - if: + condition: + lambda: 'return id(relay).state;' + then: + - switch.turn_on: blue_led + else: + - switch.turn_off: blue_led + + + + + - platform: template + id: in_use + name: ${friendly_name} Device In Use + + + + +script: + - id: blink_led + mode: queued + then: + - switch.toggle: blue_led + - delay: 250ms + - script.execute: blink_led + + + + + + +switch: + + # blue LED follows relay power state + - platform: gpio + id: blue_led + pin: + number: GPIO2 + inverted: true + + # relay output + - platform: gpio + id: relay + name: $friendly_name + pin: GPIO4 + + # automatically make blue led equal relay state + on_turn_on: + - switch.turn_on: blue_led + on_turn_off: + - switch.turn_off: blue_led + + + +# clock input from Home Assistant used for total daily energy +time: + - platform: homeassistant + id: homeassistant_time + + + +sensor: # Power monitoring sensors output to Home Assistant + - platform: hlw8012 + sel_pin: + number: GPIO12 + inverted: True + cf_pin: GPIO5 + cf1_pin: GPIO14 + current_resistor: 0.001 # The value of the shunt resistor for current measurement. + voltage_divider: 2401 # The value of the voltage divider on the board as (R_upstream + R_downstream) / R_downstream. + power: + name: ${friendly_name} Power + unit_of_measurement: W + id: wattage + filters: + - calibrate_linear: + - 0.0 -> 0.0 + - 333.8 -> 60 # value with 60W bulb. + on_value: # set or clear in_use template binary sensor depending on whether power usage is over threshold + - if: + condition: + lambda: 'return (x >= id(threshold).state);' + then: + - binary_sensor.template.publish: + id: in_use + state: ON + else: + - binary_sensor.template.publish: + id: in_use + state: OFF + current: + name: ${friendly_name} Current + unit_of_measurement: A + filters: + - calibrate_linear: + - 0.0 -> 0.0 + - 0.6 -> 0.515 # value with 60W bulb. + voltage: + name: ${friendly_name} Voltage + unit_of_measurement: V + filters: + - calibrate_linear: + - 0.0 -> 0.0 + - 302.1 -> 117.1 # Tested using a meter + change_mode_every: 1 + update_interval: 10s # 20 second effective update rate for Power, 40 second for Current and Voltage. + +# Reports the total Power so-far each day, resets at midnight, see https://esphome.io/components/sensor/total_daily_energy.html + - platform: total_daily_energy + name: ${friendly_name} Total Daily Energy + power_id: wattage + filters: + - multiply: 0.001 ## convert Wh to kWh + unit_of_measurement: kWh + + +number: + - platform: template + name: ${friendly_name} Use Threshold + min_value: 1 + max_value: 100 + step: 1 + initial_value: 2 + id: threshold + optimistic: true # required for changing value from home assistant + restore_value: true + on_value: + - if: # set or clear in_use template binary sensor depending on whether power usage is above threshold + condition: + lambda: 'return (id(wattage).state >= x);' + then: + - binary_sensor.template.publish: + id: in_use + state: ON + else: + - binary_sensor.template.publish: + id: in_use + state: OFF + + + +# Send IP Address to HA +text_sensor: + - platform: wifi_info + ip_address: + name: $friendly_name IP Address
\ No newline at end of file |