Status LED dual use? Is this possible?

I have a project that involves and ESP32 and CC1101 module, I have it basically working as I want it to except for one fan I can turn off but not back on...

I decided to use the status LED as a TX indicator and that works very well, but it seems to me there should be some way to use it as a status indicator as well. It would be great to have the visual indicator of a problem with connections to HA or wireless by having it blink when needed.

Current config involving the status LED as a TX indicator, obviously will not indicate status:

remote_transmitter:
  pin: GPIO4      # Must match GDO0
  id: transmitter0
  carrier_duty_percent: 100%
  non_blocking: false
  on_transmit:
    then:
      - output.turn_on: blue_tx_led
      - cc1101.begin_tx
  on_complete:
    then:
      - output.turn_off: blue_tx_led
      - cc1101.begin_rx

output:
  - platform: gpio
    pin: GPIO02
    id: blue_tx_led

I have tried using these methods, with little success: In the following I tried to define a switch to control the LED. This did not try to work or pass testing

remote_transmitter:
  pin: GPIO4      # Must match GDO0
  id: transmitter0
  carrier_duty_percent: 100%
  non_blocking: false
  on_transmit:
    then:
      - switch.turn_on: blue_tx_led
      - cc1101.begin_tx
  on_complete:
    then:
      - switch.turn_off: blue_tx_led
      - cc1101.begin_rx
switch:
  - platform: status_led
    name: "Indicator LED"
    id: blue_tx_led
    pin: GPIO2

This compiles and makes the LED reflect status, but does not activate when TX is turned on:

remote_transmitter:
  pin: GPIO4      # Must match GDO0
  id: transmitter0
  carrier_duty_percent: 100%
  non_blocking: false
  on_transmit:
    then:
      - light.turn_on: blue_tx_led
      - cc1101.begin_tx
  on_complete:
    then:
      - light.turn_off: blue_tx_led
      - cc1101.begin_rx

light:
  - platform: status_led
    name: "Indicator LED"
    id: blue_tx_led
    pin: GPIO2

So, I think I am close here. In the ESPHome web interface I get a toggle for "Indicator LED" and it does turn on the blue LED but it does not turn on during transmit. Feels like I am so close...

Thanks for looking at this!

perhaps this: Generic Output Switch - ESPHome - Smart Home Made Simple

Use the switch to control the output. Control the output directly with the TX (which you said was working).

I guess I do not understand. With the switch and output there is no way to tie in the status function since I can only call out the gpio 1 time in one section.

Something like this:

output:
  - platform: gpio
    pin: GPIO02
    id: blue_tx_led

switch:
  - platform: output
    name: "Indicator LED" 
    output: blue_tx_led

So, I think it is actually working...

When a tx code is sent I see the web interface toggle the indicator on and off quickly. So, I added a delay in the transmitter section and it does not seem to make a difference.. If I toggle the LED on the web interface it does indeed come on.

light:
  - platform: status_led
    name: "Device Status LED"
    pin: GPIO2  # Replace with your actual LED pin
    id: blue_tx_led

remote_transmitter:
  pin: GPIO4      # Must match GDO0
  id: transmitter0
  carrier_duty_percent: 100%
  non_blocking: false
  on_transmit:
    then:
      - light.turn_on: blue_tx_led
      - cc1101.begin_tx
      - delay: 2s
  on_complete:
    then:
      - light.turn_off: blue_tx_led
      - cc1101.begin_rx

Also, when I trigger a light change and tx, I get the LED status in the log when it turns off but not when it turns on? When I do it with the web toggle same result and off message but no an on message.

'Device Status LED': Setting state OFF

But, that code will only make it work as a tx state indicator? I am trying to retain the original status function as well as add the tx indication function.

I till try it as soon as I can.

How will you know when led flashes from TX activity and / or from status activity ? Using same led for two simultaneous things isn't so great idea because it's confusing.

