####################################################
# config for homes without solar / wind production #
####################################################

esphome:
    name: vue-utility

esp32:
  board: esp-wrover-kit
  framework:
    type: esp-idf

external_components:
  source:
    type: git
    url: https://github.com/nekorevend/esphome-emporia-vue-utility
    ref: esp-idf

# Add your own wifi credentials
wifi:
    ssid: !secret wifi_ssid
    password: !secret wifi_password

ota:

logger:
    logs:
        # Change to DEBUG / INFO / WARN / ERROR as desired
        Vue: DEBUG

api:

mqtt:
    broker: !secret mqtt_broker
    id: vue_utility
    username: !secret mqtt_username
    password: !secret mqtt_password
    discovery: False # Only if you use the HA API usually

# This uart connects to the MGM111
uart:
    id: emporia_uart
    rx_pin: GPIO21
    tx_pin: GPIO22
    baud_rate: 115200

sensor:
  - platform: emporia_vue_utility
    uart_id: emporia_uart
    power:
      name: "Watts"
      # Report every 5 minutes or when +/- 20 watts
      filters:
        - or:
          - throttle: 5min
          - delta: 20  # <- watts
          - lambda: |-
              if (id(fast_reporting)) return(x);
              return {};
    energy:
      name: "Watt-hours"
      # Reduce the rate of reporting the value to
      # once every 5 minutes and/or when 0.1 kwh
      # have been consumed, unless the fast_reporting
      # button has been pushed
      filters:
        - or:
          - throttle: 5min
          - delta: 100 # <- Wh
          - lambda: |-
              if (id(fast_reporting)) return(x);
              return {};
        # If you want kWh instead of Wh
        # - lambda: return x / 1000;

# This gives you a button that temporarily causes results to be
# reported every few seconds instead of on significant change
# and/or every 5 minutes
button:
    - platform: template
      name: "Fast Reporting"
      id: fast_reporting_button
      on_press:
        - lambda: id(fast_reporting) = true;
        - delay: 5min
        - lambda: id(fast_reporting) = false;

# Global value for above button
globals:
    - id: fast_reporting
      type: bool
      restore_value: no
      initial_value: "false"

# This LED is marked D3 on the pcb and is the power led on the case
status_led:
    pin:
        number: GPIO25
        # It *is* inverted, but being normally on looks better
        inverted: false

