##################################################
# Config for homes with solar or wind production #
#  - Does not throttle the data.                 #
#  - Reports in Wh instead of kWh.               #
##################################################

esphome:
    name: vue-utility
    platform: ESP32
    board: esp-wrover-kit
    includes:
        - emporia_vue_utility.h

# 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: custom
      lambda: |-
        auto vue = new EmporiaVueUtility(id(emporia_uart), 15);
        App.register_component(vue);
        return {vue->Wh_consumed, vue->Wh_returned, vue->W, vue->Wh_net};
      sensors:
          - name: "${name} Wh Consumed"
            id: Wh_consumed
            accuracy_decimals: 0
            state_class: total_increasing
            device_class: energy
            on_raw_value:
                then:
                    lambda: |-
                        ESP_LOGI("Vue", "Wh Consumed = %0.3f", x);

          - name: "${name} Wh Returned"
            id: Wh_returned
            accuracy_decimals: 0
            state_class: total_increasing
            device_class: energy
            on_raw_value:
                then:
                    lambda: |-
                        ESP_LOGI("Vue", "Wh Returned = %0.3f", x);

          - name: "${name} Watts"
            id: watts
            unit_of_measurement: "W"
            accuracy_decimals: 0
            state_class: measurement
            device_class: power
            on_raw_value:
                then:
                    lambda: |-
                        ESP_LOGI("Vue", "Watts = %0.3f", x);

          - name: "${name} Wh Net"
            id: Wh_net
            accuracy_decimals: 0
            device_class: energy
            on_raw_value:
                then:
                    lambda: |-
                        ESP_LOGI("Vue", "Wh Net = %0.3f", x);

# 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
