二、进去之后点edit进入编辑界面,代码“captive_portal:”及之前的内容都不用修改。在之后增加下面的代码:
status_led:
pin: GPIO16
globals:
- id: auto_gl
type: int
restore_value: yes
initial_value: "1"
binary_sensor:
- platform: gpio
pin:
number: 13
inverted: true
name: "paicha_B1"
device_class: motion
id: "paicha_B1"
on_click:
- min_length: 50ms
max_length: 1000ms
then:
- if:
condition:
lambda: 'return id(paicha_auto).state ;'
then:
- switch.toggle: "paicha_relay"
- min_length: 5000ms
max_length: 10000ms
then:
- switch.toggle: 'paicha_auto'
light:
- platform: binary
output: light_output
name: "blue_led"
id: "paicha_blue_led"
output:
- id: light_output
platform: gpio
pin: GPIO12
switch:
- platform: gpio #继电器
pin: GPIO14
name: "relay"
id: "paicha_relay"
on_turn_on:
then:
- light.turn_on: "paicha_blue_led"
on_turn_off:
then:
- light.turn_off: "paicha_blue_led"
- platform: template
name: "auto"
id: "paicha_auto"
turn_on_action:
then:
- lambda: |-
id(auto_gl)=1;
ESP_LOGD("main", "I am at execution number %d", id(auto_gl));
turn_off_action:
then:
- lambda: |-
id(auto_gl)=0;
ESP_LOGD("main", "I am at execution number %d", id(auto_gl));
lambda: |-
return id(auto_gl);
粘贴代码之后格式是不正确的,直接编译要报错,原因在于代码复制粘贴后对齐被改变了。需要自己手动把代码对齐一下,对齐的要求按照C语言对代码对齐的要求。不清楚的网上自己找下C语言教程,不需要学得太深,简单的了解变量命名规则和代码对齐规则就够用了。
现在功能就齐全了,再次申明,我基本上就是个搬运工,只是分享点折腾经验帮助新手兄弟们少走点弯路。
|