seperis: (Default)
seperis ([personal profile] seperis) wrote2020-09-24 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

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.
akacat: A cute cat holding a computer mice by the cord. (Default)

[personal profile] akacat 2020-09-24 05:30 pm (UTC)(link)
I’m just going to pop in here with an example if your IF statement in MUMPS:

I X STUFF


Yup, that’s it. And yeah, a lot of MUMPS programmers stick to uppercase for everything.

And your function is:

 
F X D
.STUFF
.F Y D
..MORE STUFF
..I Z STUFF IF
..E  STUFF ELSE I A YEAH STUFF
.F B EVEN MORE STUFF
.I C SO MUCH STUFF
Edited (Typo!) 2020-09-24 17:32 (UTC)
jesse_the_k: room full of women keypunching (keypunchers)

[personal profile] jesse_the_k 2020-09-24 05:44 pm (UTC)(link)

...huh, maybe that explains why Epic Systems is so excellent at non-cooperation. They're all cranky from coding MUMPS.

jesse_the_k: Scrabble triple-value badge reading "triple nerd score" (word nerd)

[personal profile] jesse_the_k 2020-09-24 05:46 pm (UTC)(link)

The only code I know is what I've just looked up and pasted into my editor window (no memory here!) and yet I could follow your argument and sympathize with your brace-less Python wilderness.

So, good writing!

renenet: (Default)

[personal profile] renenet 2020-09-24 11:31 pm (UTC)(link)
Yes, this! I really enjoy reading your tech experiments posts, although I only ever understand 30% of the techie bits because that's my level of caring. but I get main ideas and have fun along the way, so yay!
renenet: (Default)

[personal profile] renenet 2020-09-25 11:54 pm (UTC)(link)
Cool, cool, cool! I totally appreciate your pubic service attitude there.
lillian13: (Justified quote English)

[personal profile] lillian13 2020-09-26 07:31 am (UTC)(link)
...and this, ladies and gentlemen, is why she will either be the first person eliminated during the AI Uprising...or the last.
olanthanide: (Default)

[personal profile] olanthanide 2020-09-27 08:22 pm (UTC)(link)
Yeah, I've always found that aspect of anxiety to be maddening -- that with any chronic conditions, if it goes on long enough, it just gets boring. Like, even the adrenaline dump of panic attack can no longer erase the "what? Again? SIGH" -- apparently even pain can get boring if it goes on long enough. I mean I can see the evolutionary advantages of it but also it kind of makes you want to set things on fire.

[personal profile] nymphaea1 2020-10-16 01:05 am (UTC)(link)
I'm also trying to take a break from media, though mostly twitter. It was dialing my anxiety up to 35. Oddly enough I'm going back to very old fanfic and old fan acquaintances like you. I'm finally writing that 10 year old prequel to Chimera.