本帖最后由 hugh_jie 于 2019-11-29 22:23 编辑
自从养了狗子,周末的懒觉都睡不成了,于是想偷偷懒搞个定时喂狗的东西,虽说网上一大堆机器,但对于一个diy上瘾的人来说还是自己搞比较有意思...成品长这样:
大概图形原理:
其实一开始的设想是做成这样:
这样的好处是可以一次倒进去很多,可以根据槽子的容积自动定量喂食,奈何理想很丰满~~转动的时候会卡狗粮~~无奈改成了现有的方案,不过能省一次算一次咯
配置用的esphome官方配置:链接
esphome:
name: servos
platform: ESP8266
board: nodemcuv2
wifi:
ssid: "wifi"
password: "密码"
manual_ip:
static_ip: 192.168.0.222
gateway: 192.168.0.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Servos Fallback Hotspot"
password: "VYTOwxqxxlOT"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
services:
- service: control_servo
variables:
level: float
then:
- servo.write:
id: my_servo
level: !lambda 'return level / 100.0;'
ota:
binary_sensor:
- platform: gpio
pin: D2
name: "手动喂狗"
on_state:
then:
- servo.write:
id: my_servo
level: -100.0%
- delay: 2s
- servo.write:
id: my_servo
level: 0%
servo:
- id: my_servo
output: pwm_output
# Example output platform
# On ESP32, use ledc output
output:
- platform: esp8266_pwm
id: pwm_output
pin: D5
frequency: 50 Hz
复制代码
HA配置:input_number: #喂狗
servo_control:
name: Servo Control
initial: 0
min: -100
max: 100
step: 1
mode: slider
automation:
- alias: Write Servo Value to ESP
trigger:
platform: state
entity_id: input_number.servo_control
action:
# Replace livingroom with the name you gave the ESP
- service: esphome.servos_control_servo
data_template:
level: '{{ states(''input_number.servo_control'') | int }}'
测试调用服务esphome.servos _control_servo,填level:-100就是反转90度,0是复位,100正转90度,自动化应该很简单,不过我用的node-red更简单所以就不贴啦
另外有大佬试过nodemcu控制两个舵机么,,我试了一下esphome两个同时接入会互相干扰,很无奈,目前想的是用手上的arduino搞,不过完全没研究过那个。。
加了个手动开关,,不知道有啥用,或者突然断网了手动喂一下?
这东西放在生活阳台,,,wifi好像有点不太好,老是失联,索性改成esphome定时算了,,有需要esp时间方面自动化的可以参考一下:Time
time:
- platform: homeassistant
id: homeassistant_time
timezone: Asia/Shanghai
on_time:
- seconds: 0
minutes: 30
hours: 8
days_of_week: MON-SUN
then:
- servo.write:
id: my_servo
level: -100.0%
- delay: 2s
- servo.write:
id: my_servo
level: 0%
- seconds: 0
minutes: 0
hours: 12
days_of_week: MON-SUN
then:
- servo.write:
id: my_servo
level: -100.0%
- delay: 2s
- servo.write:
id: my_servo
level: 0%
- seconds: 0
minutes: 30
hours: 18
days_of_week: MON-SUN
then:
- servo.write:
id: my_servo
level: -100.0%
- delay: 2s
- servo.write:
id: my_servo
level: 0%
复制代码
直接加在上面的配置后面,从HA同步时间,然后定时执行