d03n3rfr1tz3 / hass-divoom

Divoom Integration for Home Assistant
MIT License
109 stars 9 forks source link

Feature Request: Triggering a Beep Sound on Pixoo (16) #36

Closed Bluehuu closed 3 months ago

Bluehuu commented 5 months ago

I am currently using the Divoom Pixoo (16) and integrating it with Home Assistant. I know the device has a built-in buzzer, and it is possible to program an alarm that triggers beeps. However, I would like to know if there is a way to make the Pixoo beep on demand without setting an alarm.

This functionality would be useful for triggering alerts in Home Assistant. For example, I have a binary sensor, and I would like the Pixoo to beep when the binary is on, providing an audible alert.

Is there a method or an API call that allows triggering a beep directly? If not, are there any plans to include this feature in future updates?

d03n3rfr1tz3 commented 5 months ago

Sadly there is no command in the Divoom Bluetooth protocol that I'm aware of, that could do that. Rule of thumb: If it's not in the Divoom app, it's very likely also not in the underlying protocol. And if I'm not mistaken, there is no functionality for making it beep on demand. If I'm mistaken and there is such a functionality in the app, you can guide me to that function and I'm happy to debug the underlying bluetooth code and extend the functionality of this integration. For now, there is no direct way to make it beep.

BUT, you could use the timer-mode and set it to "00:01", which is one second. It would beep after one second afaik. Of course that would also display the timer and the alarm animation, but you could overwrite it (probably with another short delay) by sending an image or whatever else you want to display.

Bluehuu commented 5 months ago

Thank you for the suggestion.

I don't think the option is present in the app. I looked at the Official Pixoo docs and found this link.

I tried implementing something in Python but was not successful. Here's the code I attempted in case it helps or has any logic that can be built upon:


# Additional Parameters (notify.py)
PARAM_BUZZER = 'buzzer'
PARAM_ACTIVE_TIME = 'active_time'
PARAM_OFF_TIME = 'off_time'
PARAM_TOTAL_TIME = 'total_time'

# Add buzzer to the VALID_MODES set (notify.py)
VALID_MODES = {'on', 'off', 'connect', 'disconnect', 'clock', 'light', 'effects', 'visualization', 
               'scoreboard', 'lyrics', 'design', 'image', 'brightness', 'datetime', 'game', 
               'gamecontrol', 'keyboard', 'playstate', 'radio', 'volume', 'weather', 'countdown', 
               'noise', 'timer', 'alarm', 'memorial', 'raw', 'buzzer'}

# Add buzzer mode in class DivoomNotificationService (notify.py)

def send_message(self, message="", **kwargs):
    if message == "" and kwargs.get(ATTR_DATA) is None:
        _LOGGER.error("Service call needs more information")
        return False

    data = kwargs.get(ATTR_DATA) or {}
    mode = data.get(PARAM_MODE) or message

    if mode != "connect" and mode != "disconnect":
        skipPing = True if mode == "gamecontrol" or mode == "raw" else False
        self._device.reconnect(skipPing=skipPing)

    if mode == 'buzzer':
        active_time = data.get(PARAM_ACTIVE_TIME, 500)
        off_time = data.get(PARAM_OFF_TIME, 500)
        total_time = data.get(PARAM_TOTAL_TIME, 3000)
        self._device.play_buzzer(active_time=active_time, off_time=off_time, total_time=total_time)

    # rest of the code ...
    else:
        _LOGGER.error("Invalid mode '{0}', must be one of 'on', 'off', 'connect', 'disconnect', 'clock', 'light', 'effects', 'visualization', 'scoreboard', 'lyrics', 'design', 'image', 'brightness', 'datetime', 'game', 'gamecontrol', 'keyboard', 'playstate', 'radio', 'volume', 'weather', 'countdown', 'noise', 'timer', 'alarm', 'memorial', 'raw', 'buzzer'".format(mode))
        return False

    return True

# Add buzzer mode in Pixoo class (pixoo.py)

def play_buzzer(self, active_time=500, off_time=500, total_time=3000):
    payload = {
        "Command": "Device/PlayBuzzer",
        "ActiveTimeInCycle": active_time,
        "OffTimeInCycle": off_time,
        "PlayTotalTime": total_time
    }
    self.send_command(payload)

# activates the buzzer (test message in Home Assistant)
message: 'buzzer'
data:
  active_time: 500
  off_time: 500
  total_time: 3000
d03n3rfr1tz3 commented 5 months ago

What you found is the API for the Pixoo16, which is WiFi based. The normal Pixoo (which is also 16x16) is Bluetooth (classic) based. This whole HA Integration is currently only for the Bluetooth based Divoom devices, not for the WiFi devices, like the Pixoo16 and the Pixoo64. Therefore your code cannot work 😉

This is the original Pixoo: https://divoom.com/products/divoom-pixoo (Bluetooth based) This is the Pixoo-16 from Kickstarter: https://www.kickstarter.com/projects/divoom/pixoo-16-the-all-in-one-pixel-art-wifi-decoration-display (WiFi based) Yes both are from Divoom... and yes, the naming is questionable.