New to Busy?

Adding "witness rank" into iOS Home App

4 comments

emrebeyler
74
last monthSteemit3 min read

I've been investing in smart home appliances lately. So far, I've managed to cover %90 of the lightning with Hue light bulbs and Hue smart outlets.

Heating is connected to Tado. And of course, I've implemented motion sensors everywhere that automate lightning and notifications in some cases.

If you're into smart homes and if you don't do everything in the "Do it Yourself" way, then you need to choose a path. Since the IoT on homes is considerably new, there is no accepted standard.

Amazon, Google, Apple, Samsung, and other companies don't agree n a standard framework that you need to deal with integration problems if you don't buy your items carefully.

I've chosen the Homekit since I love using Apple products. (It's a love-hate relationship, though) If you choose the Homekit path, then your main "command center" app is the iOs Home app.


Lately, my witness rankings floating in and out around top20, so I've made a quick virtual sensor, and successfully put it to the home app.

Dashboard View (Favorites)Steem(Virtual Room detail)
h1h2

Prescription

  1. Install Homebridge and identify it as a new bridge on your Home app.

  2. Install Homebridge HTTP Temperature Sensor.

  3. Deploy this Python service into your Raspberry PI.

  4. from lightsteem.client import Client
    from flask import Flask, request
    
    app = Flask(__name__)
    
    def get_position(witness):
        """
        Returns the ranking of a specific witness
        If only the witness is inside top100.
        """
        c = Client()
        top_100 = c.get_witnesses_by_vote("", 100)
        for index, _witness in enumerate(top_100):
            if _witness["owner"] == witness:
                return index + 1
        return 0
    
    @app.route("/api/witness-position/")
    def witness_position():
        if not request.args.get("witness"):
            return "Use it like ?witness=<witness_name>"
        return str(get_position(request.args.get("witness")))
    
    if __name__ == "__main__":
        app.run()
    
  5. Add an accessory to the Homebridge sensor with your Python service URL.

  6. After restarting Homebridge, You'll see the sensor.


Of course, Homekit doesn't have an accessory type for that kind of thing, so we're mimicking a temperature sensor, expect to see things related to temperature. :)

Mimicking a smart outlet at Home app might be cooler since it actually can be a functional widget to disable witness on emergencies. (E.G: You're surfing some part of South Asia and you needed to disable your witness as an emergency, just ask Siri to do it.)

Vote for my witness

Witness rankings between 15-25 is more challenging now. As a new consensus witness, I need your vote to secure my position so that I don't check the ranking in every minute! :)

If you didn't vote already, consider casting a vote on Steemconnect or on Steemit

Python community

This is originally posted on Python community in Steemit Beta. Check it out and subscribe if you're interested in Python related content.

Comments

Sort byBest