# Loads default set of integrations. Do not remove.
default_config:
http:
  base_url: https://ha.skinnyc.pro
  use_x_forwarded_for: true
  trusted_proxies:
    - 100.0.0.0/8
    - 192.168.1.0/24
    - 192.168.1.195
    - 127.0.0.1
  ip_ban_enabled: true
  login_attempts_threshold: 5

nginx_proxy:
  upstream:
    nodered:
      servers:
        - 127.0.0.1:1880
  servers:
    - server_name: _
      listen:
        - 443 ssl
      ssl_certificate: /ssl/fullchain.pem
      ssl_certificate_key: /ssl/privkey.pem
      locations:
        omi:
          path: /omi-transcript
          proxy_pass: http://nodered
          proxy_set_header:
            Host: $host
            X-Real-IP: $remote_addr
            X-Forwarded-For: $proxy_add_x_forwarded_for
            X-Forwarded-Proto: $scheme

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

mqtt:
  sensor:
    - name: "Solar Power"
      state_topic: "solar/dtu/power_w"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: hoymiles_dtu_power_w

    - name: "Solar Energy Today"
      state_topic: "solar/dtu/energy_today_wh"
      unit_of_measurement: "Wh"
      device_class: energy
      state_class: total_increasing
      unique_id: hoymiles_dtu_energy_today_wh

    - name: "Solar Energy Total"
      state_topic: "solar/dtu/energy_total_wh"
      unit_of_measurement: "Wh"
      device_class: energy
      state_class: total_increasing
      unique_id: hoymiles_dtu_energy_total_wh

    - name: "Solar AC Voltage"
      state_topic: "solar/dtu/ac_voltage_v"
      unit_of_measurement: "V"
      device_class: voltage
      state_class: measurement
      unique_id: hoymiles_dtu_ac_voltage

    - name: "Solar Frequency"
      state_topic: "solar/dtu/ac_freq_hz"
      unit_of_measurement: "Hz"
      device_class: frequency
      state_class: measurement
      unique_id: hoymiles_dtu_ac_freq
    - name: "Solar AC Current"
      state_topic: "solar/dtu/ac_current_a"
      unit_of_measurement: "A"
      device_class: current
      state_class: measurement
      unique_id: hoymiles_dtu_ac_current

    - name: "Solar PV1 Voltage"
      state_topic: "solar/dtu/pv1_voltage_v"
      unit_of_measurement: "V"
      device_class: voltage
      state_class: measurement
      unique_id: hoymiles_dtu_pv1_voltage

    - name: "Solar PV1 Current"
      state_topic: "solar/dtu/pv1_current_a"
      unit_of_measurement: "A"
      device_class: current
      state_class: measurement
      unique_id: hoymiles_dtu_pv1_current

    - name: "Solar PV1 Power"
      state_topic: "solar/dtu/pv1_power_w"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: hoymiles_dtu_pv1_power

    - name: "Solar Temperature"
      state_topic: "solar/dtu/temperature_c"
      unit_of_measurement: "°C"
      device_class: temperature
      state_class: measurement
      unique_id: hoymiles_dtu_temperature

    - name: "Solar Energy Today kWh"
      state_topic: "solar/dtu/energy_today_kwh"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: hoymiles_dtu_energy_today_kwh

n

    - name: "Samsung U24 Distance"
      state_topic: "espresense/devices/7d:92:e2:55:fb:a0/distance"
      unit_of_measurement: "m"
      value_template: "{{ value | round(2) }}"

homeassistant:
  name: Home
  latitude: 28.046590
  longitude: -82.179430
  unit_system: imperial
  currency: USD
  time_zone: "America/New_York"

camera:
  - platform: xiaomi_cloud_map_extractor
    host: 192.168.1.105
    token: 76784d33545074644e79416a54395471
    username: crogers2287@gmail.com
    password: "!!Alucard2287"
    draw:
      - all
    attributes:
      - calibration_points
  - platform: generic
    name: BackYard
    stream_source: rtsp://192.168.1.5:8554/back-yard-cam
  - platform: generic
    name: GrowRoom
    stream_source: rtsp://192.168.1.5:8554/shed-cam
  - platform: generic
    name: ChadGate
    stream_source: rtsp://192.168.1.207:554/cam/realmonitor?channel=1&subtype=1&unicast=true&proto=Onvif

eufy:
  username: chad@cfrfl.com
  password: "!!Alucard2287"

