uhma_s-pastebin

PIR plus SSR

Nov 21st, 2020
941
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ####################################################################
  2. # Template Binary Sensor
  3. # see https://esphome.io/components/binary_sensor/template.html
  4. # value TRUE => fallback automation is active
  5.  
  6. # sensor for fallback automation of PIR01
  7.   - platform: template
  8.     name: ${binary_template_sensor_01_name}
  9.     id: ${binary_template_sensor_01_id}
  10.  
  11. # sensor for fallback automation of PIR02
  12.   - platform: template
  13.     name: ${binary_template_sensor_02_name}
  14.     id: ${binary_template_sensor_02_id}
  15.  
  16. ####################################################################
  17. # PIR
  18.  
  19.   - platform: gpio
  20.     name: $pir01_name
  21.     id: ${pir01_id}
  22.     pin:
  23.       mcp23017: ${mcp23017_hub01_id}
  24.       number: !secret MCP23017_PIN_A0
  25.       # mode can be INPUT, INPUT_PULLUP or OUTPUT
  26.       mode: INPUT
  27.       inverted: false
  28.     device_class: motion
  29.  
  30.     # fallback automation while the device is offline:
  31.     on_press:
  32.       then:
  33.         - lambda: |-
  34.             if (!id(${wifi_status_id}).state) {
  35.               id(${binary_template_sensor_01_id}).publish_state(true);
  36.               id(${ssr01_id}).turn_on();
  37.             }
  38.         - delay: !secret DELAY_01MIN
  39.         - lambda: |-
  40.             if (id(${binary_template_sensor_01_id}).state) {
  41.               id(${ssr01_id}).turn_off();
  42.               id(${binary_template_sensor_01_id}).publish_state(false);
  43.             }
  44.  
  45.   - platform: gpio
  46.     name: $pir02_name
  47.     id: ${pir02_id}
  48.     pin:
  49.       mcp23017: ${mcp23017_hub01_id}
  50.       number: !secret MCP23017_PIN_A1
  51.       # mode can be INPUT, INPUT_PULLUP or OUTPUT
  52.       mode: INPUT
  53.       inverted: false
  54.     device_class: motion
  55.  
  56.     # fallback automation while the device is offline:
  57.     #  - the impuls from the PIR is short
  58.     #  - race condition seem to occur
  59.     #    - to be observed weird behaviour when motion appears seemingly repeatedly during the delay
  60.     on_press:
  61.       then:
  62.         - lambda: |-
  63.             if (!id(${wifi_status_id}).state) {
  64.               if (!id(${ssr01_id}).state) {
  65.                 id(${binary_template_sensor_01_id}).publish_state(true);
  66.                 id(${ssr01_id}).turn_on();
  67.               }
  68.             }
  69.         - delay: !secret DELAY_01MIN
  70.         - lambda: |-
  71.             if (id(${binary_template_sensor_01_id}).state) {
  72.               id(${ssr01_id}).turn_off();
  73.               id(${binary_template_sensor_01_id}).publish_state(false);
  74.             }
  75.  
RAW Paste Data