Skip to content

Instantly share code, notes, and snippets.

@daemonp
Created December 29, 2023 11:51
Show Gist options
  • Save daemonp/4ba3534fc96dc1b59b511cee3df8a578 to your computer and use it in GitHub Desktop.
Save daemonp/4ba3534fc96dc1b59b511cee3df8a578 to your computer and use it in GitHub Desktop.
substitutions:
device_name: "saw-clamp"
friendly_name: "Saw AMP Clamp"
timezone: "Europe/London"
main_icon: "saw"
esphome:
name: ${device_name}
platform: ESP8266
board: d1_mini
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: ${friendly_name}_AP
captive_portal:
logger: # Enable logging
api: # Enable Home Assistant API
reboot_timeout: 300s
ota:
web_server: # Enable Web server.
port: 80
globals:
- id: switch_state
type: bool
initial_value: 'false'
time: # Sync time with Home Assistant.
- platform: homeassistant
id: homeassistant_time
timezone: ${timezone}
output:
- platform: esp8266_pwm
id: power_led_output
pin: D4
sensor:
- platform: adc
pin: A0
id: adc_sensor
internal: true
- platform: ct_clamp
sensor: adc_sensor
name: "Saw Power Sensor"
id: power_sensor_live_power
update_interval: 1s
accuracy_decimals: 0
filters:
- calibrate_linear:
- 0.0008 -> 0.0
- 0.036 -> 10.87
- lambda: return x * 230;
unit_of_measurement: "mA"
on_value:
then:
- if:
condition:
lambda: 'return x > 300 and id(switch_state) == false;'
then:
- logger.log: "Turning on Hoovah"
- globals.set:
id: switch_state
value: 'true'
- homeassistant.service:
service: light.turn_on
data:
entity_id: light.kitchen_2
- if:
condition:
lambda: 'return x <= 300 and id(switch_state) == true;'
then:
- logger.log: "Turning off Hoovah"
- delay: 30s
- globals.set:
id: switch_state
value: 'false'
- homeassistant.service:
service: light.turn_off
data:
entity_id: light.kitchen_2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment