Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- captive_portal:
- web_server:
- port: 80
- version: 3
- auth:
- username: "Justin"
- password: "Olive2014"
- ################ 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_mode1_start
- # type: time
- # name: "Guest Mode 1 Start"
- # optimistic: yes
- # initial_value: "08:00:00"
- # restore_value: true
- # on_time:
- # - if:
- # condition:
- # - switch.is_on: guest1_active
- # then:
- # - switch.turn_on: guest1_active
- # - platform: template
- # id: guest_mode1_stop
- # type: time
- # name: "Guest Mode 1 Stop"
- # 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: guest1_active
- # then:
- # - button.press: transmit_rf
- # else:
- # - switch.turn_off: guest1_active
- - platform: template
- id: guest1_start_date
- type: datetime
- name: "Guest 1 Start"
- optimistic: yes
- # initial_value: lambda: auto id(homeassistant_time).state_as_esptime();
- restore_value: false
- - platform: template
- id: guest1_stop_date
- type: datetime
- name: "Guest 1 Stop"
- optimistic: true
- # initial_value: lambda: |-
- # return auto time = id(homeassistant_time).now();
- restore_value: true
- # - platform: template
- # id: guest_mode2_start
- # type: time
- # name: "Guest 2 Start"
- # optimistic: yes
- # initial_value: "08:00:00"
- # restore_value: true
- # on_time:
- # - if:
- # condition:
- # - switch.is_on: guest2_active
- # then:
- # - switch.turn_on: guest2_active
- number:
- - platform: template
- name: "Guest 1 Code"
- id: guest1_keypad_code
- min_value: 0
- max_value: 9999
- step: 1
- mode: box
- restore_value: false
- optimistic: true
- on_value:
- if:
- ## Guest1 Switch MUST be ON in order to set a Pin Code.
- condition:
- - switch.is_on: guest1_active
- then:
- - globals.set:
- id: temp_code
- value: !lambda 'return float(x);'
- - text_sensor.template.publish:
- id: guest_1_pin
- state: !lambda 'return id(guest1_keypad_code).state;'
- ## Guest 2... This is only commented out because I likely wont use it and it's to de-clutter things while ## this is still a work in progress. You can make as many Guest modes as you want/need though. You just need ## to also add the related sensors and entites necessarry for each additional one.
- # - platform: template
- # name: "Guest 2 Code"
- # id: guest2_keypad_code
- # min_value: 0
- # max_value: 9999
- # step: 1
- # mode: box
- # restore_value: false
- # optimistic: true
- # on_value:
- # if:
- # condition:
- # - switch.is_on: guest2_active
- # then:
- # - globals.set:
- # id: temp_code
- # value: !lambda 'return float(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
- ## Where do you want the ESP to sync up with for keeping the Time accurate. I use HA but, there are others.
- time:
- - platform: homeassistant
- id: homeassistant_time
- ## Remote Transmitter is unrelated and it's more for my specific setup. My thinking was to use it as a backup ## method to toggle overhead door because my Keypad isn't physically wired to the overhead door motor and ## this is to send an RF_Switch signal to my esp board that is wired to the motor and is incase the WiFi goes ## down and Keypad can't communicate with door motor. This is my backup 433mhz P2P option. ##
- remote_transmitter:
- pin: 4
- carrier_duty_percent: 100%
- #### THIS IS FROM ME TESTING/PLAYING WITH DOING SOME RF433 MHZ STUFF MENTIONED ABOVE AND IS NOT NEEDED ###
- ## THIS IS HOW YOU CAN SEND INDIVIDUAL DIGITS OR A STRING OF THEM(PIN CODE) TO YOUR KEYPAD FROM A DIFFERENT ESP BOARD FYI..... IT ISN'T USED FOR THIS KEYPAD UI AND CAN BE REMOVED OR COMMENTED OUT.
- button:
- - platform: template
- name: "test send number"
- id: test_keysend
- on_press:
- then:
- - lambda: |-
- id(pincode_reader).send_key('4');
- - delay: 250ms
- - lambda: |-
- id(pincode_reader).send_key('3');
- - delay: 250ms
- - lambda: |-
- id(pincode_reader).send_key('2');
- - delay: 250ms
- - lambda: |-
- id(pincode_reader).send_key('1');
- - 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
- ### END OF RF 433 MHZ TESTING STUFF ##################
- - platform: restart
- id: keypad_restart
- name: "Keypad Restart"
- - platform: safe_mode
- id: keypad_safemode
- name: "Keypad (Safe Mode)"
- switch:
- - platform: template
- id: guest1_active
- name: "Guest Mode 1"
- optimistic: True
- restore_mode: DISABLED
- on_turn_off:
- then:
- - number.set:
- id: guest1_keypad_code
- value: 0
- # - platform: template
- # id: guest2_active
- # name: "Guest Mode 2"
- # optimistic: True
- # restore_mode: DISABLED
- # on_turn_off:
- # then:
- # - number.set:
- # id: guest2_keypad_code
- # value: 0
- ## THIS IMPORTS MY DOOR COVER FROM HA SINCE IT'S ON A DIFFERNT ESP BOARD.
- - platform: template
- id: ovrhead
- optimistic: true
- on_turn_on:
- - homeassistant.service:
- service: switch.toggle
- data:
- entity_id: switch.overhead_door_rf_barn_overhead_door
- ## SWITCH TO TURN ON THE INTERIOR LIGHTS FOR GARAGE. ##
- - platform: gpio
- pin:
- number: 25
- inverted: False
- name: 'Barn Door Lights'
- id: outside_barn_lights
- restore_mode: RESTORE_DEFAULT_OFF
- - 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
- ## THIS JUST COMBINES LIGHT SWITCH 1&2 INTO A SINGLE LIGHT SWITCH. SIMILAR TO A "GROUP" IN HA. ##
- - platform: template
- name: "Barn Lights"
- id: barn_inside_lights
- optimistic: true
- restore_mode: RESTORE_DEFAULT_ON
- 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:
- #### EXTRA SENSORS NOT NECESSARY FOR KEYPAD ###########
- - 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 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_inside_lights
- ### A STATUS SENSOR IS HANDY TO HAVE BUT ISN'T NECESSARY FOR KEYPAD ######
- - platform: status
- id: keypad_status
- name: Barn Keypad Status
- text_sensor:
- - platform: template
- id: newest_user
- name: "New Keypad User"
- ## SUNRISE/SUNSET INFO ISN'T NEEDED AND JUST SOMETHING I USE BUT, IT CAN BE REMOVED WITH 0 ISSUE.
- - platform: sun
- name: Next Sunrise
- type: sunrise
- id: next_sunrise1
- - platform: sun
- name: Next Sunset
- type: sunset
- id: next_sunset
- - 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"
- ## The "door access method" displays whether someone used a Pin code or scanned an RFID tag. ###
- - platform: template
- name: "Door Access Method"
- id: door_access_method
- ### Guest1 pin will display what you have set as the pin code if you have turned on Guest mode 1. ###
- - platform: template
- name: "Guest 1 Pin #"
- id: guest_1_pin
- icon: mdi:account-plus
- ## Combining an Alarm with the Keypad is just something i was messing with and isn't setup currently and ## isn't needed at all on the devices running your keypad. ##
- - platform: template
- name: "Alarm State"
- id: alarm_state
- icon: mdi:account-multiple
- ## Last User displays the last User Name that accessed the Keypad with either a Pin or RFID tag.
- - platform: template
- name: "Last User"
- id: last_user
- icon: mdi:clock-start
- ## Displays the name you assigned for Guest 1 ##
- - platform: template
- name: "Assigned Guest"
- id: assigned_guest_1
- icon: mdi:account-plus
- ## This is the Text Input box for assigning a name for Guest 1 ###
- text:
- - platform: template
- id: guest_1_name
- name: "Guest 1 Name"
- restore_value: True
- mode: text
- optimistic: true
- on_value:
- - if:
- condition:
- - switch.is_on: guest1_active
- then:
- - text_sensor.template.publish:
- id: assigned_guest_1
- state: !lambda 'return x.c_str();'
- - globals.set:
- id: guest_1
- value: !lambda 'return x.c_str();'
- ## The "Create New User" feature isn't complete and i'm still messing with it. It's easy to add users via the ## Esphome config and then flash the board to add something new but, the intended goal of this UI was to do ## everything from the Homeassistant UI and this isn't a complete feature yet, sorry. ##
- - platform: template
- id: create_new_user
- name: "Create New User"
- mode: text
- restore_value: True
- optimistic: true
- on_value:
- then:
- - text_sensor.template.publish:
- id: newest_user
- state: !lambda 'return x.c_str();'
- - globals.set:
- id: new_user_created
- value: !lambda 'return x.c_str();'
- ### These are the globals that store sensor states and for some reason the states are not surviving after ## rebooting the esp board and is still in progress. Globals will stay for days/weeks as long as there isn't ## a reboot, at least temporarily. ##
- globals:
- - id: method
- type: std::string
- restore_value: yes
- max_restore_data_length: 13
- initial_value: ""
- - id: last_user_access
- type: std::string
- restore_value: yes
- max_restore_data_length: 13
- initial_value: ""
- - id: new_user_created
- 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: 5
- initial_value: ""
- - id: guest_1
- type: std::string
- restore_value: yes
- max_restore_data_length: 8
- initial_value: ""
- sensor:
- ## Timestamp for different actions that happen. ##
- - platform: template
- name: "Display Timestamp"
- device_class: timestamp
- id: keypad_timestamp
- ## This is for a smaller/man door that has a Reed switch installed on it. This is just a dutyf_time sensor ## that shows me how long the door was open.
- - 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"
- ## This is a sensor that displays the last Pin code someone entered whether it is correct or incorrect. ##
- ## All of these "if" statements under (id: keyCode) are what makes up the Keypad's logic and is where you ## need to create any "Master" Usernames like yourself and anyone else that lives there or you anticipate to ## have access indefinately like children or family members for example. ##
- - platform: template
- name: Keypad Code
- id: keyCode
- on_value:
- - if:
- condition:
- and:
- ## This condition checks the code that was entered against a number/pincode from a list of saved
- ## pin codes that do have access and work.
- ## if none match..... 1050, 1955, 6800, etc, etc.
- - 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);'
- - lambda: 'return id(keyCode).state != id(guest1_keypad_code).state;'
- then:
- ## No Match then it Publishes "Invalid Code" as "keypad_code" entity. I do plan to add a UI configurable ## limit for incorrect codes entered and then followed by a timout/cool down period where pincodes wont be ## accepted for a certain amount of time that i have set via UI. You could even incorporate a function to ## send you a notification of X number of wrong pincodes being entered so that police or someone can be ## alerted to the situation/problem..... Stay Tuned for that feature and more LOL. ##
- - text_sensor.template.publish:
- id: last_user
- state: "Invalid Code Entered"
- - if:
- ## IF this matches a specific Pincode "1050"
- condition:
- - lambda: 'return id(keyCode).state == 1050;'
- then:
- ## This first "if statement" above and the lambda, this is how i setup each person/user.
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Justin");
- id(door_access_method ).publish_state("Pin Code");
- }
- - lambda: 'return id(keypad_timestamp).publish_state(id(homeassistant_time).now().timestamp);'
- ## If True then Toggle "overhead" which is my Cover for overhead door.
- ## Then publishes the person/user name who's pin code is 1050
- ## publish the method as far as Pincode or RFID tag that "Justin" used to access the door via
- ## keypad codes entered or rfid tags scanned or even Alarm issues.
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Justin");
- id(door_access_method ).publish_state("PinCode);
- ## Create a TimeStamp for a code entered and opened the door.
- - lambda: 'return id(keypad_timestamp).publish_state(id(homeassistant_time).now().timestamp);'
- ### These are just more of the example above and you need 1 of these ( - if: ) statements for each user you ## intend to create. You do not need to repeat the list of user codes like above. That list is checked each ## time a Pincode is typed on the Keypad and only needs added in here 1 time. ##
- - 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");
- }
- - lambda: 'return id(keypad_timestamp).publish_state(id(homeassistant_time).now().timestamp);'
- - 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");
- }
- - lambda: 'return id(keypad_timestamp).publish_state(id(homeassistant_time).now().timestamp);'
- - 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");
- }
- - lambda: 'return id(keypad_timestamp).publish_state(id(homeassistant_time).now().timestamp);'
- - if:
- condition:
- and:
- ## Guest1 and Guest2 Pincodes only work if the switch is toggled ON and here is that logic that will ## allow or deny a Pincode currently in use or one that was used in the past. Guest1/2 mode must be turned ## ON. ##
- - switch.is_on: guest1_active
- - lambda: 'return id(keyCode).state == id(guest1_keypad_code).state;'
- then:
- - logger.log: "Guest 1 Code Accepted!"
- - text_sensor.template.publish:
- id: last_user
- state: !lambda 'return id(assigned_guest_1).state;'
- - lambda: |-
- {
- id(ovrhead).toggle();
- id(last_user).publish_state("Olive");
- id(door_access_method ).publish_state("Pin Code");
- }
- - lambda: 'return id(keypad_timestamp).publish_state(id(homeassistant_time).now().timestamp);'
- - if:
- condition:
- and:
- - switch.is_on: guest2_active
- - lambda: 'return id(keyCode).state == id(guest2_keypad_code).state;'
- then:
- - logger.log: "Guest 2 Code Accepted!"
- - text_sensor.template.publish:
- id: last_user
- state: "Guest 2 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: 18 ## 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"
- effects:
- - random:
- - random:
- name: Random Colors
- transition_length: 5s
- update_interval: 15s
- 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