home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.92k stars 30.98k forks source link

Rflink sensor_type battery is missing device_class #128664

Closed fsaris closed 1 month ago

fsaris commented 1 month ago

The problem

Sensors defined as battery don't get the device_type battery

What version of Home Assistant Core has the issue?

core-2024.10.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

rflink

Link to integration documentation on our website

No response

Diagnostics information

Sensors defined as battery don't get the device_type battery

homeassistant/components/rflink/sensor.py

SensorEntityDescription(
        key="battery",
        name="Battery",
        icon="mdi:battery",
    ),

Could be updated to the following to resolve this:

SensorEntityDescription(
        key="battery",
        name="Battery",
        device_class=SensorDeviceClass.BATTERY,
    ),

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 month ago

Hey there @javicalle, mind taking a look at this issue as it has been labeled with an integration (rflink) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `rflink` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign rflink` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


rflink documentation rflink source (message by IssueLinks)

mib1185 commented 1 month ago

Hi @fsaris Home Assistant is an open source projects, those lives from contributions of the community. Therefore any contribution would be highly appreciated :heart: so if you're are comfortable with this, feel free to create a pull request to adjust this.

epenet commented 1 month ago

As discussed in #128873, adding the device class would not be valid

Rflink devises reports ok/low so devise class can’t be used

fsaris commented 1 month ago

Tnx for your effort.

For now I created a helper that turns the low/ok value into a % to work around this

javicalle commented 3 weeks ago

Sorry for the late reply. I can't test myself but maybe you can just configure it as a binary_sensor like this:

binary_sensor:
   - platform: rflink
     devices:
       oregontemp_0d93_bat:
         name: Weather battery
         device_class: battery
fsaris commented 2 weeks ago

@javicalle that doesn't seem to work. Somehow it still creates the sensor.digoo_2_battery instead of updating binary_sensor.digoo_2_battery':

yaml

binary_sensor:
  - platform: rflink
    devices:
      tunex_f301_bat:
        name: 'DIGOO 2 battery'
        device_class: battery
        aliases:
          - xiron_f301_bat

Debug logs:

2024-11-08 21:45:48.143 DEBUG (MainThread) [rflink.protocol] received data: 20;02;Tunex;ID=F301;TEMP=00b7;HU
2024-11-08 21:45:48.147 DEBUG (MainThread) [rflink.protocol] received data: M=72;BAT=OK;
2024-11-08 21:45:48.147 DEBUG (MainThread) [rflink.protocol] got packet: 20;02;Tunex;ID=F301;TEMP=00b7;HUM=72;BAT=OK;
2024-11-08 21:45:48.147 DEBUG (MainThread) [rflink.protocol] decoded packet: {'node': 'gateway', 'protocol': 'tunex', 'id': 'f301', 'temperature': 18.3, 'temperature_unit': '°C', 'humidity': 72, 'humidity_unit': '%', 'battery': 'ok'}
2024-11-08 21:45:48.148 DEBUG (MainThread) [rflink.protocol] got event: {'id': 'tunex_f301_temp', 'sensor': 'temperature', 'value': 18.3, 'unit': '°C'}
2024-11-08 21:45:48.148 DEBUG (MainThread) [homeassistant.components.rflink] event of type sensor: {'id': 'tunex_f301_temp', 'sensor': 'temperature', 'value': 18.3, 'unit': '°C'}
2024-11-08 21:45:48.148 DEBUG (MainThread) [homeassistant.components.rflink] entity_ids: ['sensor.digoo_2_temp']
2024-11-08 21:45:48.148 DEBUG (MainThread) [homeassistant.components.rflink] passing event to sensor.digoo_2_temp
2024-11-08 21:45:48.148 DEBUG (MainThread) [rflink.protocol] got event: {'id': 'tunex_f301_hum', 'sensor': 'humidity', 'value': 72, 'unit': '%'}
2024-11-08 21:45:48.149 DEBUG (MainThread) [homeassistant.components.rflink] event of type sensor: {'id': 'tunex_f301_hum', 'sensor': 'humidity', 'value': 72, 'unit': '%'}
2024-11-08 21:45:48.149 DEBUG (MainThread) [homeassistant.components.rflink] entity_ids: ['sensor.digoo_2_hum']
2024-11-08 21:45:48.149 DEBUG (MainThread) [homeassistant.components.rflink] passing event to sensor.digoo_2_hum
2024-11-08 21:45:48.149 DEBUG (MainThread) [rflink.protocol] got event: {'id': 'tunex_f301_bat', 'sensor': 'battery', 'value': 'ok', 'unit': None}
2024-11-08 21:45:48.149 DEBUG (MainThread) [homeassistant.components.rflink] event of type sensor: {'id': 'tunex_f301_bat', 'sensor': 'battery', 'value': 'ok', 'unit': None}
2024-11-08 21:45:48.149 DEBUG (MainThread) [homeassistant.components.rflink] entity_ids: ['sensor.digoo_2_battery']
2024-11-08 21:45:48.149 DEBUG (MainThread) [homeassistant.components.rflink] passing event to sensor.digoo_2_battery
2024-11-08 21:45:48.149 DEBUG (MainThread) [rflink.protocol] got event: {'id': 'tunex_f301_update_time', 'sensor': 'update_time', 'value': 1731098748, 'unit': 's'}
2024-11-08 21:45:48.150 DEBUG (MainThread) [homeassistant.components.rflink] event of type sensor: {'id': 'tunex_f301_update_time', 'sensor': 'update_time', 'value': 1731098748, 'unit': 's'}
2024-11-08 21:45:48.150 DEBUG (MainThread) [homeassistant.components.rflink] entity_ids: ['sensor.tunex_f301_update_time']
2024-11-08 21:45:48.150 DEBUG (MainThread) [homeassistant.components.rflink] passing event to sensor.tunex_f301_update_time
javicalle commented 2 weeks ago

Ummm, I see the reason now: binary_sensor only responds to "command" events and not to "sensor" events like these:

2024-11-08 21:45:48.149 DEBUG (MainThread) [homeassistant.components.rflink] event of type sensor: {'id': 'tunex_f301_bat', 'sensor': 'battery', 'value': 'ok', 'unit': None}

Probably because motion detectors triggers command events and were the first use case for RFLink binary sensors.

Not an easy fix.

Thanks for testing anyway.

Regards