本帖最后由 ciasdmxhxjjpd@c 于 2023-2-7 09:14 编辑
esphome:
name: gas
esp8266:
board: nodemcuv2
# Enable logging
logger:
level: NONE
web_server:
port: 80
auth:
username: admin
password: !secret web_password
# Enable Home Assistant API
api:
password: !secret api_password
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Gas Fallback Hotspot"
password: !secret wifi_password
captive_portal:
globals:
- id: total_value3
type: float
restore_value: yes
initial_value: '577.808'
i2c:
sda: GPIO4
scl: GPIO5
scan: true
id: bus_a
output:
- platform: gpio
pin: D6
id: gpio_d6
binary_sensor:
- platform: gpio
pin: D5
name: "murui bell ring"
- platform: template
id: "gas_pulse"
lambda: |-
if (id(hmc5883l_z).state > 105.4){
id(gpio_d6).turn_on();
}
if(id(hmc5883l_z).state < 104.6) {
id(gpio_d6).turn_off();
}
return 1;
sensor:
- platform: hmc5883l
address: 0x1E
field_strength_z:
name: "HMC5883L Field Strength Z"
id: hmc5883l_z
oversampling: 1x
range: 130uT
update_interval: 500ms
- platform: pulse_counter
pin:
number: D7
mode: INPUT_PULLUP
inverted: True
name: "gas"
update_interval: 60s
filters:
- lambda: |-
id(total_value3) += x * 0.001;
return id(total_value3);
unit_of_measurement: "m³"
state_class: total_increasing
device_class: gas
accuracy_decimals: 3
icon: 'mdi:fire'
switch:
- platform: restart
name: "gas restart"
id: gas_restart
d6 和 d7 用一根跳线相连接。
我的表是每走 0.001 磁场变化一个周期。
具体是 0.001 还是 0.01 具体看 HMC5883L Field Strength Z 的变化图。
以我的为例。不用燃气时,波动范围不超过1,
设置上限为 105.5
下限为104.5
|