Thursday, September 24th, 2020 08:47 am
coding and education in home automation aka learning home assistant
I am taking a month off social media--by that I mean tumblr and twitter--to see if that helps calm me down. I'm officially bored with anxiety; I didn't know it was possible to experience both together, but here we are.
In the last few weeks;
1.) learned new exercises for PT.
2.) installed Home Assistant on my Pi, which is something like SmartThings hub but like, so fucking much cooler and better and more awesome.
After problems with SmartThings meant I de-integrated everything that wasn't z-wave or zigbee. SmartThings went to a new standard and also new app and lost functionality, so it was no longer fun; all my scripts were being killed and all the ones from the community were dying. However, it's still an exemplary z-wave and zigbee hub, so it could be used for that (a z-wave stick is about the same price as a SmartThings hub and that's without zigbee), so I finally sat down with my Pi and installed Home Assistant.
It's about a thousand times better than SmartThings. For one, it's web based, not app based, so the web components are both not an afterthought and also exist; for another it uses Javascript but mostly Python and YAML, and I've really been wanting to learn those two.
I will do an entry on this eventually because holy shit, this is fun.
Related....
3.) Did my first fork and pull on github to bug fix a python script. Yes, I'm finally using github as intended.
4.) Am finally learning python (and yaml). I learn by doing, which generally means I need a project to work on, specifically one that does something I really want to do and can't make work in any language I already know. Making my Sengled Color Bulbs work, as it turns out, was the trick.
When doing the integration for my Sengled bulbs into Home Assistant, the Sengled script had some problems and since python is Javacript With Indents, I went to read the script then read the developer's notes. He didn't have some of the bulbs I did, so I sent him my logs and then made some corrections to the scripts since it would be harder for him to do that part without the right bulbs to test (Sengled doesn't have a public API so he was doing it all with the app, a Sengled Hub, and watching traffic and jsons). Anyway, he invited me to submit a pull instead of sending him script bits, so I learned github while python to do the corrections. It was fun.
I really thought Python would be much harder, but honestly, it only took me a couple of scripts to get read and write and correcting was fairly simple after that; in some ways, it's a little more refined than Javascript, like someone sat down to correct JS's more wild-west approach and fix some of the more obvious workarounds. I mean, the reason I love JS is that 1.) you can use it pretty much anywhere, and 2.) you really can do anything with it, literally. If it can be done in a language, you can do it in Javascript; all the pieces are there, you just have to build them yourself.
Which is great; I have entire sheets of custom classes and constructors and prototypes when I learned about hashes and JS's tragic lack (and multi-dimensional hashes, for that matter, still the most interesting and least practically useful piece of scripting I ever did; what I needed it for its perfect but that's literally the only use. Still, it's so pretty you have no idea) and expanding Strings so I could do one-stop clean up and formatting of titles, the list goes on. Even better, Javascript translates to anything; if I write it in JS, I can translate it to VBA and Bash and even Groovy given a little time. And the reverse is also true: except for very specific things in VBA that are internal to Word and Excel, it's almost a one to one, and the specific things generally can be worked around.
(Javascript is honestly my One True Language. I don't have anything against languages requiring compiling, but anything big enough to need compiling is a project both way outside my general scope of interest and honestly, you'd have to pay me a lot to deal with Java's incredible bullshit. I like reading it and it's cool, don't get me wrong, but it's just not elegant and gets byzantine very fast. I thought for a while it was OOP thinking that was my problem, but once I wrote my own classes I accepted that I was just bored; the amount of time to write, debug, compile and test for one program to do one thing is the same as writing five scripts that do the same thing and the scripts I can use anywhere.
I admit, doing some vague work in C# has made me rethink my feelings on compiling--C# is surprisingly elegant and clean and doesn't require you to rediscover and redesign the wheel eight times in five functions and three includes--but I haven't run into anything I want to do that needed it. Projects that require it are generally ones you do for money to create things to sell and with more than one collaborator; other than making my own addons for Word and Excel, I've never yet run into a project smaller that I'd use it for, and for the addons, I had several much better options to use that didn't require a pauses for debug/compile.)
Python though: I can't entirely deny there is something rather nice about working in a language that I don't need to start off with a page of my custom constructors, classes, and prototypes, not to mention the ones I got from other people.
However: Python is tab based, with neither brackets (Javascript) nor closure statements (Bash, VBA) to visually demarcate the end of a function/if/else/for/loop and that's stressing me.
For example:
Javascript
VBA
Bash:
Python:
Note: yes that indent is literally all I get.
This isn't a problem in scripting--I keep strict indentation no matter what I'm writing because it's visually easier to read/write--but it gets weird fast when reading/editing because there's no visual end for an if/for/loop other than that indentation and if you're nesting loops and ifs, that gets old very fast. The only clue you have to the end is the lack of indentation, and if you have an if inside a for inside a for--I mean, if the IDE has a graph background I'm less annoyed but if a function or a loop goes more than a page or the IDE isn't graphed--yeah.
Python:
There's colons? I guess that's--something. But seriously, why? Why for the love of God remove literally every visual marker possible? Yeah, it looks clean, but like, too clean, like living in a clean room; a few germs never hurt anyone. On a guess, I'm going to be documenting like I'm writing a biography of the script's life and times to get some visual markers until I get used to it or work out a way to see (and count) empty space on a glance.
Adventure indeed.
In the last few weeks;
1.) learned new exercises for PT.
2.) installed Home Assistant on my Pi, which is something like SmartThings hub but like, so fucking much cooler and better and more awesome.
After problems with SmartThings meant I de-integrated everything that wasn't z-wave or zigbee. SmartThings went to a new standard and also new app and lost functionality, so it was no longer fun; all my scripts were being killed and all the ones from the community were dying. However, it's still an exemplary z-wave and zigbee hub, so it could be used for that (a z-wave stick is about the same price as a SmartThings hub and that's without zigbee), so I finally sat down with my Pi and installed Home Assistant.
It's about a thousand times better than SmartThings. For one, it's web based, not app based, so the web components are both not an afterthought and also exist; for another it uses Javascript but mostly Python and YAML, and I've really been wanting to learn those two.
I will do an entry on this eventually because holy shit, this is fun.
Related....
3.) Did my first fork and pull on github to bug fix a python script. Yes, I'm finally using github as intended.
4.) Am finally learning python (and yaml). I learn by doing, which generally means I need a project to work on, specifically one that does something I really want to do and can't make work in any language I already know. Making my Sengled Color Bulbs work, as it turns out, was the trick.
When doing the integration for my Sengled bulbs into Home Assistant, the Sengled script had some problems and since python is Javacript With Indents, I went to read the script then read the developer's notes. He didn't have some of the bulbs I did, so I sent him my logs and then made some corrections to the scripts since it would be harder for him to do that part without the right bulbs to test (Sengled doesn't have a public API so he was doing it all with the app, a Sengled Hub, and watching traffic and jsons). Anyway, he invited me to submit a pull instead of sending him script bits, so I learned github while python to do the corrections. It was fun.
I really thought Python would be much harder, but honestly, it only took me a couple of scripts to get read and write and correcting was fairly simple after that; in some ways, it's a little more refined than Javascript, like someone sat down to correct JS's more wild-west approach and fix some of the more obvious workarounds. I mean, the reason I love JS is that 1.) you can use it pretty much anywhere, and 2.) you really can do anything with it, literally. If it can be done in a language, you can do it in Javascript; all the pieces are there, you just have to build them yourself.
Which is great; I have entire sheets of custom classes and constructors and prototypes when I learned about hashes and JS's tragic lack (and multi-dimensional hashes, for that matter, still the most interesting and least practically useful piece of scripting I ever did; what I needed it for its perfect but that's literally the only use. Still, it's so pretty you have no idea) and expanding Strings so I could do one-stop clean up and formatting of titles, the list goes on. Even better, Javascript translates to anything; if I write it in JS, I can translate it to VBA and Bash and even Groovy given a little time. And the reverse is also true: except for very specific things in VBA that are internal to Word and Excel, it's almost a one to one, and the specific things generally can be worked around.
(Javascript is honestly my One True Language. I don't have anything against languages requiring compiling, but anything big enough to need compiling is a project both way outside my general scope of interest and honestly, you'd have to pay me a lot to deal with Java's incredible bullshit. I like reading it and it's cool, don't get me wrong, but it's just not elegant and gets byzantine very fast. I thought for a while it was OOP thinking that was my problem, but once I wrote my own classes I accepted that I was just bored; the amount of time to write, debug, compile and test for one program to do one thing is the same as writing five scripts that do the same thing and the scripts I can use anywhere.
I admit, doing some vague work in C# has made me rethink my feelings on compiling--C# is surprisingly elegant and clean and doesn't require you to rediscover and redesign the wheel eight times in five functions and three includes--but I haven't run into anything I want to do that needed it. Projects that require it are generally ones you do for money to create things to sell and with more than one collaborator; other than making my own addons for Word and Excel, I've never yet run into a project smaller that I'd use it for, and for the addons, I had several much better options to use that didn't require a pauses for debug/compile.)
Python though: I can't entirely deny there is something rather nice about working in a language that I don't need to start off with a page of my custom constructors, classes, and prototypes, not to mention the ones I got from other people.
However: Python is tab based, with neither brackets (Javascript) nor closure statements (Bash, VBA) to visually demarcate the end of a function/if/else/for/loop and that's stressing me.
For example:
Javascript
if (x){
stuff
}
VBA
If x Then
stuff
End If
Bash:
if (x); then
stuff
fi
Python:
if x:
stuff
Note: yes that indent is literally all I get.
This isn't a problem in scripting--I keep strict indentation no matter what I'm writing because it's visually easier to read/write--but it gets weird fast when reading/editing because there's no visual end for an if/for/loop other than that indentation and if you're nesting loops and ifs, that gets old very fast. The only clue you have to the end is the lack of indentation, and if you have an if inside a for inside a for--I mean, if the IDE has a graph background I'm less annoyed but if a function or a loop goes more than a page or the IDE isn't graphed--yeah.
Python:
functionname:
for x:
stuff
for y:
more stuff
if z:
stuff if
else:
stuff else
if a:
yeah stuff
for b:
even more stuff
if c:
so much stuff
return
There's colons? I guess that's--something. But seriously, why? Why for the love of God remove literally every visual marker possible? Yeah, it looks clean, but like, too clean, like living in a clean room; a few germs never hurt anyone. On a guess, I'm going to be documenting like I'm writing a biography of the script's life and times to get some visual markers until I get used to it or work out a way to see (and count) empty space on a glance.
Adventure indeed.