Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- esphome:
- name: keypad
- friendly_name: keypad
- esp32:
- board: esp32dev
- framework:
- type: arduino
- # Enable logging
- logger:
- # Enable Home Assistant API
- api:
- encryption:
- key: "6c7jRAZCFNm9iaRuXNIujFbwB3bst0Ple8lRVGWjp/w="
- ota:
- - platform: esphome
- password: "49f36bca21d4d0a8609cd3fa297e6e73"
- wifi:
- on_connect:
- then:
- - text_sensor.template.publish:
- id: last_user
- state: !lambda |-
- return id(last_user_access).value;
- ### - dfplayer.play: !lambda return atoi(x.c_str()); ###
- networks:
- - ssid: linksys-barn
- password: "XXXXXX"
- - ssid: linksys-baker
- password: "XXXXXX"
- manual_ip:
- static_ip: 192.168.0.186
- gateway: 192.168.0.1
- subnet: 255.255.255.0
- dns1: 192.168.0.1
- dns2: 192.168.0.194
- # Enable fallback hotspot (captive portal) in case wifi connection fails
- #ap:
- # ssid: "Keypad"
- # password: "XXXXXX"
- captive_portal:
- web_server:
- port: 80
- version: 3
- auth:
- username: "Justin"
- password: "XXXXXX"
- ################ Guest Mode Timers #############
- #
- # Use both Start and Stop timers to specify which times of the day are allowed for the guest.
- #
- # Example: Start Time 08:00:00Am - Stop Time 05:00:00Pm Will Only Allow Access between Those Times (9 Hours)
- datetime:
- - platform: template
- id: guest_mode_start_time
- type: time
- name: "Guest Mode Time On"
- optimistic: yes
- initial_value: "08:00:00"
- restore_value: true
- on_time:
- - if:
- condition:
- - switch.is_on: guest_active
- then:
- - switch.turn_on: guest_active
- - platform: template
- id: guest_mode_off_time
- type: time
- name: "Guest Mode Time Off"
- optimistic: yes
- initial_value: "05:00:00"
- restore_value: true
- on_time:
- - if:
- condition:
- and:
- - text_sensor.state:
- id: ha_cover_state
- state: open
- - switch.is_on: guest_active
- then:
- - button.press: transmit_rf
- else:
- - switch.turn_off: guest_active
- number:
- - platform: template
- name: "Set New Code"
- id: new_keypad_code
- min_value: 0
- max_value: 9999
- step: 1
- mode: box
- restore_value: false
- optimistic: true
- on_value:
- if:
- condition:
- - switch.is_on: guest_active
- then:
- - globals.set:
- id: temp_code
- value: !lambda 'return x;'
- sun:
- latitude: 40.173568
- longitude: -86.0225536
- on_sunset:
- - light.turn_on:
- id: barn_overhead_led
- brightness: 50%
- white: 100%
- - switch.turn_on:
- id: outside_barn_lights
- on_sunrise:
- - light.turn_off:
- id: barn_overhead_led
- - switch.turn_off:
- id: outside_barn_lights
- time:
- - platform: homeassistant
- id: homeassistant_time
- remote_transmitter:
- pin: 4
- carrier_duty_percent: 100%
- button:
- - platform: template
- name: "test send number"
- id: test_keysend
- on_press:
- then:
- - lambda: |-
- id(pincode_reader).send_key('1');
- - delay: 250ms
- - lambda: |-
- id(pincode_reader).send_key('2');
- - delay: 250ms
- - lambda: |-
- id(pincode_reader).send_key('3');
- - delay: 250ms
- - lambda: |-
- id(pincode_reader).send_key('4');
- - delay: 50ms
- - lambda: |-
- id(pincode_reader).send_key('#');
- - platform: template
- id: transmit_rf
- name: "Overhead Door RF"
- on_press:
- then:
- - remote_transmitter.transmit_rc_switch_raw:
- code: '00101001100111110101101' #### Test Code Only '00100100100001' #######
- protocol: 1
- repeat:
- times: 1
- wait_time: 0ms
- - platform: restart
- id: keypad_restart
- name: "Keypad Restart"
- - platform: safe_mode
- id: keypad_safemode
- name: "Keypad (Safe Mode)"
- switch:
- - platform: template
- assumed_state: False
- id: reset_password
- name: "Reset Keypad Pin"
- - platform: template
- name: "Auto-Restart 2x"
- id: auto_restart_keypad
- optimistic: true
- restore_mode: RESTORE_DEFAULT_ON
- - platform: template
- id: guest_active
- name: "Guest Mode"
- optimistic: True
- restore_mode: DISABLED
- on_turn_off:
- then:
- - number.set:
- id: new_keypad_code
- value: 0
- - platform: template
- id: ovrhead
- optimistic: true
- on_turn_on:
- - homeassistant.service:
- service: switch.toggle
- data:
- entity_id: switch.overhead_door_rf_barn_overhead_door
- - platform: gpio
- pin:
- number: 25
- #mode:
- inverted: true
- name: 'Barn Door Lights'
- id: outside_barn_lights
- #optimistic: true
- - platform: gpio
- name: "Barn Switch 1"
- id: barn_switch1
- pin:
- number: 15
- inverted: false
- device_class: switch
- - platform: gpio
- name: "Barn Switch 2"
- id: barn_switch2
- pin:
- number: 5
- inverted: false
- device_class: switch
- - platform: template
- name: "Barn Lights"
- id: barn_inside_lights
- optimistic: true
- restore_mode: RESTORE_DEFAULT_OFF
- turn_on_action:
- - switch.turn_on: barn_switch1
- - switch.turn_on: barn_switch2
- turn_off_action:
- - switch.turn_off: barn_switch1
- - switch.turn_off: barn_switch2
- binary_sensor:
- - platform: gpio
- name: "Small Barn Door"
- pin:
- number: 12
- mode:
- input: true
- pullup: true
- inverted: true
- id: barn_door_small
- device_class: door
- # - platform: gpio
- # name: "Light Switch1"
- # id: barn_switch_sensor1
- # pin:
- # number: 23
- # mode:
- # input: true
- # pullup: true
- # inverted: False
- # filters:
- # - settle: 1.5s
- # - delayed_on_off: 1.5s
- # on_state:
- # - if:
- # condition:
- # - switch.is_off:
- # id: barn_switch1
- # then:
- # - switch.turn_on:
- # id: barn_switch1
- # else:
- # - switch.turn_off: barn_switch1
- # - switch.template.publish:
- # id: barn_inside_lights
- # state: OFF
- - platform: gpio
- name: "Light Switch2"
- id: barn_switch_sensor2
- pin:
- number: 14
- mode:
- input: true
- pullup: true
- inverted: true
- filters:
- - settle: 1.5s
- - delayed_on_off: 1.5s
- on_state:
- then:
- - switch.toggle: barn_switch1
- - switch.toggle: barn_switch2
- - platform: status
- id: keypad_status
- name: Barn Keypad Status
- text_sensor:
- - platform: sun
- name: Next Sunrise
- type: sunrise
- id: next_sunrise1
- - platform: sun
- name: Next Sunset
- type: sunset
- id: next_sunset
- - platform: template
- name: "Current Time"
- id: current_time
- update_interval: 5s
- lambda: return id(homeassistant_time).utcnow(); # .now(); ####### .now().strftime("%I%M%p"); #######
- - platform: homeassistant
- entity_id: cover.overhead_door_rf_overhead
- id: ha_cover_state
- name: "Overhead Door"
- internal: false
- - platform: template
- name: Uptime Wg26
- id: uptime_human_wg26
- icon: mdi:clock-start
- - platform: wifi_info
- ip_address:
- name: Keypad IP Address
- ssid:
- name: Keypad Connected SSID
- # mac_address:
- # name: Keypad Mac Address
- scan_results:
- name: Keypad Latest Scan Results
- dns_address:
- name: "dns used"
- - platform: template
- name: "Door Access Method"
- id: door_access_method
- - platform: template
- name: "Alarm State"
- id: alarm_state
- icon: mdi:account-multiple
- - platform: template
- name: Last User
- id: last_user
- icon: mdi:clock-start
- globals:
- - id: method
- type: std::string
- restore_value: yes
- max_restore_data_length: 13
- initial_value: ""
- # Example for global string variable
- - id: last_user_access
- type: std::string
- restore_value: yes
- max_restore_data_length: 13
- initial_value: ""
- - id: temp_code
- type: int
- restore_value: yes
- max_restore_data_length: 4
- initial_value: ""
- sensor:
- - platform: duty_time
- id: small_door_open
- name: "Door Open Time"
- # Support logical sources (optional): 'binary_sensor'
- sensor: barn_door_small
- restore: true # Sensor for last turn-on time (optional)
- last_time:
- name: "Last Time Door Open"
- - platform: template
- name: Keypad Code
- id: keyCode
- on_value:
- - if:
- condition:
- - lambda: 'return id(keyCode).state == 1050;'
- then:
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Justin");
- id(door_access_method ).publish_state("Pin Code");
- }
- - if:
- condition:
- - lambda: 'return id(keyCode).state != 1050;'
- - lambda: 'return id(keyCode).state != 1955;'
- - lambda: 'return id(keyCode).state != 6800;'
- - lambda: 'return id(keyCode).state != 2014;'
- - lambda: 'return id(keyCode).state != id(temp_code);'
- then:
- - text_sensor.template.publish:
- id: last_user
- state: "Invalid Code"
- - if:
- condition:
- - lambda: 'return id(keyCode).state == 6800;'
- then:
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Paula");
- id(door_access_method ).publish_state("Pin Code");
- }
- - if:
- condition:
- - lambda: 'return id(keyCode).state == 1955;'
- then:
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Mike");
- id(door_access_method ).publish_state("Pin Code");
- }
- - if:
- condition:
- - lambda: 'return id(keyCode).state == 2014;'
- then:
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Olive");
- id(door_access_method ).publish_state("Pin Code");
- }
- - if:
- condition:
- and:
- - switch.is_on: guest_active
- - lambda: 'return id(keyCode).state == id(temp_code);'
- then:
- - logger.log: "KeyCode equals temp code!"
- - text_sensor.template.publish:
- id: last_user
- state: "Temp. Code"
- # - lambda: |-
- # if (x == "6789"); {
- # id(ovrhead).toggle();
- # id(last_user).publish_state("Temp. Code");
- # }
- # id(last_user_access) = "Temp Code";
- - if:
- condition:
- and:
- # - alarm_control_panel.is_armed: acp1
- - lambda: 'return id(keyCode).state == 6753957;'
- then:
- # - alarm_control_panel.disarm:
- # id: acp1
- # code: "2014"
- - delay: 1s
- - switch.toggle: ovrhead
- - text_sensor.template.publish:
- id: last_user
- state: "Justin Tag"
- - text_sensor.template.publish:
- id: alarm_state
- state: "Disarmed By Justin"
- else:
- # if:
- # condition:
- # not:
- # - alarm_control_panel.is_armed: acp1
- # then:
- if:
- condition:
- - lambda: 'return id(keyCode).state == 6753957;'
- then:
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Justin");
- id(door_access_method).publish_state("RFID Tag");
- }
- - if:
- condition:
- - lambda: 'return id(keyCode).state == 6422842;'
- then:
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Paula");
- id(door_access_method ).publish_state("RFID Tag");
- }
- - if:
- condition:
- - lambda: 'return id(keyCode).state == 6491970;'
- then:
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Mike");
- id(door_access_method ).publish_state("RFID Tag");
- }
- - if:
- condition:
- - lambda: 'return id(keyCode).state == 5553549;'
- then:
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Golf Cart Key1");
- }
- - if:
- condition:
- - lambda: 'return id(keyCode).state == 5627758;'
- then:
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Golf Cart Key2");
- }
- - platform: wifi_signal
- id: wifi_signal_db
- update_interval: 300s
- entity_category: "diagnostic"
- internal: true
- - platform: copy
- source_id: wifi_signal_db
- name: "WiFi Signal Keypad"
- filters:
- - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
- unit_of_measurement: "Signal %"
- entity_category: "diagnostic"
- id: wifiSignalWG26
- - platform: uptime #Uptime in Seconds
- name: Barn Keypad Uptime
- id: uptime_sensor_wiegand
- update_interval: 240s
- internal: True
- on_raw_value:
- then:
- - text_sensor.template.publish:
- id: uptime_human_wg26
- state: !lambda |-
- int seconds = round(id(uptime_sensor_wiegand).raw_state);
- int days = seconds / (24 * 3600);
- seconds = seconds % (24 * 3600);
- int hours = seconds / 3600;
- seconds = seconds % 3600;
- int minutes = seconds / 60;
- seconds = seconds % 60;
- return (
- (days ? String(days) + "d " : "") +
- (hours ? String(hours) + "h " : "") +
- (minutes ? String(minutes) + "m " : "") +
- (String(seconds) + "s")
- ).c_str();
- wiegand:
- - id: mykeypad
- d0: 21 ## Grn
- d1: 19 ## Wht
- on_key:
- - lambda: ESP_LOGI("KEY", "received key %d", x);
- on_tag:
- - lambda: ESP_LOGI("TAG", "received tag %s", x.c_str());
- - sensor.template.publish:
- id: keyCode
- state: !lambda "return parse_number<float>(x).value();"
- - if:
- condition:
- and:
- - lambda: 'return id(keyCode).state != 5553549;'
- - lambda: 'return id(keyCode).state != 6422842;'
- - lambda: 'return id(keyCode).state != 6491970;'
- - lambda: 'return id(keyCode).state != 6753957;'
- # - lambda: 'return id(keyCode).state != #######;'
- # - lambda: 'return id(keyCode).state != #######;'
- # - lambda: 'return id(keyCode).state != #######;'
- then:
- - text_sensor.template.publish:
- id: last_user
- state: "Invalid Tag Scanned"
- on_raw:
- - lambda: ESP_LOGI("RAW", "received raw %d bits, value %llx", bits, value);
- key_collector:
- - id: pincode_reader
- source_id: mykeypad
- min_length: 4
- max_length: 5
- end_keys: "#"
- end_key_required: true
- clear_keys: "*"
- allowed_keys: "0123456789"
- timeout: 5s
- on_progress:
- - logger.log:
- format: "input progress: '%s', started by '%c'"
- args: [ 'x.c_str()', "(start == 0 ? '~' : start)" ]
- on_result:
- then:
- - sensor.template.publish:
- id: keyCode
- state: !lambda "return parse_number<float>(x).value();"
- on_timeout:
- - logger.log:
- format: "input timeout: '%s', started by '%c'"
- args: [ 'x.c_str()', "(start == 0 ? '~' : start)" ]
- # D1
- light:
- - platform: neopixelbus
- type: RGB
- variant: WS2811
- pin: 17
- num_leds: 20
- id: barn_overhead_led
- name: "Barn Door LED Strip"
- select:
- - platform: template
- id: barn_led_effect
- name: "Barn Light Effect"
- options:
- - "R/W/B"
- - "B/R/W"
- - ""
- initial_option: ""
- optimistic: True
- on_value:
- then:
- if:
- condition:
- - lambda: 'return id(barn_led_effect).state == "R/W/B";'
- then:
- - light.addressable_set:
- id: barn_overhead_led
- range_from: 0
- range_to: 7
- red: 100%
- green: 0%
- blue: 0%
- color_brightness: 100%
- - light.addressable_set:
- id: barn_overhead_led
- range_from: 8
- range_to: 14
- red: 0%
- green: 0%
- blue: 0%
- white: 100%
- color_brightness: 100%
- - light.addressable_set:
- id: barn_overhead_led
- range_from: 15
- range_to: 20
- red: 0%
- green: 0%
- blue: 100%
- color_brightness: 100%
- interval:
- - interval: 1min
- then:
- - if:
- condition:
- and:
- - sun.is_below_horizon:
- - light.is_off:
- id: barn_overhead_led
- then:
- - light.turn_on:
- id: barn_overhead_led
- brightness: 75%
- red: 0%
- green: 0%
- blue: 100%
- - if:
- condition:
- and:
- - sun.is_above_horizon:
- - light.is_on:
- id: barn_overhead_led
- then:
- - light.turn_off:
- id: barn_overhead_led
- - if:
- condition:
- and:
- - sun.is_above_horizon:
- - switch.is_on:
- id: outside_barn_lights
- then:
- - switch.turn_off:
- id: outside_barn_lights
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement