---
substitutions:
  device: can-node-2
  name: CAN Node 2
  area: DEV
  comment: CANopen

esphome:
  name: mcu-${device}
  friendly_name: ${name}
  area: ${area}
  comment: ${comment}

esp32:
  variant: esp32
  toolchain: esp-idf
  framework:
    type: esp-idf

external_components:
  - source: github://mrk-its/esphome-canopen@dev
    refresh: 1h
  - source: github://mrk-its/esphome-canbus-udp-multicast@dev
    refresh: 1h

packages:
  common: !include common/common.yaml

canbus:
  - platform: esp32_can
    id: can_bus
    rx_pin: 22
    tx_pin: 23
    can_id: 2
    bit_rate: 500kbps

canopen:
  id: can_open
  canbus_id: can_bus
  node_id: 2
  entities:
    - index: 1
      id: light1
      tpdo: 0

    - index: 2
      id: light2
      tpdo: 0

    - index: 3
      id: light3
      tpdo: 0

output:
  - platform: template
    id: cw_output1
    type: float
    write_action:
      - logger.log:
          format: "output1: %f"
          args: ['state']

  - platform: template
    id: ww_output1
    type: float
    write_action:
      - logger.log:
          format: "output2: %f"
          args: ['state']

  - platform: template
    id: output2
    type: float
    write_action:
      - logger.log:
          format: "output1: %f"
          args: ['state']

  - platform: template
    id: output3
    type: float
    write_action:
      - logger.log:
          format: "output1: %f"
          args: ['state']

light:
  - platform: cwww
    id: light1
    name: Light 1
    cold_white: cw_output1
    warm_white: ww_output1
    cold_white_color_temperature: 6536 K
    warm_white_color_temperature: 2000 K
    constant_brightness: false
    default_transition_length: 0s

  - platform: monochromatic
    id: light2
    name: Light 2
    output: output2
    default_transition_length: 0s

  - platform: binary
    id: light3
    name: Light 3
    output: output3


## LIGHTENING
i2c:
  sda: 17
  scl: 18
  scan: true
  # frequency: 100kHz

as3935_i2c:
  irq_pin: 19
  spike_rejection: 4

binary_sensor:
  - platform: as3935
    name: Storm Alert

sensor:
  - platform: as3935
    lightning_energy:
      name: Energy
    distance:
      name: Storm Distance

# logger:
#   level: VERY_VERBOSE
#   logs:
#     canbus: DEBUG
#     canopen: DEBUG
#     can_driver: DEBUG
#     timer_driver: DEBUG
