Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- esphome:
- name: kitchen-basecabinet
- on_boot:
- then:
- - wait_until:
- condition:
- api.connected:
- timeout: 10s
- - mqtt.publish_json:
- topic: kitchen-basecabinet/status
- payload: |-
- root["kitchen_water1_state"] = id(kitchen_water1).state;
- root["greeting"] = "On_boot api_connected.";
- esp8266:
- board: d1_mini
- # restore_from_flash: true
- # Enable logging
- logger:
- level: INFO
- # Enable Home Assistant API
- api:
- ota:
- password: "deleted"
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- # Optional manual IP
- manual_ip:
- static_ip: 192.168.4.126
- gateway: 192.168.4.1
- subnet: 255.255.255.0
- # Enable fallback hotspot (captive portal) in case wifi connection fails
- ap:
- ssid: "kitchen-basecabinet Hotspot"
- password: "deleted"
- mqtt:
- broker: !secret mqtt_broker
- username: !secret mqtt_user
- password: !secret mqtt_password
- discovery_prefix: homeassistant
- captive_portal:
- globals:
- - id: end_pulse_count
- type: float
- restore_value: no
- initial_value: '0'
- # Text sensors with general information.
- text_sensor:
- - platform: wifi_info
- ip_address:
- name: kitchen_basecabinet_ip
- # Sensors with general information.
- sensor:
- - platform: uptime
- name: kitchen_basecabinet_uptime
- update_interval: 600s
- expire_after: 660s
- - platform: homeassistant
- name: "Requested Amount"
- id: "requested_amount"
- entity_id: input_number.water_amount
- on_value:
- then:
- - mqtt.publish_json:
- topic: kitchen-basecabinet/status
- payload: |-
- root["requested_amount"] = id(requested_amount).state;
- root["greeting"] = "New amount detected.";
- - sensor.template.publish:
- id: "requested_amount_sensor"
- state: !lambda 'return id(requested_amount).state;'
- - platform: template
- name: "Requested Amount Sensor"
- id: "requested_amount_sensor"
- lambda: !lambda |-
- return id(requested_amount).state;
- - platform: pulse_counter
- pin: D5
- name: "Pulse Rate"
- update_interval: 100ms
- unit_of_measurement: 'pulses/min'
- filters:
- - or:
- - throttle: 30s
- - delta: 1.0
- total:
- unit_of_measurement: 'pulses'
- name: 'pulses counted'
- id: "pulses_counted"
- filters:
- - multiply: 1
- - or:
- - throttle: 30s
- - delta: 1.0
- switch:
- - platform: gpio
- name: "kitchen_water1"
- id: "kitchen_water1"
- pin:
- number: D6
- inverted: true
- on_turn_on:
- then:
- - mqtt.publish_json:
- topic: kitchen-basecabinet/status
- payload: |-
- root["kitchen_water1_state"] = id(kitchen_water1).state;
- root["pulses_counted_state"] = id(pulses_counted).state;
- root["greeting"] = "Switch turn_on detected.";
- on_turn_off:
- then:
- - mqtt.publish_json:
- topic: kitchen-basecabinet/status
- payload: |-
- root["kitchen_water1_state"] = id(kitchen_water1).state;
- root["pulses_counted_state"] = id(pulses_counted).state;
- root["greeting"] = "Switch turn_off detected.";
- - platform: restart
- name: "kitchen_basecabinet Restart"
- # Button
- binary_sensor:
- - platform: gpio
- pin:
- number: D7
- mode: INPUT_PULLUP
- inverted: True
- name: "button1"
- on_press:
- then:
- - if:
- condition:
- switch.is_on: kitchen_water1
- then:
- - switch.turn_off: kitchen_water1
- - mqtt.publish_json:
- topic: kitchen-basecabinet/status
- payload: |-
- root["kitchen_water1_state"] = id(kitchen_water1).state;
- root["pulses_counted_state"] = id(pulses_counted).state;
- root["greeting"] = "Water turned off by button press.";
- else:
- - lambda: |-
- ESP_LOGD("main", "Starting pulses (.state) equals %f", id(pulses_counted).state);
- - lambda: |-
- ESP_LOGD("main", "Requested amount equals %f", id(requested_amount).state);
- - globals.set:
- id: end_pulse_count
- value: !lambda return (id(pulses_counted).state) + (id(requested_amount).state);
- - switch.turn_on: kitchen_water1
- - mqtt.publish_json:
- topic: kitchen-basecabinet/status
- payload: |-
- root["kitchen_water1_state"] = id(kitchen_water1).state;
- root["greeting"] = "Water turned on by button press.";
- - lambda: |-
- ESP_LOGD("main", "Stopping pulses equals %f", id(end_pulse_count));
- - wait_until:
- condition:
- lambda: |-
- return id(pulses_counted).state >= id(end_pulse_count);
- - mqtt.publish_json:
- topic: kitchen-basecabinet/status
- payload: |-
- root["kitchen_water1_state"] = id(kitchen_water1).state;
- root["pulses_counted_state"] = id(pulses_counted).state;
- root["greeting"] = "Pulse count reached.";
- - lambda: |-
- ESP_LOGD("main", "Stopping pulses (wait until) equals %f", id(end_pulse_count));
- - switch.turn_off: kitchen_water1
- - mqtt.publish_json:
- topic: kitchen-basecabinet/status
- payload: |-
- root["kitchen_water1_state"] = id(kitchen_water1).state;
- root["pulses_counted_state"] = id(pulses_counted).state;
- root["greeting"] = "Water turned off when pulse count reached.";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement