esphome:
  name: "esp8266"
  friendly_name: Ando DFM1000-W Durchflussmesser

esp8266:
  board: esp01_1m

debug:
  update_interval: 5s


# Enable logging
logger:
  level: VERY_VERBOSE
  baud_rate: 0 
  
# Enable Home Assistant API
api:
  encryption:
    key: "b2zxQsZLOcFEBX......"

ota:
  - platform: esphome
    password: "52a6c40"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.16.....
    gateway: 192........
    subnet: 255.255.255.0
    dns1: 192.168.178.1
  min_auth_mode: WPA2

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Kzgout Fallback Hotspot"
    password: "W8FWgE3I0zO2"


captive_portal:

time:
  - platform: homeassistant
    id: homeassistant_time


uart:
  id: uart_0
  baud_rate: 9600
  tx_pin: TX                   
  rx_pin: RX 
  stop_bits: 1
  parity: none                 
  debug:
    direction: BOTH  

modbus:
  id: modbus1
  uart_id: uart_0
  flow_control_pin: GPIO4    
  send_wait_time: 500ms     
  disable_crc: true

modbus_controller:
  - id: TUF2000M
    address: 0x1
    modbus_id: modbus1
    setup_priority: -10
    update_interval: 15s
    command_throttle: 3s


text_sensor:
  - platform: wifi_info
    ip_address:
      name: IP Address
    ssid:
      name: Connected SSID
    bssid:
      name: Connected BSSID
    mac_address:
      name: Mac Wifi Address


  - platform: modbus_controller
    modbus_controller_id: TUF2000M
    name: "TUV2000M"
    address: 1
    register_count: 3
    register_type: holding
    entity_category: diagnostic


sensor:
  - platform: modbus_controller
    modbus_controller_id: TUF2000M
    name: "Durchfluß"
    id: flow
    register_type: holding
    address: 0x1  # Register 1
    register_count: 2
    response_size: 2
    accuracy_decimals: 3
    value_type: FP32
    device_class: "volume_flow_rate"
    state_class: "measurement"
    unit_of_measurement: "m³/h"

  - platform: modbus_controller
    modbus_controller_id: TUF2000M
    name: "flowmeter_travelTimeRate"
    id: flow_travelTimeRate
    register_type: holding
    address: 0x61
    register_count: 2    
    accuracy_decimals: 2
    response_size: 2
    value_type: FP32
    unit_of_measurement: "h"
    
  - platform: modbus_controller
    modbus_controller_id: TUF2000M
    name: "Fließgeschwindigkeit"
    id: flow_fluidSoundSpeed
    register_type: holding
    address: 0x7 # Register 7
    device_class: "speed"
    state_class: "measurement"
    register_count: 2    
    accuracy_decimals: 2
    response_size: 2
    value_type: FP32
    unit_of_measurement: "m/s"

  - platform: modbus_controller
    modbus_controller_id: TUF2000M
    name: "Accumulator"
    register_type: holding
    address: 0x9  # Register 9
    register_count: 2
    value_type: FP32
    device_class: "water"
    state_class: "measurement"
    unit_of_measurement: "kg"

  ##############################

  - platform: modbus_controller
    modbus_controller_id: TUF2000M
    name: "Flow rate"
    id: flow_rate
    register_type: holding
    address: 0x1 # Register 1
    register_count: 2
    response_size: 2
    value_type: FP32
    device_class: "speed"
    state_class: "measurement"
    unit_of_measurement: "m³/h"

###################################################

binary_sensor:

  - platform: modbus_controller
    modbus_controller_id: TUF2000M
    name: "Flow Meter Error No Signal"
    register_type: holding
    address: 0x48  # Register 72
    bitmask: 0x1

  - platform: modbus_controller
    modbus_controller_id: TUF2000M
    name: "Flow Meter Error Low Signal"
    register_type: holding
    address: 0x48  # Register 72
    bitmask: 0x2

  - platform: modbus_controller
    modbus_controller_id: TUF2000M
    name: "Flow Meter Error Poor Signal"
    register_type: holding
    address: 0x48  # Register 72
    bitmask: 0x4





 
