spark66

EspHome Socket

Oct 16th, 2020
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. substitutions:
  2. devicename: two_nice_plug_1
  3. friendly_name: 2Nice Plug Tv
  4. device_description: 2Nice Plug 1 Power Monitoring Plug with button, Red and Blue led.
  5. current_res: "0.00221" # Random value. Requires power monitoring calibration
  6. voltage_div: "955" # Random value. Requires power monitoring calibration
  7.  
  8. esphome:
  9. name: ${devicename}
  10. comment: ${device_description}
  11. platform: ESP8266
  12. board: esp8285
  13.  
  14. wifi:
  15. # reboot_timeout: 60min
  16. # ssid: !secret wifissid_1
  17. # password: !secret wifipw_1
  18. # manual_ip:
  19. # static_ip: 192.168.31.15
  20. # gateway: 192.168.31.1
  21. # subnet: 255.255.255.0
  22. # fast_connect: true
  23.  
  24. # Enable fallback hotspot (captive portal) in case wifi connection fails
  25. ap:
  26. ssid: ${friendly_name}
  27. password: !secret appw
  28. manual_ip:
  29. static_ip: 192.168.2.2
  30. gateway: 192.168.2.1
  31. subnet: 255.255.255.0
  32.  
  33. #captive_portal:
  34.  
  35. # Enable logging
  36. logger:
  37.  
  38. # Web server can be removed after enabling HA API
  39. web_server:
  40. port: 80
  41.  
  42. # Enable Home Assistant API
  43. api:
  44. password: !secret apw
  45.  
  46. ota:
  47. password: !secret otapw
  48.  
  49. # Enable time component for use by daily power sensor
  50. time:
  51. - platform: homeassistant
  52. id: homeassistant_time
  53.  
  54. sensor:
  55. # Reports how long the device has been powered (in minutes)
  56. - platform: uptime
  57. name: ${friendly_name} Uptime
  58. filters:
  59. - lambda: return x / 60.0;
  60. unit_of_measurement: minutes
  61.  
  62. # Reports the WiFi signal strength
  63. - platform: wifi_signal
  64. name: ${friendly_name} Wifi Signal
  65. update_interval: 60s
  66.  
  67. # Reports the Current, Voltage, and Power used by the plugged-in device
  68. - platform: hlw8012
  69. sel_pin:
  70. number: GPIO12
  71. inverted: true
  72. cf_pin: GPIO04
  73. cf1_pin: GPIO05
  74. change_mode_every: 8
  75. update_interval: 10s
  76. current:
  77. name: ${friendly_name} Amperage
  78. icon: mdi:current-ac
  79. unit_of_measurement: A
  80. voltage:
  81. name: ${friendly_name} Voltage
  82. icon: mdi:flash-circle
  83. unit_of_measurement: V
  84. power:
  85. id: wattage
  86. name: ${friendly_name} Wattage
  87. icon: mdi:flash-outline
  88. unit_of_measurement: W
  89. current_resistor: ${current_res}
  90. voltage_divider: ${voltage_div}
  91.  
  92. # Reports the total Power so-far each day, resets at midnight, see https://esphome.io/components/sensor/total_daily_energy.html
  93. - platform: total_daily_energy
  94. name: ${friendly_name} Total Daily Energy
  95. icon: mdi:circle-slice-3
  96. power_id: wattage
  97. filters:
  98. # Multiplication factor from W to kW is 0.001
  99. - multiply: 0.001
  100. unit_of_measurement: kWh
  101.  
  102. binary_sensor:
  103. # Button on the front is pressed and then toggle relay
  104. - platform: gpio
  105. device_class: power
  106. pin:
  107. number: GPIO03
  108. mode: INPUT_PULLUP
  109. inverted: True
  110. name: ${friendly_name} Button # Name to make button visible in HA
  111. on_press:
  112. - switch.toggle: relay
  113.  
  114. text_sensor:
  115. # Reports the ESPHome Version with compile date
  116. - platform: version
  117. name: ${friendly_name} ESPHome Version
  118.  
  119. # Reports detailed wifi info, can be commented out
  120. - platform: wifi_info
  121. ip_address:
  122. name: ${friendly_name} IP Address
  123. # ssid: # Some additional wifi info that is not normally needed
  124. # name: ${friendly_name} Connected SSID
  125. # bssid:
  126. # name: ${friendly_name} Connected BSSID
  127.  
  128. switch:
  129. # Relay itself
  130. - platform: gpio
  131. name: ${friendly_name}
  132. pin: GPIO14
  133. id: relay
  134. restore_mode: RESTORE_DEFAULT_OFF #Try to restore relay state after reboot/power-loss event.
  135. #RESTORE_DEFAULT_OFF (Default) - Attempt to restore state and default to OFF if not possible to restore. Uses flash write cycles.
  136. #RESTORE_DEFAULT_ON - Attempt to restore state and default to ON. Uses flash write cycles.
  137. #ALWAYS_OFF - Always initialize the pin as OFF on bootup. Does not use flash write cycles.
  138. #ALWAYS_ON - Always initialize the pin as ON on bootup. Does not use flash write cycles.
  139. on_turn_on: # Action when relay is turned on
  140. - script.execute: led_power_on
  141. on_turn_off: # Action when relay is turned off
  142. - script.execute: led_relay_off
  143.  
  144. output:
  145. # Output GPIOs for blue led
  146. - platform: esp8266_pwm # Blue
  147. id: ${devicename}_blue_output
  148. pin:
  149. number: GPIO01
  150. inverted: True
  151.  
  152. status_led:
  153. pin:
  154. number: GPIO13
  155. inverted: True
  156.  
  157. light:
  158. # RGB light
  159. - platform: monochromatic
  160. name: ${friendly_name} Light
  161. output: ${devicename}_blue_output
  162. id: ${devicename}_blue_led
  163.  
  164. # Blink the blue light if we aren't connected to WiFi. Could use https://esphome.io/components/status_led.html instead but then we couldn't use the blue light for other things as well.
  165. # Only if not connected after 30s
  166. interval:
  167. - interval: 2000ms
  168. then:
  169. - if:
  170. condition:
  171. for:
  172. time: 30s
  173. condition:
  174. not:
  175. wifi.connected:
  176. then:
  177. - light.turn_on:
  178. id: ${devicename}_blue_led
  179. brightness: 100%
  180.  
  181. script:
  182. - id: led_relay_off # Normal operation when relay is off
  183. then:
  184. - light.turn_off:
  185. id: ${devicename}_blue_led
  186. - id: led_power_on # Normal operation when relay is on
  187. then:
  188. - light.turn_on:
  189. id: ${devicename}_blue_led
  190. brightness: 80%
  191.  
  192.  
Add Comment
Please, Sign In to add comment