本帖最后由 fk0074 于 2026-1-21 10:00 编辑
燃气DIY-巧读天然气表引用大佬的教程及评论区各位大佬的代码,【学习-记录-分享】燃气DIY篇2-巧读天然气表(https://bbs.hassbian.com/thread-16773-1-2.html)。 简介家里开暖气,想记录不同温度设置下对用能的影响,新奥燃气的统计结果有滞后,学习了大佬的帖子后手动制作,还增加了433发射模块以及温湿度传感器模块,后续还可以拓展更多模块。 目的利用计量码盘最后一位数字“0”的的小镜面反射部,使用光电采样计量,集成到HA中记录并统计用气量。 准备在巨人的肩膀上,操作难度就小很多,为了打印外壳,购入了3D打印机,自制配件,通过esp8266模块直接接入。有个注意事项,TCRT5000有个检测距离,1mm-8mm,上面的可调电阻是调整检测距离的,因此在设计3d打印模型的时候,一定要提前预留好距离,免得过近了无法监测。 硬件esp8266,TCRT5000循迹模块x1,DHT22温湿度模块x1,H34L低电压无线发射模块x1等。 还需要3D打印制作esp8266模块盒,具体见图。
esphome:
name: laundry
friendly_name: '燃气'
esp8266:
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: ""
ota:
- platform: esphome
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ""
password: ""
captive_portal:
remote_transmitter:
pin: D1
# RF uses a 100% carrier signal
carrier_duty_percent: 100%
switch:
- platform: template
name: Up
turn_on_action:
- remote_transmitter.transmit_rc_switch_raw:
code: '0111110110100111101010000000000000010001' # 0x4F 8C10 0611
protocol:
pulse_length: 350
sync: [14, 4]
zero: [1, 2]
one: [2, 1]
repeat:
times: 5
wait_time: 7500us
- platform: template
name: down
turn_on_action:
- remote_transmitter.transmit_rc_switch_raw:
code: '0111110110100111101010000000000000110011' # 0x4F 8C10 0611
protocol:
pulse_length: 350
sync: [14, 4]
zero: [1, 2]
one: [2, 1]
repeat:
times: 5
wait_time: 7500us
- platform: template
name: stop
turn_on_action:
- remote_transmitter.transmit_rc_switch_raw:
code: '0111110110100111101010000000000001010101' # 0x4F 8C10 0611
protocol:
pulse_length: 350
sync: [14, 4]
zero: [1, 2]
one: [2, 1]
repeat:
times: 5
wait_time: 7500us
- platform: template
name: light
turn_on_action:
- remote_transmitter.transmit_rc_switch_raw:
code: '0111110110100111101010000000000000001111' # 0x4F 8C10 0611
protocol:
pulse_length: 350
sync: [14, 4]
zero: [1, 2]
one: [2, 1]
repeat:
times: 5
wait_time: 7500us
- platform: template
name: power
turn_on_action:
- remote_transmitter.transmit_rc_switch_raw:
code: '011111011010011110101000000000001110000' # 0x4F 8C10 0611
protocol:
pulse_length: 350
sync: [14, 4]
zero: [1, 2]
one: [2, 1]
repeat:
times: 5
wait_time: 7500us
# binary_sensor:
# - platform: gpio
# name: "gas_count"
# pin:
# number: GPIO4
# inverted: true
# mode:
# input: true
# pullup: true
time:
- platform: sntp
id: sntp_time
timezone: Asia/Shanghai
# on_time:
# - cron: '* 10 2 * * *' #每天2点10分重启
# then:
# - switch.toggle: ranqi_esp8266_restart
globals:
- id: counter_int
type: float
restore_value: yes
initial_value: '0'
binary_sensor:
- platform: gpio
pin:
number: D3
mode: INPUT_PULLUP
inverted: True
name: gas_counter_key_point
id: gas_counter_key_point
icon: mdi:gas-burner
on_release:
then:
- lambda: |-
id(counter_int) += 0.01;
id(gas_meter).publish_state(id(counter_int));
sensor:
- platform: template
name: "gas_meter"
id: gas_meter
lambda: !lambda |-
return id(counter_int);
unit_of_measurement: 'm³'
state_class: 'total_increasing'
accuracy_decimals: 2
device_class: 'gas'
update_interval: 60s
- platform: dht
pin: D2
temperature:
name: "outdoor Temperature"
humidity:
name: "outdoor Humidity"
update_interval: 60s
# switch:
# - platform: restart #用于重启NodeMCU
# name: "ranqi_esp8266_restart"
# id: ranqi_esp8266_restart
|