TRIGGERcmd
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    HomeGenie X10 control with single bash script

    Raspberry Pi
    raspberry pi google assistan alexa homegenie x10
    4
    15
    1.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • tuicemenT
      tuicemen
      last edited by tuicemen

      Actually I believe this (HG.sh)will work for all HomeGenie configured switches, lights or plugs no mater the protocol.
      I've tested with Zwave and X10 so far .

      #!/bin/bash
      echo "Sending HomeGenie the $1 command $2 to turn $3"
      curl http://192.168.0.24:8084/api/HomeAutomation.$1/$2/Control.$3
      

      Naturally you'd change the IP & port # to that of your HG server.
      To test:

      • 1: Make the HG.sh file executable (chmod +x HG.sh)
      • 2: From command line for X10 type: sh HG.sh X10 A3 On
        This turns on X10 module A3
      • 3: From command line for ZWave type: sh HG.sh ZWave 1 On
        This turns on ZWave node 1

      Update: I added a Dim preset to the script so a new script isn't required for that.

      #!/bin/bash
      foo=$(echo "${3}" | awk '{$1=toupper(substr($1,0,1))substr($1,2)}1')
      if [ $foo = "Dim" ]
      then(
      #following turns device to 20% brigtness if you wish it to be different change the value between 1-100 where 100 is full brightness
      curl http://192.168.0.24:8084/api/HomeAutomation.$1/$2/Control.Level/20
      echo "Sending HomeGenie the $1 command $2 to Dim"
      )
      else(
      curl http://192.168.0.24:8084/api/HomeAutomation.$1/$2/Control.$foo
      echo "Sending HomeGenie the $1 command $2 to turn $foo"
      )
      fi
      echo Sent HomeGenie the $1 command $foo to $2 >> /home/pi/scripts/HGsents.txt
      
      

      To use this with Alexa and or Google you need to edit the commands.json file
      For X10 on/off add lines like:

      #{"trigger":"a8","command":"/home/pi/scripts/HG.sh x10 A8","ground":"background","voice":"?","allowParams":"true"},
      

      change a8 and A8 to match the x10 address you require and change the ? to a friendly name for Alexa &or Google
      For X10 dim add lines like:

      #{"trigger":"a8","command":"/home/pi/scripts/HG.sh x10 A8 Dim","ground":"background","voice":"?","allowParams":"false"},
      

      change a8 and A8 to match the x10 address you require and change the ? to a friendly name for Alexa &or Google
      For ZWave on/off add lines like:

      #{"trigger":"ZWave","command":"/home/pi/scripts/HG.sh Zwave 
      8 ","ground":"background","voice":"?","allowParams":"true"},
      

      change the 8 to the node# you wish to control
      For ZWave Dim add lines like:

      #{"trigger":"ZWave","command":"/home/pi/scripts/HG.sh Zwave 
      8 Dim","ground":"background","voice":"?","allowParams":"false"},
      

      change the 8 to the node# you wish to control

      RussR A 2 Replies Last reply Reply Quote 0
      • RussR
        Russ @tuicemen
        last edited by

        @tuicemen, that's pretty cool. I might try this. I didn't realize HomeGenie is opensource.

        https://homegenie.it

        Russell VanderMey

        tuicemenT 1 Reply Last reply Reply Quote 0
        • tuicemenT
          tuicemen @Russ
          last edited by

          @russ the cool thing is, like TRIGGERcmd it can be used on a variety of OSs, Mac, Windows, Linux, Raspi

          1 Reply Last reply Reply Quote 1
          • A
            alwaysbroke @tuicemen
            last edited by

            @tuicemen I was wondering if people were still using X10 besides me. I ended up using an old broadlink RM Pro to control mine. I just use the newest Broadlink app, (Not IHC, and no IFTTT) and it controls all my x10 devices and also has ir, so it can also control my dumb TV, surround, fireplace, etc. There is no subscription fees with this either.

            tuicemenT 1 Reply Last reply Reply Quote 0
            • tuicemenT
              tuicemen @alwaysbroke
              last edited by tuicemen

              @alwaysbroke, there are a number of users still on the X10 band wagon as can be seen on the X10 forums ( https://forums.x10.com ).
              I have used the Broadlink RM, Samsung SmartThings developer console, and Ha-Bridge and a few other methods to get Alexa control in the past.
              The easiest by far to setup was HA-Bridge however currently there is a issue with adding new devices which started to affect me as well as several others. This lead me to TRIGGERcmd.
              I'm not a big fan of subscription fees either but if reasonable and it does what I require it is worth it.
              HomeGenie is free and I created several addon plugins for it so interfacing to it is best for me. HA-Bridge did this seamless when it was working. I'm sure Triggercmd will do this as well once I have all the bugs worked out. The limitation of one call per min for the non subscription is slowing testing things up here for sure. One call every 30 seconds would sure speed up my testing but once everything is setup 1 call per min I think I can live with for most things Alexa and every thing Google Home is used for here.

              tuicemenT 1 Reply Last reply Reply Quote 0
              • tuicemenT
                tuicemen @tuicemen
                last edited by tuicemen

                @Russ , seems Alexa and Google send lower case on/off commands and HomeGenie requires the commands to start with upper case. I'm not sure why with using just 1 parameter this seems to work but with 3 parameters it doesn't

                In any case I've got a work around for this in the Bash script which I edited to look like this now

                #!/bin/bash
                foo=$(echo "${3}" | awk '{$1=toupper(substr($1,0,1))substr($1,2)}1')
                echo Sent HomeGenie the $1 command $2 to turn $foo >> /home/pi/scripts/HGsents.txt
                echo "Sending HomeGenie the $1 command $2 to turn $foo"
                
                curl http://192.168.0.24:8084/api/HomeAutomation.$1/$2/Control.$foo
                

                next I'll start to play with adding dim commands but not sure if TRIGGERcmd will process them from Alexa/Google

                tuicemenT 1 Reply Last reply Reply Quote 1
                • tuicemenT
                  tuicemen @tuicemen
                  last edited by

                  I rarely if ever use dim commands and when I do it is for a single lamp and to set it to a specific level.
                  Since TRIGGERcmd currently doesn't accept dim commands from Alexa or Google the dim operation is a set value (that works for me) if you wish a different value the script would require editing.
                  If in the future @Russ adds dimming I'll rework this bash script.
                  I'll edit my OP showing the revised script.

                  W 1 Reply Last reply Reply Quote 0
                  • W
                    Wholepunch @tuicemen
                    last edited by

                    @tuicemen Thanks for this - looks like an elegant solution. I've been putting together a Home Assistant (Hassio) build having tried OpenHab and several others but hadn't come across Home Genie for some reason so you've prompted me to do some research - I find Hassio a bit restrictive / cumbersome for some of the things I want to implement, although the work put into making it a polished user experience is very evident.

                    tuicemenT 1 Reply Last reply Reply Quote 0
                    • tuicemenT
                      tuicemen @Wholepunch
                      last edited by

                      @wholepunch, one thing I like about HomeGenie is it has it's own drivers for X10 unlike the other Multi OS HA software solutions.
                      The Developer isn't as quick at resolving issues and the user base isn't as big as it use to be(perhaps due to that fact).
                      The user base that have stuck with it are very knowledgeable so most issues that are discovered are usually fixed with a workaround. Having different built in coding languages means most anyone can develop plugins for it.

                      W tuicemenT 2 Replies Last reply Reply Quote 0
                      • W
                        Wholepunch @tuicemen
                        last edited by

                        @tuicemen That's useful to know - thank you! I must admit that I thought that pure X10 devices had been steam-rollered by ZWave, ZigBee at al - but that just shows you what a home automation noob I am. I fully agree with your comments re: some other HA systems - Hassio in particular seems to want to move to a binary " that's supported/not supported" model, which I understand for the purposes of user friendliness and stability, but it's frustrating for the tinkerer!

                        1 Reply Last reply Reply Quote 0
                        • tuicemenT
                          tuicemen @tuicemen
                          last edited by

                          @wholepunch, since @Russ posted https://www.triggercmd.com/forum/post/5208 I got thinking about HG responding back to the API request. It may be possible to add a custom response to device calls indicating that HG did actually receive and perform the task.
                          Creating a variable Received for the Curl call
                          then using a

                          "if [ $Recieved='{"ResponceValue":OK}' ]
                          then
                          ........
                          

                          one could have TRIGGERcmd report that HG did indeed send the command or not via Alexa or Google.

                          I don't wish to play with Voice Monkey unless I have to.

                          tuicemenT 1 Reply Last reply Reply Quote 0
                          • tuicemenT tuicemen referenced this topic on
                          • tuicemenT
                            tuicemen @tuicemen
                            last edited by

                            I reworked the hg script to handle how I suspect alexa or Google will send the dim command to TRIGGERcmd when(if) @Russ is able to add that feature it presumes the HG server is running on the same PI as TRIGGER and is on port 8080

                            #!/bin/bash
                            foo=$(echo "${3}" | awk '{$1=toupper(substr($1,0,1))substr($1,2)}1')
                            if [ -n "$foo" ] && [ "$foo" -eq "$foo" ] 2>/dev/null;
                            then(
                            #following turns device to the brigtness level
                            curl -s http://localhost:8080/api/HomeAutomation.$1/$2/Control.Level/$foo
                            echo "Sent HomeGenie the $1 command $2 to $foo % brightness"
                            )
                            else(
                             curl -s http://localhost:8080/api/HomeAutomation.$1/$2/Control.$foo
                            echo "Sent HomeGenie the $1 command $2 to turn $foo"
                            )
                            fi
                            #if next line uncomented it will log commands sent to a already created file HGsents.txt
                            #echo Sent HomeGenie the $1 command $3 to $2 >> /home/pi/scripts/HGsents.txt
                            

                            You can test the script from the command line for on/off and dim
                            Using sh hg.sh X10 A3 50 this would set the X10 module A3 to 50%
                            for those that don't wish to create this file you can download it here: script

                            1 Reply Last reply Reply Quote 0
                            • tuicemenT
                              tuicemen
                              last edited by tuicemen

                              I'm happy to report the above posted script works for Dimming via Alexa since @Russ added support in the Alexa skill.
                              You do need to have Alexa rediscover those dimmable lights

                              RussR 1 Reply Last reply Reply Quote 0
                              • RussR
                                Russ @tuicemen
                                last edited by Russ

                                @tuicemen said in HomeGenie X10 control with single bash script:

                                "deviceType":"light"

                                This is actually wrong ^. "deviceType":"light" is not a thing.

                                If adding that made it work, it's because when you change a command, TRIGGERcmd deletes and re-creates the Alexa smart home device. That needed to happen for the Alexa device associated with your command would have the new brightness feature.

                                Sorry I didn't tell you that in my reply to your post where I told you it should work now.

                                Russell VanderMey

                                tuicemenT 1 Reply Last reply Reply Quote 0
                                • tuicemenT
                                  tuicemen @Russ
                                  last edited by tuicemen

                                  @russ thanks, I removed the deviceType from my json file and had Alexa rediscover and they do still dim. I edited my previous post.
                                  It should be noted that using dim turns the device to that value. So if you turn a light on (100%) then say dim 20% it doesn't set the light level to 80 but instead sets the light level to 20.
                                  At least that's the way it works for HG.

                                  1 Reply Last reply Reply Quote 1
                                  • First post
                                    Last post