Advertisement
steve2982

Untitled

Jul 30th, 2023 (edited)
1,301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 5.94 KB | None | 0 0
  1. esphome:
  2.   name: kitchen-basecabinet
  3.   on_boot:
  4.     then:
  5.       - wait_until:
  6.           condition:
  7.             api.connected:
  8.           timeout: 10s
  9.       - mqtt.publish_json:
  10.           topic: kitchen-basecabinet/status
  11.           payload: |-
  12.             root["kitchen_water1_state"] = id(kitchen_water1).state;
  13.             root["greeting"] = "On_boot api_connected.";
  14.  
  15. esp8266:
  16.   board: d1_mini
  17. #  restore_from_flash: true
  18.  
  19. # Enable logging
  20. logger:
  21.   level: INFO
  22.  
  23. # Enable Home Assistant API
  24. api:
  25. ota:
  26.   password: "deleted"
  27.  
  28. wifi:
  29.   ssid: !secret wifi_ssid
  30.   password: !secret wifi_password
  31.  
  32. # Optional manual IP
  33.   manual_ip:
  34.     static_ip: 192.168.4.126
  35.     gateway: 192.168.4.1
  36.     subnet: 255.255.255.0
  37.  
  38. # Enable fallback hotspot (captive portal) in case wifi connection fails
  39.   ap:
  40.     ssid: "kitchen-basecabinet Hotspot"
  41.     password: "deleted"
  42.  
  43. mqtt:
  44.   broker: !secret mqtt_broker
  45.   username: !secret mqtt_user
  46.   password: !secret mqtt_password
  47.   discovery_prefix: homeassistant
  48.  
  49. captive_portal:
  50. globals:
  51.   - id: end_pulse_count
  52.     type: float
  53.     restore_value: no
  54.     initial_value: '0'
  55.    
  56. # Text sensors with general information.
  57. text_sensor:
  58.   - platform: wifi_info
  59.     ip_address:
  60.       name: kitchen_basecabinet_ip
  61.  
  62. # Sensors with general information.
  63. sensor:
  64.   - platform: uptime
  65.     name: kitchen_basecabinet_uptime
  66.     update_interval: 600s
  67.     expire_after: 660s
  68.  
  69.   - platform: homeassistant
  70.     name: "Requested Amount"
  71.     id: "requested_amount"
  72.     entity_id: input_number.water_amount
  73.     on_value:
  74.       then:
  75.         - mqtt.publish_json:
  76.             topic: kitchen-basecabinet/status
  77.             payload: |-
  78.               root["requested_amount"] = id(requested_amount).state;
  79.               root["greeting"] = "New amount detected.";
  80.         - sensor.template.publish:
  81.             id: "requested_amount_sensor"
  82.             state: !lambda 'return id(requested_amount).state;'
  83.      
  84.   - platform: template
  85.     name: "Requested Amount Sensor"
  86.     id: "requested_amount_sensor"
  87.     lambda: !lambda |-
  88.       return id(requested_amount).state;
  89.  
  90.   - platform: pulse_counter
  91.     pin: D5
  92.     name: "Pulse Rate"
  93.     update_interval: 100ms
  94.     unit_of_measurement: 'pulses/min'
  95.     filters:
  96.       - or:
  97.         - throttle: 30s
  98.         - delta: 1.0
  99.     total:
  100.       unit_of_measurement: 'pulses'
  101.       name: 'pulses counted'
  102.       id: "pulses_counted"
  103.       filters:
  104.         - multiply: 1  
  105.         - or:
  106.           - throttle: 30s
  107.           - delta: 1.0
  108.  
  109.  
  110. switch:
  111.   - platform: gpio
  112.     name: "kitchen_water1"
  113.     id: "kitchen_water1"
  114.     pin:
  115.       number: D6
  116.       inverted: true
  117.     on_turn_on:
  118.       then:
  119.         - mqtt.publish_json:
  120.             topic: kitchen-basecabinet/status
  121.             payload: |-
  122.               root["kitchen_water1_state"] = id(kitchen_water1).state;
  123.               root["pulses_counted_state"] = id(pulses_counted).state;
  124.               root["greeting"] = "Switch turn_on detected.";
  125.     on_turn_off:
  126.       then:
  127.         - mqtt.publish_json:
  128.             topic: kitchen-basecabinet/status
  129.             payload: |-
  130.               root["kitchen_water1_state"] = id(kitchen_water1).state;
  131.               root["pulses_counted_state"] = id(pulses_counted).state;
  132.               root["greeting"] = "Switch turn_off detected.";
  133.    
  134.   - platform: restart
  135.     name: "kitchen_basecabinet Restart"
  136.    
  137. # Button      
  138. binary_sensor:
  139.   - platform: gpio
  140.     pin:
  141.       number: D7
  142.       mode: INPUT_PULLUP
  143.       inverted: True
  144.     name: "button1"
  145.     on_press:
  146.       then:
  147.         - if:
  148.             condition:
  149.               switch.is_on: kitchen_water1
  150.             then:
  151.               - switch.turn_off: kitchen_water1
  152.               - mqtt.publish_json:
  153.                   topic: kitchen-basecabinet/status
  154.                   payload: |-
  155.                     root["kitchen_water1_state"] = id(kitchen_water1).state;
  156.                     root["pulses_counted_state"] = id(pulses_counted).state;
  157.                     root["greeting"] = "Water turned off by button press.";
  158.  
  159.  
  160.             else:
  161.               - lambda: |-
  162.                   ESP_LOGD("main", "Starting pulses (.state) equals %f", id(pulses_counted).state);
  163.               - lambda: |-
  164.                   ESP_LOGD("main", "Requested amount equals %f", id(requested_amount).state);
  165.               - globals.set:
  166.                   id: end_pulse_count
  167.                   value: !lambda return (id(pulses_counted).state) + (id(requested_amount).state);
  168.               - switch.turn_on: kitchen_water1
  169.               - mqtt.publish_json:
  170.                   topic: kitchen-basecabinet/status
  171.                   payload: |-
  172.                     root["kitchen_water1_state"] = id(kitchen_water1).state;
  173.                     root["greeting"] = "Water turned on by button press.";
  174.               - lambda: |-
  175.                   ESP_LOGD("main", "Stopping pulses equals %f", id(end_pulse_count));
  176.               - wait_until:
  177.                   condition:
  178.                     lambda: |-
  179.                       return id(pulses_counted).state >= id(end_pulse_count);
  180.               - mqtt.publish_json:
  181.                   topic: kitchen-basecabinet/status
  182.                   payload: |-
  183.                     root["kitchen_water1_state"] = id(kitchen_water1).state;
  184.                     root["pulses_counted_state"] = id(pulses_counted).state;
  185.                     root["greeting"] = "Pulse count reached.";
  186.               - lambda: |-
  187.                   ESP_LOGD("main", "Stopping pulses (wait until) equals %f", id(end_pulse_count));
  188.               - switch.turn_off: kitchen_water1
  189.               - mqtt.publish_json:
  190.                   topic: kitchen-basecabinet/status
  191.                   payload: |-
  192.                     root["kitchen_water1_state"] = id(kitchen_water1).state;
  193.                     root["pulses_counted_state"] = id(pulses_counted).state;
  194.                     root["greeting"] = "Water turned off when pulse count reached.";
  195.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement