esphome-econet / esphome-econet

esphome-econet is a package for controlling a Rheem water heater or HVAC system with an esp32 or esp8266 micro-computer.
https://esphome-econet.github.io/
Other
114 stars 28 forks source link

Utilize LED on the M5 to Indicate Power / Activity #241

Closed stockmopar closed 9 months ago

Daniel-dev22 commented 10 months ago

This depends on the user having an M5 stack though. Unless we can make it optional?

BigThunderSR commented 10 months ago

Pretty much every ESP32 board available these days has a status LED (although not multi-color like the M5) that can be enabled on GPIO2, so it would be good if enabling the status LED was available for all boards with the option to customize the GPIO pin as necessary. Thanks.

stockmopar commented 10 months ago

Looks like here's an example of controlling the LED:

https://github.com/m5stack/M5Atom/blob/00f5a14e1cf6c25d16a4dd011a5f971bca29ec43/examples/Basics/FactoryTest/ATOM_LITE/ATOM_LITE.ino#L4

stockmopar commented 10 months ago

This page: https://community.home-assistant.io/t/atom-lite-rgb-led-turns-on-by-itself/452852/6

Gives this yaml to try:

light:
  - platform: esp32_rmt_led_strip
    rgb_order: GRB
    pin: 27
    num_leds: 1
    rmt_channel: 0
    chipset: SK6812
    id: status_led
    name: ${name} Light
    effects:
      - random:
      - flicker:
      - addressable_rainbow:
barndawgie commented 10 months ago

This is my Atom Lite config:

---
binary_sensor:
  - platform: gpio
    id: atom_button
    pin:
      number: GPIO39
      inverted: true
    name: "ATOM Lite Button"
    icon: "mdi:gesture-tap-button"
    entity_category: "config"
    disabled_by_default: true

light:
  - platform: esp32_rmt_led_strip
    name: "ATOM Lite LED"
    id: atom_led
    pin: GPIO27
    chipset: SK6812
    num_leds: 1
    rmt_channel: 0
    rgb_order: GRB
    icon: "mdi:led-off"
    entity_category: "config"
    disabled_by_default: true

output:
  - platform: template
    id: atom_led_output
    type: binary
    write_action:
      if:
        condition:
          lambda: return state;
        then:
          - light.turn_on: atom_led
        else:
          - light.turn_off: atom_led

# esp32_improv:
#   authorizer: atom_button
#   status_indicator: atom_led_output

I haven't been able to get the BLE Improv working. Or rather, it works, but results in repeated wi-fi disconnects that I haven't been able to troubleshoot. But the light and button for sure work. I haven't figured out how to control the LED color yet, though. Maybe those "effects" are what I need.

barndawgie commented 10 months ago

What exactly do we think it would look like to "use" this LED? GIve wi-fi connectivity status? Successful comms with the Rheem unit in the last X minutes?

BigThunderSR commented 10 months ago

What exactly do we think it would look like to "use" this LED? GIve wi-fi connectivity status? Successful comms with the Rheem unit in the last X minutes?

On the generic ESP32 boards, the status LED flashes while the board is booting up and stays off as long as things are functioning as expected (Inverted mode set to off). It starts flashing when the code hangs up for example when a connected sensor is not responding to or providing data as expected, so it is helpful to see if something is amiss. I'm hoping you can provide a similar functionality here as well. Thanks.

BigThunderSR commented 10 months ago

This is my Atom Lite config:


---
binary_sensor:
  - platform: gpio
    id: atom_button
    pin:
      number: GPIO39
      inverted: true
    name: "ATOM Lite Button"
    icon: "mdi:gesture-tap-button"
    entity_category: "config"
    disabled_by_default: true

ESPHome does not let you enable the button in HA if "entity_category:" is set to "config", but it works if you either do not set the "entity_category:" or set it as: _entitycategory: "diagnostic"

barndawgie commented 10 months ago

ESPHome does not let you enable the button in HA if "entity_category:" is set to "config", but it works if you either do not set the "entity_category:" or set it as: _entitycategory: "diagnostic"

I'm not sure what you mean. It shows up for me in the config section (as a binary sensor).

BigThunderSR commented 10 months ago

ESPHome does not let you enable the button in HA if "entity_category:" is set to "config", but it works if you either do not set the "entity_category:" or set it as: _entitycategory: "diagnostic"

I'm not sure what you mean. It shows up for me in the config section (as a binary sensor).

I'm on HA 2023.12 and the latest version of ESPHome and the button shows up under config when it is not enabled which is the default. If you try to enable it, it throws an error in the HA logs stating that you cannot enable that component under config and the button goes away. Note the last line in the error log output below:


Source: helpers/entity_platform.py:509
Integration: Binary sensor ([documentation](https://www.home-assistant.io/integrations/binary_sensor), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+binary_sensor%22))
First occurred: 6:57:44 PM (1 occurrences)
Last logged: 6:57:44 PM

Error adding entities for domain binary_sensor with platform esphome
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 509, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 754, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in add_to_platform_finish
    await self.async_internal_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 198, in async_internal_added_to_hass
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Entity binary_sensor.esphome_hphw_gen4_atom_lite_button cannot be added as the entity category is set to config
BigThunderSR commented 10 months ago

This works great to control the LED!

https://github.com/esphome-econet/esphome-econet/discussions/118#discussioncomment-7804224

barndawgie commented 10 months ago

ESPHome does not let you enable the button in HA if "entity_category:" is set to "config", but it works if you either do not set the "entity_category:" or set it as: _entitycategory: "diagnostic"

I'm not sure what you mean. It shows up for me in the config section (as a binary sensor).

I'm on HA 2023.12 and the latest version of ESPHome and the button shows up under config when it is not enabled which is the default. If you try to enable it, it throws an error in the HA logs stating that you cannot enable that component under config and the button goes away. Note the last line in the error log output below:

Source: helpers/entity_platform.py:509
Integration: Binary sensor ([documentation](https://www.home-assistant.io/integrations/binary_sensor), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+binary_sensor%22))
First occurred: 6:57:44 PM (1 occurrences)
Last logged: 6:57:44 PM

Error adding entities for domain binary_sensor with platform esphome
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 509, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 754, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in add_to_platform_finish
    await self.async_internal_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 198, in async_internal_added_to_hass
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Entity binary_sensor.esphome_hphw_gen4_atom_lite_button cannot be added as the entity category is set to config

I'm almost certain this was working for me, but now I get the error that you mention. I believe the issue is that config entities are meant to be ones that you can use to change device behavior (i.e. not just read-only types like binary_sensor).

I think the "fix" might be to expose the button as a button to Home Assistant.

barndawgie commented 9 months ago

I've added an example ATOM Lite config to the wiki. GIven that we want to support multiple device types, I'm not sure it makes sense to build this into our configs.