[HN Gopher] My Lights Run on Bash
       ___________________________________________________________________
        
       My Lights Run on Bash
        
       Author : todsacerdoti
       Score  : 52 points
       Date   : 2025-06-27 11:09 UTC (11 hours ago)
        
 (HTM) web link (kramkow.ski)
 (TXT) w3m dump (kramkow.ski)
        
       | Rediscover wrote:
       | It's time for me to re-read the man page for bash. I was not
       | aware of BASH_REMATCH, wow. It's in the first snippet on the
       | linked page, and would save the hassle of using multiple var
       | expansions of the %% and ## et al sort.
        
         | tecleandor wrote:
         | Oh yeah! I was unaware too! Nowadays I quickly jump to python
         | instead of using Bash even for the simplest of scripts , but
         | this could help creating tiny and easy to understand scripts
         | for some integrations...
        
           | enriquto wrote:
           | > I quickly jump to python instead of using Bash even for the
           | simplest of scripts
           | 
           | You don't seem to respect the old, venerable, well-tested
           | adage: "once your shell script becomes too complex, switch to
           | a real programming language like python".
           | 
           | Or, the zen version (formally equivalent, but with quite a
           | different tone): "once your program becomes sufficiently
           | simple, turn it into a beautiful shell script".
        
             | skydhash wrote:
             | The true power of shell script is to coordinate programs.
             | Once you find yourself altering data with the shell
             | constructs, that's the sign to use $LISP instead.
        
         | alganet wrote:
         | Yes, but also:
         | 
         | https://wiki.ubuntu.com/DashAsBinSh#Why_was_this_change_made...
         | 
         | > [bash] is rather large and slow to start up and operate by
         | comparison with dash
         | 
         | For more complex regular expressions, you can use `sed`.
         | 
         | --
         | 
         | It's all a matter of context. Sometimes simple ## and %% param
         | substitutions are the best tool for the job.
         | 
         | I think bash is a fantastic interactive shell and a lousy
         | script runner.
        
           | Calzifer wrote:
           | Bash is slower than other POSIX compatible shells but once
           | you start running external commands for any substring or
           | replace operation you loose much of this performance edge
           | since forking is comparable slow.
           | 
           | One reason why I personally prefer to use Bashisms like
           | ${x//str/replace} or [[ $value =~ $pattern ]] instead of
           | doing the common x=$(echo $x | sed s/str/replace/) which has
           | to launch two processes just for the sake of avoiding
           | Bashism. (or grep -oP ... which is nice but a BASH_REMATCH is
           | often simpler)
        
             | Ferret7446 wrote:
             | The _reason_ Bash has so many features is that doing these
             | things natively in the shell is faster and more convenient.
             | After all, these features weren 't just added randomly.
        
       | sunshine-o wrote:
       | MQTT is a fantastic protocol.
       | 
       | I basically do the same as the author but use nutshell and its
       | powerful pattern matching [0] as the router
       | 
       | -[0]
       | https://www.nushell.sh/cookbook/pattern_matching.html#patter...
        
       | sunshine-o wrote:
       | For those using termux, termux widgets are exposed to Android
       | device control so you don't need the MqttDroid app
        
         | Arch-TK wrote:
         | Interesting... I didn't know about this, although I was pretty
         | satisfied with the simplicity of MqttDroid (after I fixed a
         | bug: https://github.com/LightJockey/MqttDroid/pull/3). Will
         | investigate to compare.
        
       | Spivak wrote:
       | The hate for the HomeAssistant OS is misplaced. It's just an
       | appliance that manages its own software packages. Like for
       | example the author could have set up Zigbee2MQTT entirely through
       | the web GUI.
        
         | jrm4 wrote:
         | It's really not though; I went with it for a while then it did
         | this weird diverging thing with updates and full versions that
         | I still don't fully understand because I just got fed up with
         | it.
        
           | nomel wrote:
           | It really is the design and intent, though. What year was
           | this? Things are much more stable than in the early days.
        
         | skgough wrote:
         | HomeAssistant's dependency requirements are so complex as to
         | make a deployment of it essentially read-only. Trying to mod it
         | with HACS is so hard that I gave up even though I write python
         | for a living. I can't recommend it to anyone that doesn't know
         | how to use linux at an expert level. This detracts from it's
         | mission IMO; I would like to tell my family to use it instead
         | of Google Home or Amazon whatever but it is so fragile that I
         | can't do that in good conscience.
        
           | Spivak wrote:
           | My install has been essentially maintenance free for years. I
           | don't imagine many casual users that just want an app/gui for
           | their smart outlets will be reaching for HACS. HA even warns
           | you when you install HACS that you're voiding all the
           | warranties.
        
         | Arch-TK wrote:
         | Author here.
         | 
         | Just to be clear, the one paragraph that indirectly references
         | HA was not intended as "hate". It was intended solely as gentle
         | mockery and a bit of humour. I think it should be very clear
         | from the article that my Mosquitto + Z2M + mqttr + bash + jq
         | solution, while feature-complete for my purposes, is not a
         | competitor to HA, which I have never used or tried.
         | 
         | Why have I never tried HA? To run it, I would need to either
         | create a VM or buy dedicated hardware. First, I don't want any
         | more dedicated hardware in my house. Second, I like to keep the
         | number of hosts I need to secure, manage, and keep running to a
         | minimum. Third, from what I've heard (from people insisting it
         | can't run on cheaper SBCs), it's not light; I was genuinely
         | concerned about the server load on my single, low-power home
         | server which already handles other things.
         | 
         | I imagine that for many people, Home Assistant works great: the
         | UI is what they like, it never breaks, and they never have to
         | troubleshoot it. Or, if it does break, they're satisfied with
         | just backing up their configuration and reinstalling it.
         | 
         | But for me, when it comes to things I set up in my own time for
         | my own use, I like to understand everything I am managing so I
         | can quickly understand any failures. If I am going to use a
         | ZBMINIR2 in detached mode to have my smart lights effectively
         | on 100% of the time with the only method of control being
         | Zigbee + glue, the glue had better be: a. rock-solid, b.
         | trivial to troubleshoot, and c. easy to fix. I am not confident
         | that I could learn, and retain, enough knowledge about HA to be
         | able to achieve those three goals.
         | 
         | Lastly, I have extensive experience of DIYing my own solutions
         | to problems for which working off-the-shelf solutions exist.
         | This is not because I am a contrarian who hates everything that
         | works, although maybe there's a tiny bit of that. The reason I
         | didn't use HA wasn't because I hate it; I didn't use it because
         | I wanted the pleasure of solving that problem myself.
        
       | ramon156 wrote:
       | I respect both the DIY's and the HA fans.
       | 
       | That aside, I'm currently contemplating whether running TrueNAS
       | Scale for web apps is really necessary. I like the fact that I
       | only need to click a few buttons or fill in a few fields, but on
       | the otherhand my setup can be kept inside a docker-compose.yml
       | 
       | We'll never know, since I like the safety of running my apps
       | through something like TrueNAS Scale. It feels professional
        
       ___________________________________________________________________
       (page generated 2025-06-27 23:01 UTC)