I use a separate dedicated led for my status, but i have my own code, i don't use bulit-in "status_led" function, since it's too limited. My version lights steadily with short "off" every 2 s when powered on (that way i know it's powered and working, not "stuck"), flashes steadily at 1Hz when only wifi is connected and it's off with short "on" every 2s when it's connected to HA, too. I can give you the code if you decide for this option.

1 Like

Even if your cc1101 has parameter non_blocking:false, delays on code are normally non-blocking.
So neither status code or on_complete considers your delay..
Try how it behaves like this:

  on_transmit:
    then:
      - light.turn_on: blue_tx_led
      - cc1101.begin_tx
      - delay: 2s
      - light.turn_off: blue_tx_led
  on_complete:
    then:
      - cc1101.begin_rx

But the idea of sharing one LED for two purposes doesn't sound like great idea to me..

I would love to look at your code... I doubt that I will add a second LED, but I may look at an ESP with an addressable LED.

I will try it out. It will never be so busy that the led will flash due to TX, I really like the idea of a status LED. As I just told the other person who responded, I may look for an ESP with an addressable LED...

I will try it this evening and let you know.

Thanks

It takes one minute to add LED (+resistor) to your actual Esp board...

I agree, but I have this and the CC1101 stuffed into a case the literally is the footprint of the ESP and the CC1101 sits between the legs of the ESP. If I cannot get to where I want to, I may try to stuff one in.

If there's very little room i generally use 0603 diode and 0603 resistor, it mostly fits between two pins.

Here's version for classic single led, connected from GPIO to GND:
NOTE: i have this code in a separate yaml, i only define "connected_pin" in my main program (which GPIO is led connected to), then i just include appropriate package in my main yaml. You must define it or replace with fixed number!

interval:
  - interval: 2s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - if:
              condition:
                api.connected:
              then:
                - light.turn_on:
                    id: led
                    flash_length: 100ms
              else:
                - light.turn_on:
                    id: led
                    flash_length: 1000ms
        else:
          - light.turn_on:
              id: led
              flash_length: 1900ms

light: # ----------------------------------------------------------------------- LIGHT
  - platform: binary
    id: led
    internal: true
    output: status_ledica_out

output:
  - id: status_ledica_out
    platform: gpio
    pin: ${connected_pin}

If you have led connected from +3.3V to GPIO then "interval" part is different:

interval:
  - interval: 2s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - if:
              condition:
                api.connected:
              then:
                - light.turn_on:
                    id: led
                    flash_length: 1900ms
              else:
                - light.turn_on:
                    id: led
                    flash_length: 1000ms
        else:
          - light.turn_on:
              id: led
              flash_length: 100ms

I also tested WS2812 led, in this case color shows connection status:
Here you must (apart from connected_pin) also define:

  • led_brightness (sometimes it's not needed for led to lights at full brightness)
  • rgb_order (this depends on led used):

Colors:
- green: HA connected
- blue: wifi connected, HA not yet
- red: wifi not connected

interval:
  - interval: 2s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - if:
              condition:
                api.connected:
              then:
                - light.turn_on:
                    id: led
                    brightness: ${led_brightness}
                    flash_length: 100ms
                    red: 0%
                    green: 100%
                    blue: 0%
              else:
                - light.turn_on:
                    id: led
                    brightness: ${led_brightness}
                    flash_length: 500ms
                    red: 0%
                    green: 0%
                    blue: 100%
                - delay: 500ms
                - light.turn_on:
                    id: led
                    brightness: ${led_brightness}
                    flash_length: 500ms
                    red: 0%
                    green: 0%
                    blue: 100%

        else:
          - light.turn_on:
              id: led
              brightness: ${led_brightness}
              flash_length: 1500ms
              red: 100%
              green: 0%
              blue: 0%
          - delay: 500ms
          - light.turn_on:
              id: led
              brightness: ${led_brightness}
              flash_length: 1500ms
              red: 100%
              green: 0%
              blue: 0%
light: # ----------------------------------------------------------------------- LIGHT
  - platform: esp32_rmt_led_strip
    id: led
    rgb_order: ${rgb_order}
    chipset: ws2812
    pin: ${connected_pin}
    num_leds: 1
2 Likes

I saw a note in the docs on delay regarding not introducing a delay due to continued processing. Now I know what they were trying to say! This works exactly as I was trying to make it work. Status still indicates during startup and once booted the blue led is indicating tx activity.

Thanks a bunch! I had a feeling I was close!

I miss doing this kind of work! I have really bad glaucoma, until a few years ago I would build custom flashlight drivers, double sided all hand soldered SMT components... now I can barely crimp on a Dupont connector. I really need to make a custom ribbon cable for this project, but I am not sure I could make it reliable. The cable I am using is much longer than I need.

Couple pics for size and space comparison. I still need to find a 90 degree 433mHz antenna for the build. The white PLA allows me to see both LEDs through the base of the box, (solid side) as the ESP 30 pin board is sitting against that face of the box.


2 Likes

Auch... sorry to hear that... do you have/did you consider having a microscope then? I have it and despite "normal" eyes (of a 60-year) it's indispensable for SMD work. It's not exactly cheap, but it's worthed every penny. The distance is pretty big (in the range of 10cm), so you can do pretty much anything with it.

EXAMPLE

Ahh, that makes sense. I thought indicator was used at runtime..

All good, your comment about how delay was used actually solved my issue! So, I did test as well and if the unit disconnects from HA or wifi after booted I still get the 2 different blink rates for indication of a problem.

I have not used one.. I would love to, the HDMI units really interest me. My concern, having used microscscopes in the past is depth of field. I assume that the DOF is so shallow you end up with only part of a component in focus at a time? I would really love to get back to being able to do some finer detail work again. Not sure how long I will have meaningful sight, at 60 I hope it is several more years.

In case anyone is interested... here is the basically completed code. I would still like to find a way to turn on and of the receiver from the web frontend so I do not have to uncomment and recompile each time I want to receive a signal and I have one fan that just does not want to turn off but will turn on...

substitutions:
  name: "esphome-dev1"
  friendly_name: ESPHome Dev 1
  devicename: esphome_dev1
#  esphome_platform: esp32
  esphome_board: esp32dev
  esphome_project_name: "Matt.Ward Remote Control"
  esphome_project_version: "rc-control-v.2"

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: false
  project:
    name: $esphome_project_name
    version: $esphome_project_version
  on_boot:
      if:
        condition:
          api.connected: null
        then:
          - logger.log: API is connected! Now we can trigger what we want!

esp32:
  board: esp32dev
  framework:
    type: esp-idf
    advanced:
      minimum_chip_revision: "3.1"
      sram1_as_iram: true

network:
    enable_ipv6: true
    min_ipv6_addr_count: 2
    enable_high_performance: true


#status_led:
#  id: blue_tx_led
#  pin:
#    number: 02
#    inverted: false

# Enable logging
logger:
  level: DEBUG

debug:
  update_interval: 30s

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:
  platform: esphome

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
#  use_address: esphome_tank_test
  domain: .home
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Set up a wifi access point
  ap:  
    ssid: "${friendly_name}"
    password: !secret wifi_ap_password

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:

dashboard_import:
  package_import_url: github://esphome/example-configs/esphome-web/esp32.yaml@main
  import_full_config: true


# To have a "next url" for improv serial
web_server:
#  include_internal: True
  version: 3
  sorting_groups:
    - id: sorting_group_ip_settings
      name: "IP Settings"
      sorting_weight: 10
    - id: sorting_group_wifi
      name: "Wifi"
      sorting_weight: 15

i2c:
  sda: GPIO21
  scl: GPIO22
  frequency: 400kHz

spi:
  clk_pin:  GPIO18                   # SCK
  miso_pin: GPIO19                   # MISO
  mosi_pin: GPIO23                   # MOSI

#     CC1101 Top view
#   -----------------------------------
#   | 1 GND   2 VCC         -----     |
#   | 3 GDO0  4 CSN        |     |    |ANTENNA
#   | 5 SCK   6 MOSI       |     |    |ANTENNA
#   | 7 MISO  8 GDO2        -----     |
#   -----------------------------------
#   1 - GND  - Ground -     Red
#   2 - VCC  - 1.8v-3.6v -  Brown
#   3 - GDO0 - Module Out - Yellow  gpio4
#   4 - CSN  - Chip Select- Orange  gpio27
#   5 - SCK  - SPI Clock -  Blue    gpio18
#   6 - MOSI - SPI IN -     Green   gpio23
#   7 - MISO - SPI Out -    White   gpio19
#   8 - GDO2 - Module Out - Purple  gpio25

light:
  - platform: status_led
    name: "Device Status LED"
    pin: GPIO2  # Replace with your actual LED pin
    id: blue_tx_led

cc1101:
  cs_pin: GPIO27
  id: transceiver
  output_power: "10"
  rx_attenuation: "18dB"
# frequency: 433.92MHz
#  frequency: 350MHz

remote_transmitter:
  pin: GPIO4      # Must match GDO0
  id: transmitter0
  carrier_duty_percent: 100%
  non_blocking: false
  on_transmit:
    then:
      - light.turn_on: blue_tx_led
      - cc1101.begin_tx
      - delay: 2s
      - light.turn_off: blue_tx_led
  on_complete:
    then:
      - cc1101.begin_rx

####        Uncomment to enable receiver
#remote_receiver:
#  pin:
#    number: GPIO25      # GDO2 (Optional for TX-only)
#    inverted: false
#  id: receiver0
#  dump: raw
#  filter: 150us   # Has worked for me
#  #filter: 250us
#  idle: 30ms         # Has worked for me
#  #idle: 40ms
#  #tolerance: 50%     # A guess
#  buffer_size: 10kb

button:
  - platform: template
    name: "Toy Room light"
    web_server:
      sorting_weight: 1
    on_press:
      - lambda: |-
          // Change frequency to 350 MHz before sending
          id(transceiver).set_frequency(350.0e6);
      - remote_transmitter.transmit_raw:
          code: [187,	-362,	180, -411, 194, -203,	392, -207,	388, -218,	380, -267,	330, -272,	327, -273,	328, -425,	181, -421,	180, -422,	180, -423,	177, -6953]
          repeat:
            times: 12
            wait_time: 0ms
      - logger.log: "Toy room light toggled"

  - platform: template
    name: "Kitchen light"
    web_server:
      sorting_weight: 5
    on_press:
      - logger.log: "Kitchen light pressed"
      - lambda: |-
          // Change frequency to 350 MHz before sending
          id(transceiver).set_frequency(350.0e6);
      - remote_transmitter.transmit_raw:
          code: [179, -399, 199, -193, 366, -221, 366, -220, 364, -220, 365, -221, 362, -221, 366, -221, 367, -442, 150, -444, 151, -417, 174, -415, 174, -6809]
          repeat:
            times: 12
            wait_time: 0ms
      - logger.log: "Kitchen light toggled"

  - platform: template
    name: "Dining Room light"
    web_server:
      sorting_weight: 10
    on_press:
      - lambda: |-
          // Change frequency to 433.92 MHz before sending
          id(transceiver).set_frequency(433.92e6);
      - remote_transmitter.transmit_raw:
          code: [403, -438, 359, -429, 380, -426, 378, -425, 376, -424, 377, -424, 376, -424, 376, -423, 377, -424, 377, -423, 376,
           -424, 377, -5202, 803, -396, 801, -397, 401, -801, 400, -798, 400, -799, 802, -397, 805, -397, 802, -396, 803, -398, 402,
            -799, 401, -797, 804, -397, 804, -398, 801, -397, 804, -396, 402, -798, 401, -798, 402, -801, 400, -797, 804, -397, 800,
             -398, 805, -398, 401, -798, 402, -798, 402, -798, 402, -798, 802, -398, 805, -397, 401, -797, 402, -800, 800, -397, 402,
              -798, 804, -397, 402, -798, 401, -798, 402, -800, 801, -397, 804, -397, 804, -398, 801, -398, 802, -397, 400, -800, 401,
               -799, 400, -799, 402, -799, 801, -398, 402, -798, 402, -799, 400, -798, 402, -799, 402, -798, 402, -799, 401, -797, 804,
                -398, 804, -397, 801, -398, 804, -397, 401, -797, 801, -398, 804, -398, 805, -397, 801, -398, 802, -397, 801, -398, 802, -397, 402, -2849]
          repeat:
            times: 2
            wait_time: 0ms
      - logger.log: "Dining room light toggled"

  - platform: template
    name: "Dining Room Fan Off"
    web_server:
      sorting_weight: 11
    on_press:
      - lambda: |-
          // Change frequency to 433.92 MHz before sending
          id(transceiver).set_frequency(433.92e6);
      - remote_transmitter.transmit_raw:
          code: [826, -400, 380, -426, 377, -424, 377, -424, 377, -423, 377, -399, 402, -398, 400, -423, 377, -423, 377, -423, 377, -424, 377, -5202, 800, -397, 801, -397, 402, -799, 402, -798, 401, -798, 804, -398, 803, -398, 801, -398, 800, -398, 402,
-799, 402, -799, 802, -398, 801, -398, 804, -397, 802, -397, 401, -799, 402, -799, 400, -798, 401, -799, 803, -397, 804, -397, 802, -397, 402, -799, 400, -799, 402, -800, 400, -798, 804, -398, 800, -398, 402, -799, 400, -799, 801, -399, 402, -799,
801, -398, 401, -799, 401, -799, 402, -799, 801, -397, 802, -398, 804, -398, 802, -398, 801, -398, 401, -799, 401, -799, 401, -798, 402, -799, 401, -799, 401, -799, 401, -799, 401, -799, 402, -798, 402, -799, 400, -798, 803, -399, 801, -398, 802,
-399, 801, -397, 803, -399, 800, -398, 803, -398, 804, -398, 801, -397, 802, -398, 801, -398, 802, -398, 402, -800, 400, -25644]
          repeat:
            times: 1
            wait_time: 0ms
      - logger.log: "Dining room fan turned off"

  - platform: template
    name: "Dining Room Fan ON"
    web_server:
      sorting_weight: 12
    on_press:
      - lambda: |-
          // Change frequency to 433.92 MHz before sending
          id(transceiver).set_frequency(433.92e6);
      - remote_transmitter.transmit_raw:
          code: [402, -2900, 275, -497, 299, -497, 300, -499, 327, -447, 350, -473, 325, -475, 326, -474, 326, -5239, 772, -444, 774, -422, 375, -823, 376, -824, 375, -799, 803, -397, 804, -398, 799, -422, 779, -423, 375, -825, 376, -824, 779, -423, 777,
-423, 776, -398, 802, -422, 375, -825, 377, -823, 376, -824, 376, -823, 778, -422, 779, -398, 804, -423, 374, -822, 377, -823, 376, -825, 378, -824, 776, -422, 778, -397, 401, -823, 376, -824, 778, -422, 377, -823, 779, -423, 375, -825, 375, -799,
400, -824, 778, -423, 778, -422, 778, -422, 776, -423, 776, -424, 376, -801, 401, -822, 377, -823, 377, -826, 375, -797, 803, -422, 376, -799, 402, -800, 401, -821, 376, -824, 377, -823, 377, -825, 777, -423, 776, -422, 779, -398, 801, -422, 779,
-422, 377, -800, 801, -422, 779, -397, 801, -398, 801, -397, 806, -397, 802, -423, 376, -25641]
          repeat:
            times: 2
            wait_time: 0ms
      - logger.log: "Dining room fan turned on"

  - platform: template
    name: "Living Room light"
    web_server:
      sorting_weight: 15
    on_press:
#      - logger.log: "Living room button pressed"
      - lambda: |-
          // Change frequency to 433.92 MHz before sending
          id(transceiver).set_frequency(433.92e6);
      - remote_transmitter.transmit_raw:
          code: [401, -445, 343, -466, 317, -466, 344, -468, 323, -468, 349, -445, 350, -446, 352, -448, 351, -447, 353, -448, 376, -422, 377, -5225, 779, -421, 377, -823, 779, -395, 403, -798, 402, -821, 778, -397, 804, -396, 402, -798, 402, -822, 378,
-799, 402, -821, 779, -421, 377, -822, 780, -420, 781, -421, 378, -822, 377, -799, 402, -822, 378, -821, 780, -421, 378, -799, 804, -396, 803, -395, 805, -420, 780, -420, 378, -821, 778, -423, 377, -821, 378, -822, 377, -823, 778, -422, 780, -421,
378, -800, 401, -821, 377, -823, 378, -822, 780, -421, 377, -801, 801, -396, 402, -822, 779, -422, 377, -800, 403, -797, 402, -797, 804, -396, 403, -797, 402, -798, 401, -821, 378, -822, 378, -822, 378, -799, 403, -799, 401, -798, 804, -396, 804,
-395, 804, -421, 377, -824, 780, -396, 800, -421, 779, -421, 779, -422, 779, -396, 805, -396, 803, -421, 779, -421, 377, -25648]
          repeat:
            times: 5
            wait_time: 0ms
      - logger.log: "Living room light toggled"

  - platform: template
    name: "Living Room fan off"
    web_server:
      sorting_weight: 16
    on_press:
      - lambda: |-
         // Change frequency to 433.92 MHz before sending
          id(transceiver).set_frequency(433.92e6);
      - remote_transmitter.transmit_raw:
          code: [275, -1326, 275, -526, 200, -600, 251, -550, 275, -501, 300, -500, 300, -501, 300, -500, 301, -650, 150, -626, 150, -5354, 651, -1726, 675, -2928, 675, -526, 675, -526, 300, -900, 276, -975, 151, -2677, 175, -550, 250, -1051, 551, -825,
250, -5480, 675, -1726, 676, -500, 476, -4353, 651, -8982, 225,
-7030, 225, -6480, 326, -550, 250, -1251, 275, -4279, 200, -976, 225, -951, 225, -1076, 175, -2477, 150, -3227, 526, -525, 300, -1026, 150, -926, 275, -2152, 200, -2452, 400, -526, 675, -525, 676, -2927, 651, -1726, 300, -901, 300, -926,
675, -501, 675, -551, 250, -1001, 200, -2127, 300, -900, 701, -500, 301, -1301, 275, -525, 275, -1126, 476, -650, 150, -926, 300, -901, 300, -901, 275, -926, 275, -951, 250, -926, 675, -551, 175, -975, 301, -900, 301, -900, 676, -550, 200, -1001, 676,
-500, 701, -525, 676, -500, 700, -501, 700, -501, 700, -501, 300, -901, 700, -526, 675, -526, 675, -500, 301, -900, 701, -500, 301, -25744, 301, -500, 325, -476, 325, -475, 325, -476, 300, -500, 326, -475, 325, -476, 325, -475, 301, -500, 300, -501,
300, -475, 325, -5280, 725, -500, 301, -900, 701, -475, 326, -900, 300, -876, 726, -475, 726, -475, 325, -876, 325, -876, 325, -876, 325, -876, 725, -476, 325, -876, 725, -475, 726, -475, 326, -875, 326, -875, 325, -876, 325, -876, 726, -450, 350,
-851, 751, -450, 750, -476, 725, -451, 750, -451, 350, -851, 750, -450, 351, -850, 351, -850, 351, -850, 751, -450, 751, -450, 325, -876, 350, -851, 350, -851, 325, -876, 725, -476, 325, -876, 725, -451, 350, -876, 725, -450, 351, -850, 351, -850,
351, -850, 350, -851, 350, -851, 350, -851, 751, -450, 350, -851, 350, -851, 350, -851, 750, -451, 350, -851, 750, -450, 751, -450, 751, -450, 751, -450, 751, -450, 751, -450, 350, -851, 751, -425, 776, -425, 775, -426, 375, -826, 750, -451, 375]
          repeat:
            times: 1
            wait_time: 10ms
      - logger.log: "Living room fan turned off"

  - platform: template
    name: "LR fan speed 2"
    web_server:
      sorting_weight: 18
    on_press:
      - lambda: |-
         // Change frequency to 433.92 MHz before sending
          id(transceiver).set_frequency(433.92e6);
      - remote_transmitter.transmit_raw:
          code: [401, -436, 367, -417, 372, -444, 349, -446, 350, -447, 377, -422, 378, -423, 377, -423, 377, -423, 377, -421, 376, -422, 378, -5203, 803, -396, 402, -796, 805, -395, 402, -796, 403, -797, 804, -396, 805, -396, 403, -797, 403, -796, 403,
-822, 378, -824, 780, -421, 377, -823, 778, -420, 778, -422, 378, -821, 378, -822, 378, -825, 377, -822, 778, -421, 377, -823, 777, -421, 781, -397, 804, -421, 778, -420, 378, -823, 777, -422, 377, -822, 379, -823, 378, -822, 777, -421, 779, -422,
377, -822, 378, -822, 377, -822, 379, -823, 780, -421, 377, -822, 779, -423, 377, -822, 779, -422, 377, -823, 377, -822, 377, -822, 378, -822, 377, -822, 378, -823, 777, -422, 377, -822, 378, -823, 377, -822, 378, -823, 377, -822, 778, -422, 780,
-424, 778, -421, 779, -421, 779, -421, 777, -421, 377, -823, 780, -422, 780, -421, 776, -422, 779, -421, 779, -421, 377, -25642, 400, -530, 206, -1365, 230, -627, 227, -474, 328, -473, 328, -475, 327, -473, 326, -448, 352, -447, 352, -448, 378, -5207,
802, -420, 375, -821, 776, -422, 378, -822, 378, -822, 777, -422, 780, -421, 378, -823, 377, -822, 378, -825, 376, -821, 777, -422, 378, -825, 779, -421, 778, -420, 378, -824, 377, -821, 378, -822, 377, -825, 778, -396, 403, -822, 778, -397, 805,
-396, 803, -420, 778, -421, 378, -823, 778, -421, 378, -822, 377, -822, 378, -823, 778, -421, 781, -422, 378, -821, 377, -822, 378, -824, 377, -797, 802, -422, 377, -824, 777, -422, 378, -823, 780, -422, 378, -823, 377, -798, 400, -821, 378, -824,
377, -824, 378, -822, 778, -422, 376, -822, 378, -798, 401, -822, 378, -825, 377, -821, 779, -422, 779, -421, 779, -421, 780, -420, 779, -421, 779, -420, 377, -824, 780, -420, 778, -421, 779, -421, 778, -421, 778, -421, 377]
          repeat:
            times: 1
            wait_time: 10ms
      - logger.log: "Living room fan speed 2"

  - platform: template
    name: "LR fan speed 1"
    web_server:
      sorting_weight: 17
    on_press:
      - lambda: |-
         // Change frequency to 433.92 MHz before sending
          id(transceiver).set_frequency(433.92e6);
      - remote_transmitter.transmit_raw:
          code: [351, -450, 350, -451, 350, -450, 350, -451, 350, -450, 351, -450, 350, -451, 350, -450, 351, -450, 350, -450, 351, -450, 350, -5229, 776, -425, 351, -850, 776, -425, 375, -826, 350, -851, 751, -450, 751, -450, 350, -851, 350, -851, 350,
-851, 350, -851, 750, -451, 350, -850, 751, -450, 751, -450, 351, -850, 350, -851, 350, -851, 350, -851, 751, -450, 350, -851, 750, -451, 750, -451, 750, -451, 750, -426, 375, -850, 751, -425, 351, -850, 376, -825, 351, -850, 751, -450, 751, -450,
350, -851, 350, -851, 350, -851, 350, -851, 750, -451, 350, -851, 750, -450, 351, -850, 751, -450, 351, -850, 351, -850, 350, -851, 350, -851, 350, -851, 325, -876, 325, -876, 350, -851, 350, -826, 375, -851, 750, -451, 325, -850, 751, -475, 726,
-450, 751, -450, 751, -450, 751, -450, 751, -450, 751, -450, 751, -450, 750, -451, 750, -451, 350, -851, 750, -451, 350, -25695, 350, -450, 351, -475, 325, -476, 325, -475, 325, -476, 325, -450, 351, -450, 350, -451, 350, -450, 350, -451, 350, -450,
351, -5254, 750, -451, 350, -851, 750, -451, 350, -850, 351, -850, 751, -450, 751, -450, 351, -825, 375, -851, 350, -851, 350, -851, 751, -450, 350, -826, 775, -451, 750, -426, 375, -826, 375, -825, 351, -850, 351, -850, 776, -425, 376, -825, 751,
-450, 751, -450, 751, -450, 751, -450, 350, -851, 750, -451, 350, -851, 350, -851, 350, -851, 750, -450, 751, -450, 351, -850, 351, -825, 376, -825, 375, -826, 776, -425, 375, -826, 776, -425, 375, -826, 775, -426, 375, -826, 375, -826, 375, -825,
376, -825, 351, -850, 351, -850, 351, -850, 350, -851, 350, -851, 350, -851, 751, -450, 350, -851, 750, -451, 750, -451, 750, -451, 750, -451, 750, -450, 751, -450, 751, -450, 751, -450, 751, -450, 751, -450, 350, -851, 751, -450, 350]
          repeat:
            times: 1
            wait_time: 10ms
      - logger.log: "Living room fan speed 1"

time:
  - platform: homeassistant
    id: my_time

text_sensor:
# Send Uptime in raw seconds                                                                                                                                                                                                           
  - platform: template
    name: $friendly_name Uptime HR
    id: uptime_human
    icon: mdi:clock-start
    entity_category: "diagnostic"
    web_server:
      sorting_weight: 25

  - platform: version
    name: $friendly_name Version
    id: device_esphome_version
    internal: false
    icon: 'mdi:chevron-right'
    web_server:
      sorting_weight: 3
   
# Expose WiFi information as sensors.
  - platform: wifi_info
    ip_address:  
      name: IP
      id: IP
      web_server:
        sorting_group_id: sorting_group_ip_settings
        sorting_weight: 5
      address_1:
        name: IPv6 LL
        web_server:
          sorting_group_id: sorting_group_ip_settings
          sorting_weight: 15
      address_2:
        name: IPv6 routed
        web_server:
          sorting_group_id: sorting_group_ip_settings
          sorting_weight: 10
 
    ssid:
      name: SSID
      web_server:
        sorting_group_id: sorting_group_wifi
        sorting_weight: 6
    mac_address:
      name: ESP Mac Wifi Address
      web_server:
        sorting_group_id: sorting_group_wifi
        sorting_weight: 10
    #scan_results:
    #  name: ESP Latest Scan Results
  
  - platform: debug
    reset_reason:
      name: "Reset Reason"

sensor:
    # Uptime sensor.
  - platform: uptime
    name: $friendly_name Uptime
    id: uptime_sensor
    update_interval: 60s
    internal: true
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            # Custom C++ code to generate the result                                                                                                                                                                                     
            state: !lambda |-
              int seconds = round(id(uptime_sensor).get_raw_state());
              int days = seconds / (24 * 3600);                                                                                                                                                                                          
              seconds = seconds % (24 * 3600);                                                                                                                                                                                           
              int hours = seconds / 3600;                                                                                                                                                                                                
              seconds = seconds % 3600;                                                                                                                                                                                                  
              int minutes = seconds /  60;                                                                                                                                                                                               
              seconds = seconds % 60;                                                                                                                                                                                                    
              return (                                                                                                                                                                                                                   
                (days ? to_string(days) + "d " : "") +
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();
   
  # WiFi Signal sensor.
  - platform: wifi_signal
    name: WiFi Signal
    update_interval: 60s
    web_server:
        sorting_group_id: sorting_group_wifi
        sorting_weight: 20

#  - platform: internal_temperature
#    name: "ESP32 Internal Temperature"
 #   update_interval: 60s
 #   unit_of_measurement: "°F"
 #   filters:
 #     - lambda: return x * (9.0/5.0) + 32.0;
    
binary_sensor:  
  - platform: status
    name: "Connected"
    web_server:
        sorting_group_id: sorting_group_wifi
        sorting_weight: 5

switch:
  - platform: restart
    name: "Restart"