❤️💻 Macbook Pro's Touch Bar is finally useful: displaying sensors and controlling devices

I can control Home Assistant from my Touch Bar on the Macbook Pro now!

I’ve written down how I do this and shared all the code here on GitHub. :star:

It can make switchable buttons for

  • input_booleans
  • lights

and display the state of

  • sensors
  • binary_sensors
  • probably anything with a state

and create a slider for

  • light
  • probably works for changing the volume of media_players too with minimal modifications

The rest of my config files are here.

13 Likes

This is bloody amazing mate well done :slight_smile:

1 Like

Hello guys!

I’m blocked here:

I really don’t understand what I have to do now :smiley:

This is how it looks for me:

get your full Python path by writing which python in your Terminal.

Thanks. So i need to install python first?

Python is installed by default on Mac OS.

1 Like

mhmm… now i got the python path, and something happened. But I got this…

If I run the script I receive this message:

Traceback (most recent call last):

  • File “/Users/ndr/Downloads/ha-touch/widgets/switch.py”, line 9, in *
  • from utils import entity, icon_folder, service*
  • File “/Users/ndr/Downloads/ha-touch/widgets/utils.py”, line 4, in *
  • import requests*
    ModuleNotFoundError: No module named ‘requests’
Pictures

First try

pip3 install requests

If that doesn’t work, do

sudo pip3 install requests

I forgot to add that to the instructions…

I still have the same issue =(

Brilliant! Definitely going to try this.

It would be easier to help if you post the error message.

Sure, I will send some screenshots this afternoon =)

Meanwhile I would to thank you for all of your quick replies!

Sorry fior the delay, here the error I have:

Traceback (most recent call last):
  File "/Users/ndr/Downloads/ha-touch/widgets/switch.py", line 9, in <module>
    from utils import entity, icon_folder, service

I see two issues!

  1. In your “Script:” section your Mac converted two dashes -- to an em (long) dash automatically (... —toggle -> --toggle). It should be two dashes!
  2. You need to put the utils.py script in your ~/Downloads/ha-touch/widgets/ folder. It seems like it’s not there, judging from the (incomplete!) error message.

I’m really sorry @basnijholt, I don’t want to stress you. But still nothing.
What I’ve done:

1- corrected the “- -toggle” as you suggested (without the spacing between the two -)
2- Replaced the whole folder (excluding “secret.py”) due to the fact I already had all the corrected files.
To be sure, i downloaded again all the github zip and put all the files there.

The error is still the same:

Traceback (most recent call last):
  File "/Users/ndr/Downloads/ha-touch/widgets/switch.py", line 9, in <module>
    from utils import entity, icon_folder, service
  File "/Users/ndr/Downloads/ha-touch/widgets/utils.py", line 4, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

Ah right, I couldn’t see the entire error message before, so my guess was wrong.
In your terminal do

sudo /usr/bin/pip3 install requests

and fill in your password and click enter. That should fix that error.

1 Like

Mate… thanks so much for your patience! It works!

Happy that you can finally use it! No problem at all.

If you have any ideas or improvements in mind, just say it and maybe I’ll make it or fix it.

I have just an idea at the moment. Cause I still didn’t set up all of my stuff:

If I put, for example, two lights in the touch bar, it will show the state of both lights (of course).

But the result is a bit confusing, cause I will have two identical buttons showing on/off. Is there a way to show also the name of the light/button instead of only the state of that switch/light?

Instead of showing the state, you can display a text by using the --text "bedroom" or --text "any text here" argument to the script.

So for you to would be something like

/usr/bin/python3 ~/Downloads/ha-touch/widgets/switch.py --entity_id light.luce_studio --icon fa-lightbulb-o.png --toggle --text "luce studio"

Another option is to change the icon and replace it with something custom.

1 Like