Skip to content

Commit

Permalink
Remove logs from webserver
Browse files Browse the repository at this point in the history
Added running sum counter
  • Loading branch information
ColoMAX committed Jan 16, 2024
1 parent a7a2ef5 commit be657c0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ date: 14-01-2024
# FishFeeder

Standalone automatic fish feeder, based on a ESP8266 with ESPHome.
![](assets/pictures/skyview.png)
![](docs/assets/pictures/skyview.png)

Just dispenses (fish) food using a 3D-printed (archimedean) two flute scew. It uses a modified servo motor to drive the screw, such that it no longer has angle limits. A secondary servo is installed to open a lid of the fish tank, as well as a vibration motor to make the dispenses more consistent. An additional relay can be installed to control some form of lighting.

Expand Down
57 changes: 49 additions & 8 deletions src/fish_feeder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ esphome:
then:
- lambda: |-
id(last_update_str).publish_state(strtok(ctime(&id(last_timestamp)), "\n"));
char fsbuf[15];
snprintf(fsbuf, sizeof(fsbuf), "%.2g", id(feed_sum));
id(feed_sum_str).publish_state(fsbuf);
preferences:
flash_write_interval: 1min

Expand All @@ -29,13 +33,21 @@ captive_portal:

web_server:
port: 80
log: false

globals:
- id: last_timestamp # to keep track of days interval
type: long long
type: time_t
restore_value: true
initial_value: "0"

- id: feed_sum # running total sum of dosages
type: double
restore_value: true
initial_value: "0"
- id: motor_start_time
type: struct timeval
restore_value: false
initial_value: "{0}"
light:
- platform: binary
name: Fish tank light
Expand Down Expand Up @@ -151,7 +163,6 @@ number:
restore_value: true
id: feed_dosage
optimistic: true

button:
- platform: template
name: Manual feed
Expand All @@ -161,7 +172,7 @@ button:
- delay: 500ms
- switch.turn_on: feed_motor
- delay: !lambda |-
return id(feed_dosage).state*1000;
return id(feed_dosage).state*1000; // milliseconds
- switch.turn_off: feed_motor
- switch.turn_on: vib_motor
- delay: 500ms
Expand All @@ -172,7 +183,7 @@ button:
on_press:
- then:
- lambda: |-
id(last_timestamp)=1705273200LL;
id(last_timestamp)=1705273200LL; // start of project
id(last_update_str).publish_state(strtok(ctime(&id(last_timestamp)), "\n"));
id: last_time_btn
switch:
Expand All @@ -185,12 +196,39 @@ switch:
# optimistic: true
turn_on_action:
then:
- lambda: |-
id(sntptime).now().timestamp;
struct timeval tv;
gettimeofday(&tv,NULL);
id(motor_start_time)=tv;
- servo.write:
id: screw_servo
level: -10%
turn_off_action:
then:
- servo.detach: screw_servo
- lambda: |-
# define timeval_diff_macro(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
if ((result)->tv_usec < 0) { \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
} \
} while (0)
id(sntptime).now().timestamp;
struct timeval tv;
struct timeval tvstart = id(motor_start_time);
gettimeofday(&tv,NULL);
timeval_diff_macro(&tv,&tvstart,&tv);
id(feed_sum)+= (double)tv.tv_sec+tv.tv_usec/1000000.0;
char fsbuf[15];
snprintf(fsbuf, sizeof(fsbuf), "%.2g", id(feed_sum));
id(feed_sum_str).publish_state(fsbuf);
- platform: gpio
pin: GPIO14
Expand Down Expand Up @@ -297,9 +335,12 @@ binary_sensor:
- switch.turn_on: factory_reset_switch
internal: true
text_sensor:
platform: template
name: Last time fed (automatically)
id: last_update_str
- platform: template
name: Last time fed (automatically)
id: last_update_str
- platform: template
name: Running sum fed
id: feed_sum_str
time:
- platform: sntp
id: sntptime
Expand Down

0 comments on commit be657c0

Please sign in to comment.