HAP-python icon indicating copy to clipboard operation
HAP-python copied to clipboard

Pulling data from Homekit

Open netmanchris opened this issue 7 years ago • 3 comments

Great project! Looking forward to hacking away in python on my favourite smarthome ecosystem. Does HAP-Python allow for pulling data from homekit as well? Can I list homekit accessories? List attributes of homekit accessories? Grab data points of homekit accessories?

Curious if it’s possible to finally grab data points and provide a cross-vendor historical graph for things like temp or power draw.

Thanks for the great work!

netmanchris avatar May 29 '18 14:05 netmanchris

Hey thanks for the nice words and also sorry for the late reply!

You can pull data, but you would need to register your hooks to collect this data. For example:

def collect(value):
    pass  # logic to collect value. The method will be called every time the value of the char changes

class TemperatureSensor(Accessory):

    category = CATEGORY_SENSOR

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        serv_temp = self.add_preload_service('TemperatureSensor')
        # Add a callback to the temperature characteristic
        self.char_temp = serv_temp.configure_char('CurrentTemperature', setter_callback=collect)

    @Accessory.run_at_interval(3)
    def run(self):
        self.char_temp.set_value(random.randint(18, 26))

For listing accessories (I assume you will be using a Bridge, otherwise it's just one accessory) you can just do bridge.accessories.

For the attributes - what exactly do you need? An accessory is pretty much a container for services, which in turn are containers for characteristics.

Let me know if you need more info or would like to see a new feature added.

Best, Ivan

PS there is a discord channel for the project: https://discordapp.com/channels/415785197171113986/415785197687275531

ikalchev avatar May 31 '18 06:05 ikalchev

Is the project still ongoing? I can't access the discord channel.

DQgmorona avatar Jul 29 '18 22:07 DQgmorona

I just clicked the link above - it works. Can you try again?

ikalchev avatar Jul 30 '18 16:07 ikalchev