esphome:
name: natural-gas
esp8266:
board: nodemcu
restore_from_flash: true
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
captive_portal:
web_server:
port: 80
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: D1
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
|