template:
  - binary_sensor:
      - name: "Phone Connected To Car Bluetooth"
        state: >
          {{ (state_attr('sensor.chad_s_pixel_7_ii_bluetooth_connection', 'connected_paired_devices') != None) and 
          ('28:38:5C:32:D7:53' in state_attr('sensor.chad_s_pixel_7_ii_bluetooth_connection', 'connected_paired_devices')) }}
  - sensor:
      - name: "Cycle Time Remaining"
        unit_of_measurement: "D H:M:S"
        state: >
          {% set cycle_duration = 168 if is_state('input_boolean.enable_dry_cycle', 'on') else 10000 %}
          {% set time_passed = states('input_number.dry_cycle_timer') | float %}
          {% set time_remaining = cycle_duration - time_passed %}
          {% set days = (time_remaining // 24) %}
          {% set hours = (time_remaining % 24) %}
          {% set minutes = ((time_remaining % 1) * 60) %}
          {% set seconds = ((minutes % 1) * 60) %}
          {{ "%d %02d:%02d:%02d" | format(days, hours, minutes, seconds) }}
      - name: "Adjusted Canopy Humidity"
        unit_of_measurement: "%"
        state: >
          {{ ((states('sensor.grow_dehu_1_humidity') | float + states('sensor.grow_dehu_2_humidity') | float) / 2) - 10 }}
      - name: "Dry Chamber Temperature Fahrenheit"
        unit_of_measurement: "°F"
        state: >
          {% set temp_celsius = states('sensor.dry_chamber_temperature') | float %}
          {{ (temp_celsius * 9/5) + 32 | round(2) }}
      - name: "Grow Room Target VPD"
        unit_of_measurement: "kPa"
        state: >
          {% set hour = now().hour %}
          {% if 8 <= hour < 20 %}
            1.4 - 1.7
          {% else %}
            1.0 - 1.2
          {% endif %}
      - name: "Grow Room VPD"
        unit_of_measurement: "kPa"
        state: >
          {% set T_F = states('sensor.gw1100b_temperature_1') | float %}
          {% set RH = states('sensor.gw1100b_humidity_1') | float %}
          {% set T_C = (T_F - 32) * (5 / 9) %}
          {% set SVP = 610.78 * (2.71828 ** ((T_C / (T_C + 237.3)) * 17.2694)) %}
          {% set SVP_kPa = SVP / 1000 %}
          {% set AVP = SVP_kPa * (RH / 100) %}
          {% set VPD = SVP_kPa - AVP %}
          {{ VPD | round(2) }}
      - name: "VPD Status"
        state: >
          {% set vpd = states('sensor.grow_room_vpd') | float %}
          {% if states('input_select.growth_stage') == 'Propagation/Early Veg' %}
            {% if 0.4 <= vpd <= 1.0 %}
              good
            {% else %}
              bad
            {% endif %}
          {% elif states('input_select.growth_stage') == 'Early Flower/Late Veg' %}
            {% if 0.8 <= vpd <= 1.4 %}
              good
            {% else %}
              bad
            {% endif %}
          {% elif states('input_select.growth_stage') == 'Mid/Late Flower' %}
            {% if 1.0 <= vpd <= 1.6 %}
              good
            {% else %}
              bad
            {% endif %}
          {% endif %}


input_boolean:
  master_bedroom_schedule:
    name: Master Bedroom Schedule
    initial: off
  living_room_schedule:
    name: Living Room Schedule
    initial: off
  bonus_room_schedule:
    name: Bonus Room Schedule
    initial: off
  chad_s_garage_door_switch:
    name: "Chad's Garage Door Virtual Switch"
    initial: off
  ac_vpd_control_lock:
    name: "AC VPD Control Lock"
    initial: off
  govee_dehumidifier_state:
    name: Govee Dehumidifier State
    initial: on
    icon: mdi:air-humidifier
  game_kill_switch:
    name: Game Kill Switch
    initial: off
    icon: mdi:gamepad-off

  enable_dry_cycle:
    name: Enable Dry Cycle
    initial: off
  enable_cure_cycle:
    name: Enable Cure Cycle
    initial: off
  garage_door_open:
    name: "Garage Door Open"
    initial: off
    icon: "mdi:garage-open"
  garage_door_close:
    name: "Garage Door Close"
    initial: off
    icon: "mdi:garage"
  vegetative_stage:
    name: Vegetative Stage
    initial: false
  early_flowering_stage:
    name: Early Flowering Stage
    initial: false
  mid_late_flowering_stage:
    name: Mid to Late Flowering Stage
    initial: false
  late_flowering_pre_harvest:
    name: Late Flowering to Pre-Harvest
    initial: false

input_select:
  govee_dehumidifier_mode:
    name: Govee Dehumidifier Mode
    options:
      - "Low"
      - "High"
      - "Auto"
      - "Dryer"
      - "Off"
    icon: mdi:air-humidifier
  growth_stage:
    name: Growth Stage
    options:
      - "Propagation/Early Veg"
      - "Early Flower/Late Veg"
      - "Mid/Late Flower"
    initial: "Propagation/Early Veg"
    icon: mdi:sprout
rest_command:
  govee_dehumidifier:
    url: https://developer-api.govee.com/v1/appliance/devices/control
    method: PUT
    headers:
      Content-Type: application/json
      Govee-API-Key: !secret govee_api_key
    content_type: "application/json; charset=utf-8"
    payload: '{"device": "{{ device }}","model": "{{ model }}","cmd": {"name": "{{ cmd_name }}","value": "{{ cmd_value }}"}}'
    verify_ssl: true
  trigger_webhook:
    url: "https://us-apia.coolkit.cc/v2/smartscene2/webhooks/execute?id=39de8e2a8ff642e190da58dd7799bff4"
  game_kill_switch_on:
    url: "http://192.168.1.195:8770/on"
    method: POST
  game_kill_switch_off:
    url: "http://192.168.1.195:8770/off"
    method: POST
  add_automation:
    url: "https://ha.skinnyc.pro:8123/api/config/automation/config/"
    method: POST
    headers:
      Authorization: "Bearer {{ secrets.ha_long_lived_access_token }}"
      Content-Type: "application/json"
    payload: "{{ automation_config }}"
  
  delete_automation:
    url: "https://ha.skinnyc.pro:8123/api/config/automation/config/{{ automation_id }}"
    method: DELETE
    headers:
      Authorization: "Bearer {{ secrets.ha_long_lived_access_token }}"
      Content-Type: "application/json"
withings:
  use_webhook: true
input_number:
  dry_cycle_timer:
    name: Dry Cycle Timer
    min: 0
    max: 168 # 7 days in hours
    step: 1
    unit_of_measurement: "hours"
    initial: 0
  keypad_pin_number:
    name: Keypad PIN Number
    min: 0
    max: 9999
    step: 1
    mode: box
  webhook_payload:
    name: Webhook Payload
    initial: "No data"

  target_temperature:
    name: Target Temperature
    min: 60 # Adjust minimum as needed
    max: 80 # Adjust maximum as needed
    step: 1
    unit_of_measurement: "°F"

  target_humidity:
    name: Target Humidity
    min: 30 # Adjust minimum as needed
    max: 70 # Adjust maximum as needed
    step: 1
    unit_of_measurement: "%"

  cure_cycle_timer:
    name: Cure Cycle Timer
    min: 0
    max: 10000 # A large number, assuming an indefinite curing period
    step: 1
    unit_of_measurement: "hours"
    initial: 0
  daily_humidity_target:
    name: "Daily Humidity Target"
    min: 40
    max: 60
    step: 1
    mode: "box"
    initial: 60
  vacuum_daily_runs:
    name: Vacuum Daily Runs
    initial: 0
    min: 0
    max: 10
    step: 1

group:
  master_bathroom:
    name: Master Bathroom
    entities:
      - switch.master_bath_motion_switch_1
      - switch.master_closet
      - switch.master_shower_switch_1
      - switch.master_toilet_switch_1
      - switch.master_tub
  string_lights_group:
    name: String Lights Group
    entities:
      - light.string_lights
      - switch.pool_string_lights_socket

input_text:
  command_input:
    name: Command Input
    initial: ""

  grow_room_log:
    name: Grow Room Log
    max: 255
plex_webhooks:
  webhook_id: plex_webhook
shell_command:
  update_hacs: "python3 /config/update_hacs.py"

switch:
  - platform: template
    switches:
      string_lights_control:
        friendly_name: "String Lights Control"
        value_template: "{{ is_state('light.string_lights', 'on') or is_state('switch.pool_string_lights_socket', 'on') }}"
        turn_on:
          service: homeassistant.turn_on
          data:
            entity_id:
              - light.string_lights
              - switch.pool_string_lights_socket
        turn_off:
          service: homeassistant.turn_off
          data:
            entity_id:
              - light.string_lights
              - switch.pool_string_lights_socket
localtuya:
  - host: 192.168.1.138 # Replace with your device's IP
    device_id: eb694adeafc6131dabsahj
    local_key: MHv=@DQy59xtPp=' # Replace with your Local Key
    friendly_name: "EZCure"
    protocol_version: "3.3" # Update if necessary
    entities:
      - platform: switch # Change the platform as necessary (switch, light, etc.)
        friendly_name: "Switch Name"
        id: 1
webhook:
  - id: omi-transcript
    webhook_id: omi-transcript
    local_only: false
bluetooth:
  adapter: esp32_ble_tracker
  enable_passive_scanner: true

openai_conversation:


# EG4 Battery Monitor
shell_command:
  eg4_fetch: "/config/scripts/eg4_fetch.sh"

rest:
  - resource: http://192.168.1.5:8888/eg4_data.json
    scan_interval: 60
    sensor:
      - name: "EG4 Battery SOC"
        unique_id: eg4_battery_soc
        unit_of_measurement: "%"
        device_class: battery
        value_template: '{{ value_json.soc }}'
      - name: "EG4 Battery Voltage"
        unique_id: eg4_battery_voltage
        unit_of_measurement: "V"
        device_class: voltage
        value_template: '{{ value_json.voltage }}'
      - name: "EG4 Battery Power"
        unique_id: eg4_battery_power
        unit_of_measurement: "W"
        device_class: power
        value_template: '{{ value_json.power }}'
      - name: "EG4 PV Power"
        unique_id: eg4_pv_power
        unit_of_measurement: "W"
        device_class: power
        value_template: '{{ value_json.pv_watts }}'
