esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

Entity category not working #3111

Closed alnavasa closed 2 years ago

alnavasa commented 2 years ago

The problem

I have modified (not newly created) a code from an existing device, a ESP device to have the human readable uptime sensor show where it should under diagnostic tab. but it shows between all other sensors:

code used:

    entity_category: diagnostic

how it looks :

Captura de pantalla 2022-03-03 a las 13 18 21

this part is the one not working as specked


  - platform: uptime
    name: Uptime Sensor
    id: uptime_sensor
    update_interval: 60s
    entity_category: diagnostic
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).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();

Which version of ESPHome has the issue?

2022.2.6

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

2022.3.0

What platform are you using?

ESP8266

Board

ESP8266

Component causing the issue

uptime

Example YAML snippet

esphome:
  name: telefonillo

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxx"
ota:
  password: "xxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Telefonillo Fallback Hotspot"
    password: "xxxx"

captive_portal:

text_sensor:
  - platform: template
    name: Uptime Human Readable
    id: uptime_human
    icon: mdi:clock-start

  - platform: wifi_info
    ip_address:
      name: Telefonillo IP
    ssid:
      name: Telefonillo SSID
    bssid:
      name: Telefonillo BSSID

sensor:
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s

  - platform: uptime
    name: Uptime Sensor
    id: uptime_sensor
    update_interval: 60s
    entity_category: diagnostic
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).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();

status_led:
  pin:
    number: GPIO3
    inverted: false

###################

globals:
  - id: chime
    type: bool
    restore_value: true
    initial_value: 'true'

switch:
  - platform: restart
    name: "Telefonillo Restart"

  - platform: gpio
    pin: GPIO12
    name: "Abridor Puerta"
    icon: mdi:door-closed
    restore_mode: always_off
    id: r1
    on_turn_on:
    - delay: 2000ms
    - switch.turn_off: r1

  - platform: gpio
    pin: GPIO14
    name: "Telefonillo"
    icon: mdi:bell
    restore_mode: always_off
    id: r2
    on_turn_on:
    - delay: 2000ms
    - switch.turn_off: r2

  - platform: template
    name: "Telefonillo Timbre Activado"
    icon: mdi:alarm-bell
    id: chime_active
    restore_state: false
    turn_on_action:
      - globals.set:
          id: chime
          value: 'true'
    turn_off_action:
      - globals.set:
          id: chime
          value: 'false'
    lambda: |-
      return id(chime);

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
#Externall pullup fitted, un-coment if using a decent board with proper internall pullups.
#      mode: INPUT_PULLUP
      inverted: True
    name: "Telefonillo"
    icon: mdi:gesture-tap-button
    on_press:
      then:
        if:
          condition:
            - switch.is_on: chime_active
          then:
            - switch.turn_on: r2
            - delay: 2000ms
            - switch.turn_off: r2
    filters:
      - delayed_on: 200ms
      - delayed_off: 3000ms 

  - platform: status
    name: "Status Telefonillo"


### Anything in the logs that might be useful for us?

_No response_

### Additional information

As mentioned, I had this device running for some time and today decided to implement this category, edited the code and uploaded the code OTA to the device.
alnavasa commented 2 years ago

Solved: entity_category: diagnostic needs to be added to the template sensor not the uptime sensor.

text_sensor:
  - platform: template
    name: Uptime Human Readable
    id: uptime_human
    entity_category: diagnostic
    icon: mdi:clock-start