question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use binary sensors

See original GitHub issue

Problem description Follow up of discussion in #159

MCCQ02HL and WX08ZM sensors are currently discovered as sensors with on/off state. However, these sensors are actually binary_sensors, not sensors. This causes that the sensors are only able to show on/off and not e.g. closed/open.

(Possible) Solution This issue is to discuss how to solve this. The final goal should be that binary sensors are discovered with the proper device class, and show their appropriate state.

Proposal for device classes MCCQ02HL --> open/close (DEVICE_CLASS: opening) MCCQ02HL --> light/dark (DEVICE_CLASS: light) WX08ZM --> power detected/no power (DEVICE_CLASS: power)

To Do

To achieve this, we should

  • move the monitoring to __init__.py (integration level)
  • keep the add_enties in sensor.py and binary_sensor.py at platform level)
  • move BLE ADV parser to HCIdump thread because this is the only way we can sort messages (see next task)
  • split the incoming messages into two separate queues (one for each platform)?
  • move the SwitchingSensors to binary_sensor.py

Findings of other examples that could help I think the smarty can be used as an base example, although it has part of the code in a pypi package (pysmarty).

What I found in the smarty component, is that there are two links between __init__.py and e.g. sensor.py Data

  • in __init__.py, data is collected in smarty and this is passed to hass.data[DOMAIN]
    smarty = Smarty(host=host)
    hass.data[DOMAIN] = {"api": smarty, "name": name}
  • in sensor.py it gets the data via smarty = hass.data[DOMAIN]["api"]

Updating

  • It uses dispatcher_send(hass, SIGNAL_UPDATE_SMARTY) in __init__.py after receiving data
  • In sensor.py it uses this in the entity.
    async def async_added_to_hass(self):
        """Call to update."""
        async_dispatcher_connect(self.hass, SIGNAL_UPDATE_SMARTY, self._update_callback)

    @callback
    def _update_callback(self):
        """Call update method."""
        self.async_schedule_update_ha_state(True)

Not entirely sure how this update link exactly works.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:16

github_iconTop GitHub Comments

1reaction
andrewjswancommented, Nov 27, 2020

Please make this as a separate issue.

Request done - https://github.com/custom-components/ble_monitor/issues/176 😃

1reaction
Magalex2x14commented, Nov 27, 2020

Recovering the state after the start is now working for all types of sensors, whether it is possible to make a separate option to recover the values of the battery state, the state of conventional sensors and the state of binary sensors (I am not sure that this is necessary at all).

Please make this as a separate issue. I agree it’s worth doing. Or maybe a separate option per device…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binary Sensor - Home Assistant
Binary sensors are similar to other sensors in that they monitor the states and conditions of different entities. Where binary sensors differ is...
Read more >
What are binary sensors in Home Assistant?
Binary sensors in Home Assistant are sensors which can only ever have one of two states. Their state is either a 0 or...
Read more >
Binary Sensor Component - ESPHome
With ESPHome you can use different types of binary sensors. They will automatically appear in the Home Assistant front-end and have several configuration ......
Read more >
ESPHome Binary Sensors, Switches & Sensor Configuration
All numbered zones can be configured for binary sensors in ESPHome using the GPIO Binary Sensor platform. This is how you would configure ......
Read more >
On Optimal Arrangements of Binary Sensors - Springer
A large range of monitoring applications can benefit from binary sensor networks. Binary sensors can detect the presence or absence of a particular...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found