Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # D1 Mini - Alarm Panel
- # 2 x ADS1115 for 8 x Alarm zones (GPIO4/5)
- # 1 x DHT11 (GPIO14)
- # 1 x LED String (8 zone Indicators) (GPIO15)
- # 1 x Switch (LEDs Enable/Disable) (GPIO13)
- esphome:
- name: esp_alarm
- comment: D1 Mini - Loft - Alarm Panel
- platform: ESP8266
- board: esp01_1m
- # board: d1_mini
- wifi:
- ssid: 'xxxx'
- password: 'xxxx'
- manual_ip:
- static_ip: 192.168.1.52
- gateway: 192.168.1.254
- subnet: 255.255.255.0
- # Enable logging
- logger:
- level: DEBUG
- baud_rate: 0
- logs:
- ads1115: ERROR
- # level: INFO
- # Enable Home Assistant API
- api:
- ota:
- # web_server:
- substitutions:
- # Common ADS1115 Sensor Setting
- ads_gain: "6.144"
- ads_update_interval: "500ms"
- ads_delta: "0.2"
- ads_heartbeat: "120s"
- # Common Text Sensor Setting
- zone_icon: "mdi:lock-alert"
- # Common Zone (Int) Sensor Setting
- sensor_icon: "mdi:shield-lock"
- # Neopixel Brigtness
- led_bright: "50%"
- # Transition Voltages between States
- # 0 -> (State1) -> V1 -> (State2) -> V2 -> (State3) -> V3 -> (State4)
- v1: "1"
- v2: "2.5"
- v3: "3.5"
- # Text Sensor strings for each state
- alarm_state1: "Short"
- alarm_state2: "OK"
- alarm_state3: "Alarm"
- alarm_state4: "Tamper"
- # Led Effect
- led_effect1: "RED_BLINK_FAST"
- led_effect2: "GREEN"
- led_effect3: "RED"
- led_effect4: "RED_BLINK_FAST"
- # I2C Settings for 2 x ADS1115
- i2c:
- sda: GPIO4
- scl: GPIO5
- scan: False
- ads1115:
- # 1st ADS1115 (ADDR -> Grnd)
- - address: 0x48
- id: ads1115_1
- # 2nd ADS1115 (ADDR -> VDD)
- - address: 0x49
- id: ads1115_2
- # NEOPixel Leds. 1 String with 1 LED / Zone via partition
- light:
- # Define Parent String
- - platform: fastled_clockless
- chipset: WS2812B
- internal: true
- rgb_order: GRB
- default_transition_length: 0s
- pin: GPIO15
- color_correct :
- - ${led_bright}
- - ${led_bright}
- - ${led_bright}
- num_leds: 12
- name: "LED_Status_String"
- id: led_string
- # 1 Partition (Indicator LED) per Zone
- # Zone 1
- - platform: partition
- id: led_01
- internal: true
- name: "Zone 1 LED"
- default_transition_length: 0s
- segments:
- - id: led_string
- from: 0
- to: 0
- # Include Common Effects - RED/GREEN/BLINK_RED_SLOW/BLINK_RED_FAST
- effects: !include include/esp_include_alarm_led_effect.yaml
- # Zone 2
- - platform: partition
- id: led_02
- internal: true
- name: "Zone 2 LED"
- default_transition_length: 0s
- segments:
- - id: led_string
- from: 1
- to: 1
- # Include Common Effects - RED/GREEN/BLINK_RED_SLOW/BLINK_RED_FAST
- effects: !include include/esp_include_alarm_led_effect.yaml
- # Zone 3
- - platform: partition
- id: led_03
- internal: true
- name: "Zone 3 LED"
- default_transition_length: 0s
- segments:
- - id: led_string
- from: 2
- to: 2
- # Include Common Effects - RED/GREEN/BLINK_RED_SLOW/BLINK_RED_FAST
- effects: !include include/esp_include_alarm_led_effect.yaml
- # Zone 4
- - platform: partition
- id: led_04
- internal: true
- name: "Zone 4 LED"
- default_transition_length: 0s
- segments:
- - id: led_string
- from: 3
- to: 3
- # Include Common Effects - RED/GREEN/BLINK_RED_SLOW/BLINK_RED_FAST
- effects: !include include/esp_include_alarm_led_effect.yaml
- - platform: partition
- id: led_05
- internal: true
- name: "Zone 5 LED"
- default_transition_length: 0s
- segments:
- - id: led_string
- from: 4
- to: 4
- # Include Common Effects - RED/GREEN/BLINK_RED_SLOW/BLINK_RED_FAST
- effects: !include include/esp_include_alarm_led_effect.yaml
- - platform: partition
- id: led_06
- internal: true
- name: "Zone 6 LED"
- default_transition_length: 0s
- segments:
- - id: led_string
- from: 5
- to: 5
- # Include Common Effects - RED/GREEN/BLINK_RED_SLOW/BLINK_RED_FAST
- effects: !include include/esp_include_alarm_led_effect.yaml
- - platform: partition
- id: led_07
- internal: true
- name: "Zone 7 LED"
- default_transition_length: 0s
- segments:
- - id: led_string
- from: 6
- to: 6
- # Include Common Effects - RED/GREEN/BLINK_RED_SLOW/BLINK_RED_FAST
- effects: !include include/esp_include_alarm_led_effect.yaml
- - platform: partition
- id: led_08
- internal: true
- name: "Zone 8 LED"
- default_transition_length: 0s
- segments:
- - id: led_string
- from: 7
- to: 7
- # Include Common Effects - RED/GREEN/BLINK_RED_SLOW/BLINK_RED_FAST
- effects: !include include/esp_include_alarm_led_effect.yaml
- - platform: partition
- id: led_09
- internal: true
- name: "Flow 1 LED"
- default_transition_length: 0s
- segments:
- - id: led_string
- from: 8
- to: 8
- # Include Common Effects - RED/GREEN/BLINK_RED_SLOW/BLINK_RED_FAST
- effects: !include include/esp_include_alarm_led_effect.yaml
- - platform: partition
- id: led_10
- internal: true
- name: "Flow 2 LED"
- default_transition_length: 0s
- segments:
- - id: led_string
- from: 9
- to: 9
- # Include Common Effects - RED/GREEN/BLINK_RED_SLOW/BLINK_RED_FAST
- effects: !include include/esp_include_alarm_led_effect.yaml
- sensor:
- - platform: uptime
- name: Uptime Sensor
- # DHT11 Temp/Humidity Sensor
- - platform: dht
- model: dht11
- pin: GPIO14
- temperature:
- name: "Alarm Temperature"
- id: alarm_temperature
- humidity:
- name: "Alarm Humidity"
- id: alarm_humidity
- update_interval: 60s
- # Integer State Sensors, Controls Zone Text Sensor and Zone Indicator LED Effect
- - platform: template
- name: "Zone01 Sensor"
- id: zone_01_int
- icon: "${sensor_icon}"
- on_value:
- # When Zone state (1-4) changes, set effect if Lights enabled, Set Text State
- - lambda: |-
- std::string out_effect[] = {"Unset","${led_effect1}","${led_effect2}","${led_effect3}","${led_effect4}" };
- std::string out_state[] = {"Unset","${alarm_state1}","${alarm_state2}","${alarm_state3}","${alarm_state4}" };
- int y = (int) x;
- if (id(sw_lights_enable).state) {
- auto call = id(led_01).turn_on();
- call.set_effect(out_effect[y]);
- call.perform();
- }
- id(zone_01_str).publish_state(out_state[y]);
- - platform: template
- name: "Zone02 Sensor"
- id: zone_02_int
- icon: "${sensor_icon}"
- on_value:
- # When Zone state (1-4) changes, set effect if Lights enabled, Set Text State
- - lambda: |-
- std::string out_effect[] = {"Unset","${led_effect1}","${led_effect2}","${led_effect3}","${led_effect4}" };
- std::string out_state[] = {"Unset","${alarm_state1}","${alarm_state2}","${alarm_state3}","${alarm_state4}" };
- int y = (int) x;
- if (id(sw_lights_enable).state) {
- auto call = id(led_02).turn_on();
- call.set_effect(out_effect[y]);
- call.perform();
- }
- id(zone_02_str).publish_state(out_state[y]);
- - platform: template
- name: "Zone03 Sensor"
- id: zone_03_int
- icon: "${sensor_icon}"
- on_value:
- # When Zone state (1-4) changes, set effect if Lights enabled, Set Text State
- - lambda: |-
- std::string out_effect[] = {"Unset","${led_effect1}","${led_effect2}","${led_effect3}","${led_effect4}" };
- std::string out_state[] = {"Unset","${alarm_state1}","${alarm_state2}","${alarm_state3}","${alarm_state4}" };
- int y = (int) x;
- if (id(sw_lights_enable).state) {
- auto call = id(led_03).turn_on();
- call.set_effect(out_effect[y]);
- call.perform();
- }
- id(zone_03_str).publish_state(out_state[y]);
- - platform: template
- name: "Zone04 Sensor"
- id: zone_04_int
- icon: "${sensor_icon}"
- on_value:
- # When Zone state (1-4) changes, set effect if Lights enabled, Set Text State
- - lambda: |-
- std::string out_effect[] = {"Unset","${led_effect1}","${led_effect2}","${led_effect3}","${led_effect4}" };
- std::string out_state[] = {"Unset","${alarm_state1}","${alarm_state2}","${alarm_state3}","${alarm_state4}" };
- int y = (int) x;
- if (id(sw_lights_enable).state) {
- auto call = id(led_04).turn_on();
- call.set_effect(out_effect[y]);
- call.perform();
- }
- id(zone_04_str).publish_state(out_state[y]);
- - platform: template
- name: "Zone05 Sensor"
- id: zone_05_int
- icon: "${sensor_icon}"
- on_value:
- # When Zone state (1-4) changes, set effect if Lights enabled, Set Text State
- - lambda: |-
- std::string out_effect[] = {"Unset","${led_effect1}","${led_effect2}","${led_effect3}","${led_effect4}" };
- std::string out_state[] = {"Unset","${alarm_state1}","${alarm_state2}","${alarm_state3}","${alarm_state4}" };
- int y = (int) x;
- if (id(sw_lights_enable).state) {
- auto call = id(led_05).turn_on();
- call.set_effect(out_effect[y]);
- call.perform();
- }
- id(zone_05_str).publish_state(out_state[y]);
- - platform: template
- name: "Zone06 Sensor"
- id: zone_06_int
- icon: "${sensor_icon}"
- on_value:
- # When Zone state (1-4) changes, set effect if Lights enabled, Set Text State
- - lambda: |-
- std::string out_effect[] = {"Unset","${led_effect1}","${led_effect2}","${led_effect3}","${led_effect4}" };
- std::string out_state[] = {"Unset","${alarm_state1}","${alarm_state2}","${alarm_state3}","${alarm_state4}" };
- int y = (int) x;
- if (id(sw_lights_enable).state) {
- auto call = id(led_06).turn_on();
- call.set_effect(out_effect[y]);
- call.perform();
- }
- id(zone_06_str).publish_state(out_state[y]);
- - platform: template
- name: "Zone07 Sensor"
- id: zone_07_int
- icon: "${sensor_icon}"
- on_value:
- # When Zone state (1-4) changes, set effect if Lights enabled, Set Text State
- - lambda: |-
- std::string out_effect[] = {"Unset","${led_effect1}","${led_effect2}","${led_effect3}","${led_effect4}" };
- std::string out_state[] = {"Unset","${alarm_state1}","${alarm_state2}","${alarm_state3}","${alarm_state4}" };
- int y = (int) x;
- if (id(sw_lights_enable).state) {
- auto call = id(led_07).turn_on();
- call.set_effect(out_effect[y]);
- call.perform();
- }
- id(zone_07_str).publish_state(out_state[y]);
- - platform: template
- name: "Zone08 Sensor"
- id: zone_08_int
- icon: "${sensor_icon}"
- on_value:
- # When Zone state (1-4) changes, set effect if Lights enabled, Set Text State
- - lambda: |-
- std::string out_effect[] = {"Unset","${led_effect1}","${led_effect2}","${led_effect3}","${led_effect4}" };
- std::string out_state[] = {"Unset","${alarm_state1}","${alarm_state2}","${alarm_state3}","${alarm_state4}" };
- int y = (int) x;
- if (id(sw_lights_enable).state) {
- auto call = id(led_08).turn_on();
- call.set_effect(out_effect[y]);
- call.perform();
- }
- id(zone_08_str).publish_state(out_state[y]);
- # ADS1115 Voltage Sensors (1 per Zone)
- - platform: ads1115
- ads1115_id: ads1115_1
- multiplexer: 'A0_GND'
- gain: ${ads_gain}
- name: "ADS1115-1-A0"
- id: ads1115_1_a0
- update_interval: ${ads_update_interval}
- internal: true
- filters:
- - or:
- - delta: ${ads_delta}
- - heartbeat: ${ads_heartbeat}
- on_value:
- then:
- # Compare Reading to Ref voltages and set zone state (Int) if changed.
- - lambda: |-
- int y = 0;
- if (x > ${v2} ) { y = 3; } // # State 3 = Alarm = Red
- else if (x <= ${v2}) { y = 2; } // # State 2 = OK = Green
- if (id(zone_01_int).state != y) {
- id(zone_01_int).publish_state(y);
- }
- - platform: ads1115
- ads1115_id: ads1115_1
- multiplexer: 'A1_GND'
- gain: ${ads_gain}
- name: "ADS1115-1-A1"
- id: ads1115_1_a1
- update_interval: ${ads_update_interval}
- internal: true
- filters:
- - or:
- - delta: ${ads_delta}
- - heartbeat: ${ads_heartbeat}
- on_value:
- then:
- # Compare Reading to Ref voltages and set zone state (Int) if changed.
- - lambda: |-
- int y = 0;
- if (x > ${v3}) { y = 4; } // # State 4 = Tamper/Short = Red_Blink
- else if (x > ${v2} && x <= ${v3}) { y = 3; } // # State 3 = Alarm = Red
- else if (x > ${v1} && x <= ${v2}) { y = 2; } // # State 2 = OK = Green
- else if (x <= ${v1}) { y = 1; } // # State 1 = Short = Red Blink
- if (id(zone_02_int).state != y) {
- id(zone_02_int).publish_state(y);
- }
- - platform: ads1115
- ads1115_id: ads1115_1
- multiplexer: 'A2_GND'
- gain: ${ads_gain}
- name: "ADS1115-1-A2"
- id: ads1115_1_a2
- update_interval: ${ads_update_interval}
- internal: true
- filters:
- - or:
- - delta: ${ads_delta}
- - heartbeat: ${ads_heartbeat}
- on_value:
- then:
- # Compare Reading to Ref voltages and set zone state (Int) if changed.
- - lambda: |-
- int y = 0;
- if (x > ${v3}) { y = 4; } // # State 4 = Tamper/Short = Red_Blink
- else if (x > ${v2} && x <= ${v3}) { y = 3; } // # State 3 = Alarm = Red
- else if (x > ${v1} && x <= ${v2}) { y = 2; } // # State 2 = OK = Green
- else if (x <= ${v1}) { y = 1; } // # State 1 = Short = Red Blink
- if (id(zone_03_int).state != y) {
- id(zone_03_int).publish_state(y);
- }
- - platform: ads1115
- ads1115_id: ads1115_1
- multiplexer: 'A3_GND'
- gain: ${ads_gain}
- name: "ADS1115-1-A3"
- id: ads1115_1_a3
- update_interval: ${ads_update_interval}
- internal: true
- filters:
- - or:
- - delta: ${ads_delta}
- - heartbeat: ${ads_heartbeat}
- on_value:
- then:
- # Compare Reading to Ref voltages and set zone state (Int) if changed.
- - lambda: |-
- int y = 0;
- if (x > ${v3}) { y = 4; } // # State 4 = Tamper/Short = Red_Blink
- else if (x > ${v2} && x <= ${v3}) { y = 3; } // # State 3 = Alarm = Red
- else if (x > ${v1} && x <= ${v2}) { y = 2; } // # State 2 = OK = Green
- else if (x <= ${v1}) { y = 1; } // # State 1 = Short = Red Blink
- if (id(zone_04_int).state != y) {
- id(zone_04_int).publish_state(y);
- }
- - platform: ads1115
- ads1115_id: ads1115_2
- multiplexer: 'A0_GND'
- gain: ${ads_gain}
- name: "ADS1115-2-A0"
- id: ads1115_2_a0
- update_interval: ${ads_update_interval}
- internal: true
- filters:
- - or:
- - delta: ${ads_delta}
- - heartbeat: ${ads_heartbeat}
- on_value:
- then:
- # Compare Reading to Ref voltages and set zone state (Int) if changed.
- - lambda: |-
- int y = 0;
- if (x > ${v3}) { y = 4; } // # State 4 = Tamper/Short = Red_Blink
- else if (x > ${v2} && x <= ${v3}) { y = 3; } // # State 3 = Alarm = Red
- else if (x > ${v1} && x <= ${v2}) { y = 2; } // # State 2 = OK = Green
- else if (x <= ${v1}) { y = 1; } // # State 1 = Short = Red Blink
- if (id(zone_05_int).state != y) {
- id(zone_05_int).publish_state(y);
- }
- - platform: ads1115
- ads1115_id: ads1115_2
- multiplexer: 'A1_GND'
- gain: ${ads_gain}
- name: "ADS1115-2-A1"
- id: ads1115_2_a1
- update_interval: ${ads_update_interval}
- internal: true
- filters:
- - or:
- - delta: ${ads_delta}
- - heartbeat: ${ads_heartbeat}
- on_value:
- then:
- # Compare Reading to Ref voltages and set zone state (Int) if changed.
- - lambda: |-
- int y = 0;
- if (x > ${v3}) { y = 4; } // # State 4 = Tamper/Short = Red_Blink
- else if (x > ${v2} && x <= ${v3}) { y = 3; } // # State 3 = Alarm = Red
- else if (x > ${v1} && x <= ${v2}) { y = 2; } // # State 2 = OK = Green
- else if (x <= ${v1}) { y = 1; } // # State 1 = Short = Red Blink
- if (id(zone_06_int).state != y) {
- id(zone_06_int).publish_state(y);
- }
- - platform: ads1115
- ads1115_id: ads1115_2
- multiplexer: 'A2_GND'
- gain: ${ads_gain}
- name: "ADS1115-2-A2"
- id: ads1115_2_a2
- update_interval: ${ads_update_interval}
- internal: true
- filters:
- - or:
- - delta: ${ads_delta}
- - heartbeat: ${ads_heartbeat}
- on_value:
- then:
- # Compare Reading to Ref voltages and set zone state (Int) if changed.
- - lambda: |-
- int y = 0;
- if (x > ${v3}) { y = 4; } // # State 4 = Tamper/Short = Red_Blink
- else if (x > ${v2} && x <= ${v3}) { y = 3; } // # State 3 = Alarm = Red
- else if (x > ${v1} && x <= ${v2}) { y = 2; } // # State 2 = OK = Green
- else if (x <= ${v1}) { y = 1; } // # State 1 = Short = Red Blink
- if (id(zone_07_int).state != y) {
- id(zone_07_int).publish_state(y);
- }
- - platform: ads1115
- ads1115_id: ads1115_2
- multiplexer: 'A3_GND'
- gain: ${ads_gain}
- name: "ADS1115-2-A3"
- id: ads1115_2_a3
- update_interval: ${ads_update_interval}
- internal: true
- filters:
- - or:
- - delta: ${ads_delta}
- - heartbeat: ${ads_heartbeat}
- on_value:
- then:
- # Compare Reading to Ref voltages and set zone state (Int) if changed.
- - lambda: |-
- int y = 0;
- if (x > ${v3}) { y = 4; } // # State 4 = Tamper/Short = Red_Blink
- else if (x > ${v2} && x <= ${v3}) { y = 3; } // # State 3 = Alarm = Red
- else if (x > ${v1} && x <= ${v2}) { y = 2; } // # State 2 = OK = Green
- else if (x <= ${v1}) { y = 1; } // # State 1 = Short = Red Blink
- if (id(zone_08_int).state != y) {
- id(zone_08_int).publish_state(y);
- }
- # Text Sensors visible to HA, 1 per Zone
- text_sensor:
- - platform: template
- name: "Zone01 State"
- icon: "${zone_icon}"
- id: zone_01_str
- - platform: template
- name: "Zone02 State"
- icon: "${zone_icon}"
- id: zone_02_str
- - platform: template
- name: "Zone03 State"
- icon: "${zone_icon}"
- id: zone_03_str
- - platform: template
- name: "Zone04 State"
- icon: "${zone_icon}"
- id: zone_04_str
- - platform: template
- name: "Zone05 State"
- icon: "${zone_icon}"
- id: zone_05_str
- - platform: template
- name: "Zone06 State"
- icon: "${zone_icon}"
- id: zone_06_str
- - platform: template
- name: "Zone07 State"
- icon: "${zone_icon}"
- id: zone_07_str
- - platform: template
- name: "Zone08 State"
- icon: "${zone_icon}"
- id: zone_08_str
- binary_sensor:
- - platform: gpio
- id: sw_lights_enable
- name: Lights Enable
- pin:
- number: GPIO13
- internal: true
- on_state:
- if:
- condition:
- binary_sensor.is_on: sw_lights_enable
- then:
- # Publish Current Zone States to force up date of effect
- - lambda: |-
- id(zone_01_int).publish_state(id(zone_01_int).state);
- id(zone_02_int).publish_state(id(zone_02_int).state);
- id(zone_03_int).publish_state(id(zone_03_int).state);
- id(zone_04_int).publish_state(id(zone_04_int).state);
- id(zone_05_int).publish_state(id(zone_05_int).state);
- id(zone_06_int).publish_state(id(zone_06_int).state);
- id(zone_07_int).publish_state(id(zone_07_int).state);
- id(zone_08_int).publish_state(id(zone_08_int).state);
- id(flow_switch_01).publish_state(id(flow_switch_01).state);
- id(flow_switch_02).publish_state(id(flow_switch_02).state);
- else:
- - light.turn_off: led_01
- - light.turn_off: led_02
- - light.turn_off: led_03
- - light.turn_off: led_04
- - light.turn_off: led_05
- - light.turn_off: led_06
- - light.turn_off: led_07
- - light.turn_off: led_08
- - light.turn_off: led_09
- - light.turn_off: led_10
- - platform: gpio
- id: flow_switch_01
- name: Flow Switch 1
- filters:
- invert
- pin:
- number: GPIO16
- on_press:
- if:
- condition:
- binary_sensor.is_on: sw_lights_enable
- then:
- - lambda: |-
- auto call = id(led_09).turn_on();
- call.set_effect("${led_effect2}");
- call.perform();
- on_release:
- - light.turn_off: led_09
- - platform: gpio
- id: flow_switch_02
- name: Flow Switch 2
- filters:
- invert
- pin:
- number: GPIO12
- on_press:
- if:
- condition:
- binary_sensor.is_on: sw_lights_enable
- then:
- - lambda: |-
- auto call = id(led_10).turn_on();
- call.set_effect("${led_effect2}");
- call.perform();
- on_release:
- - light.turn_off: led_10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement