-
Notifications
You must be signed in to change notification settings - Fork 0
/
cat-feeder.yaml
154 lines (138 loc) · 5.02 KB
/
cat-feeder.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#/usr/share/hassio/homeassistant/esphome$ esphome logs kitchen-ctrl-center.yaml
# After motor starts
# if
# count at least 3 detections
# else empty
esphome:
name: cat-feeder
esp8266:
board: d1_mini_lite
# Enable logging
logger:
logs:
sensor: ERROR
# Enable Home Assistant API
api:
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Cat-Feeder Fallback Hotspot"
password: "w4NEJmdIsly4"
captive_portal:
globals:
- id: food_detection_count_global
type: int
restore_value: no
initial_value: '0'
- id: feeding_cycle_running_global
type: int
initial_value: '0'
sensor:
- platform: template
id: food_detection_count
name: Food Detection Count
- platform: template
id: feeding_cycle_running
name: Feeding Cycle Running
- platform: template
id: feed_detection
- platform: adc
pin: A0 # connect this to the top of the petkit circuit board label "food det"
id: food_detect
update_interval: 0.3s
on_value:
then:
- if:
condition:
- binary_sensor.is_on: motor_sense # We're feeding
# if Food is in the way, the detector rises to 1.0v. No food == 0.0v
- lambda: |-
if (id(food_detect).state >= 0.5) {
return true;
} else {
return false;
}
then:
- lambda: 'id(food_detection_count_global) += 1;'
- lambda: id(food_detection_count).publish_state(id(food_detection_count_global));
- logger.log:
format: "FOOD DETECTED!!!! food_detection_count (should increment)= %d"
args: ['id(food_detection_count).state']
- logger.log:
format: "FOOD DETECTED!!!! COUNT food_detection_count_global (should increment)= %d"
args: ['id(food_detection_count_global)']
- if:
condition:
- binary_sensor.is_on: motor_sense # We're feeding
- lambda: |-
if (id(food_detection_count).state >= 2) {
return true;
} else {
return false;
}
then:
- logger.log: "FEEDING OK - PLENTY OF FOOD DETECTED!!!!"
- lambda: id(food_detection_count).publish_state(id(food_detection_count_global));
- lambda: id(feeding_ok_flag).publish_state(true); #Set the state of a SENSOR
binary_sensor:
- platform: template
id: cycle_running
- platform: template
id: feeding_ok_flag
name: Feeding ok flag
- platform: gpio
id: motor_sense
name: Motor Sense
filters:
- delayed_on: 1.5s #it pulses once before feeding. unsure why.
# - delayed_off: 1s
pin:
number: D7 #connect this to the union of the zener/resistor on the motor
inverted: false
mode:
input: true
pullup: false
on_press:
then:
- if:
condition:
- binary_sensor.is_on: motor_sense # MOTOR is ON. We're feeding
then:
- logger.log: "**MOTOR ON BEGIN feeding ***"
- globals.set:
id: feeding_cycle_running_global
value: '1'
- lambda: id(feeding_cycle_running).publish_state(id(feeding_cycle_running_global));
- logger.log:
format: "motor_sense.on_PRESS. FEEDING CYCLE RUNNING SENSOR (shoud be 1)= %f "
args: ['id(feeding_cycle_running).state']
on_release:
then:
- logger.log: "***MOTOR NOT RUNNING -- END feeding***"
- if:
condition:
- lambda: |-
if (id(food_detection_count).state <= 3) {
return true;
} else {
return false;
}
then:
- lambda: id(feeding_ok_flag).publish_state(0); # out of food
- logger.log: "FEEDING FAILED. OUT OF FOOD"
- delay: 2s
- globals.set:
id: feeding_cycle_running_global
value: '0'
- delay: 2s
- globals.set:
id: food_detection_count_global
value: '0'
- lambda: id(food_detection_count).publish_state(0); #Set the state of a SENSOR
- lambda: id(feeding_cycle_running).publish_state(id(feeding_cycle_running_global));
- logger.log:
format: "motor_sense.on_RELEASE. FEEDING CYCLE RUNNING SENSOR (should be 0) = %f"
args: ['id(feeding_cycle_running).state']