本帖最后由 dizherui 于 2018-8-25 21:37 编辑
这并不是教程,而是我目前装修过程中是如何实现和遇到问题
材料:
12V 25A电源
12V双排铝基灯带
MOS调压模块
ESP8266
BH1750光线模块
不好意思,整赶上这几天家里有事,没来的更新,今晚有空的话,马上就更新
求大神解救代码问题,怎么写会更好;如何实现更顺滑的亮度调节;还有如何设定亮度值 100-150之间,触发,150-200之间触发,而不是像现在这样高过一定数值或者低过一定数值;还有SONOFF的状态监测,现在是状态变化才自动化,如何实现是监测的状态而不是动作。
单独一个ESP8266加扩展板用来控制客厅部分棚顶LED灯带,另外一个ESP8266来做传感器信息的收发
-------------------------------------------------------------------------------------------------首先是手动控制灯带亮度的代码:
棚顶ESP8266灯带部分:
configuration:
target_temp211:
name: LED HK211
min: 0
max: 100
step: 1
initial: 30
unit_of_measurement: "%"
icon: mdi:target
automations:
- alias: Set temp slider211
trigger:
platform: mqtt
topic: '/HK210/PWM/13'
action:
- service: input_number.set_value
data_template:
entity_id: input_number.target_temp211
value: "{{ (trigger.payload)* 10}}"
- alias: Temp slider moved61
trigger:
platform: state
entity_id: input_number.target_temp211
action:
- service: mqtt.publish
data_template:
topic: '/HK210/PWM/13'
retain: true
payload: "{{ (states('input_number.target_temp211') | int)* 10}}"
请忽略我的命名,都是临时测试随意写的。之所以自动也要*10,是因为前面想做0-100%百分比的滑动,不知道别的方法,只会这样土办法。
-------------------------------------------------------------------------------------------------
ESP8266传感器收发部分:
configuration:
sensor 17:
platform: mqtt
name: "Lux-125"
state_topic: "/ESP125/BH1750/Lux"
qos: 0
unit_of_measurement: "Lux-125"
-------------------------------------------------------------------------------------------------
利用光照传感器自动控制LED灯带亮度:
automations:
- alias: 'LED_liangduzidong'
trigger:
- platform: numeric_state
below: 1000
entity_id: sensor.lux125
action:
- service: mqtt.publish
data_template:
topic: '/HK210/PWM/13'
retain: true
payload: "{{200}}"
- alias: 'guodao11111111111112'
trigger:
- platform: numeric_state
above: 1000
entity_id: sensor.lux125
action:
- service: mqtt.publish
data_template:
topic: '/HK210/PWM/13'
retain: true
payload: "{{800}}"
请各位前辈指教,如何写才能更顺滑的来控制亮度?
-------------------------------------------------------------------------------------------------
最近发现,ESP8266会偶发的出现死机状态,所以写了个简单的重启电源的办法,因为每个房间的棚顶都是单独给ESP做的强电,并且用SONOFF来控制。虽然繁琐了一些,但这也是所能想到的笨办法了。
检测ESP8266模块是否在线:
automations:
- alias: esp128_state_off
trigger:
platform: state
entity_id: binary_sensor.esp128
from: 'on'
to: 'off'
action:
- service: switch.turn_off
entity_id: switch.led_sonoff03
- delay: 00:00:05
- service: switch.turn_on
entity_id: switch.led_sonoff03
|