Command format on Raspi
-
Oh ya, forgot. Does the RasberryPI image you created include the GUI? Think not, but just clarifying.
Steve
-
@steve-porter, this process installs the Raspberry Pi OS without a GUI and with the TRIGGERcmd agent pre-installed.
If you want to use the GUI, you'll want to install the OS first, then use this process to install the agent.
You won't be able to run "C:\Program Files (x86)\Common Files\X10\Common\ahcmd.exe" (or any .exe) on a Raspberry Pi though. EXE files are meant to run on Windows.
If you run /usr/share/triggercmdagent/app/src/installdaemon.sh it will install the agent to run as root in background mode as the root user and start when your Pi boots.
Also, if you want to run the agent in the GUI, open a shell window, then run triggercmdagent. If you want the agent to use the same computer in your account, and the same commands.json file as your background agent, you'll want to switch to the root account with a command like this:
sudo su -
It will not put an icon on your tool bar.
What's mocad?
-
Hi Russ, mocad is what sends x10 commands to a CM15A on Raspi, on Windows it's not used. My batch files in Windows look like this:
"C:\Program Files (x86)\Common Files\X10\Common\ahcmd.exe" sendplc I4 onI want to move all my commands from my Windows Desktop to my RasberryPI 4, preferable with the gui. Mocad use in a shell command window looks like:
echo "pl i6 on" | nc localhost 1099How do I get that to run from TriggerCMD on Raspi as a trigger? I can edit the trigger files, I'm just not sure how to format it.
-
@russ steve-porter Am I completely off track on getting X10 working with TriggerCMD on RasberryPI?
-
@steve-porter, I think you're close. I assume this command already works if you run it manually?
echo "pl i6 on" | nc localhost 1099
I recommend you install the triggercmd agent on the Pi the normal way - using this script:
/usr/share/triggercmdagent/app/src/installdaemon.sh
It will run as root in background mode and startup on boot.There is no GUI editor or icon for the Raspberry Pi version of the agent. You'll need to edit the /root/.TRIGGERcmdData/commands.json file manually.
If you want, you could create the command on your Windows box, then copy/paste the resulting json from your commands.json on your Windows box to the Pi.
I think this should work though:
{"trigger":"Six","command":"echo \"pl i6 on\" | nc localhost 1099","ground":"background","voice":"six","allowParams": "false"},
Notice I "escaped" the quotes around the pl i6 on part so it didn't break the json formatting.
Please test that. If it works, I can give you a script to run instead that will take an on or off parameter so you can use one command with allowParams = true. That way you can say, "Alexa, turn on 6" or "Alexa, turn off 6".
-
@russ That works, I see the trigger run. I still need to figure out what's going on inside mocad. The Tx function runs, but isn't sending the x10 signal.
How would it look using parameters? (Obviously parameters true)
-
@steve-porter, if you run this command manually does it work?
echo "pl i6 on" | nc localhost 1099
You could put that in an i6.sh script that accepts an on or off parameter like this:
echo "pl i6 $1" | nc localhost 1099
Make sure you make your script executable with a command like this:
chmod +x /usr/local/bin/i6.sh
-
@russ Hi Russ, just spent a week debugging mochad on Linux/Raspi. It now works sending to X10 perfectly, using the above command line example:
"echo "pl i6 on" | nc -w 1 localhost 1099I've never worked with scripts in linux, but I have edited the commands.json file and have a couple of commands working and showing up in the web interface, and they work.
Right now one to turn on a fan, a separate one to turn that fan off. So I added a new one, changing "allowParams": "false" to "true". So now the Parameters button is there. How do I format the command in commands.json to pass the "on"/"off" param to this:
{"trigger":"Living Room Fan On","command":"echo "pl i6 on" | nc -w 1 localhost 1099","ground":"background","voice":"Living Room Fan On","allowParams": "true"} ?I tried putting [param] in a few ways but haven't found the correct format.
Steve
-
@steve-porter , I'm new to TRIGGERcmd but not X10 or scripts
I played with mochad on a Raspberry pi a bit but it never seemed stable for me.
I use HomeGenie (HG) now with X10 but I believe you could do something similar to what I did with x10 and HG with a mochad script.
You could create 1 script that would handle all your X10 devices On & Off I can't remember if mochad did diming but if so the script could allow that as well. -
@steve-porter just quickly put together a multi use script for mochad called X10.sh
#!bin/bash echo "pl $1 $2" | nc localhost 1099 echo "sent powerline command $1 $2 to Mochad"
If your stumped on how to create this I can upload the file.
your line in the commands.json file would look like this for house code i unit code 6:{"trigger":"i6","command":"/home/pi/scripts/X10.sh i6","ground":"background","voice":"six","allowParams":"true"},
Note: this would require your X10.sh script to be in the home/pi/scripts folder to turn on or off a different module you simply add another line to the commands.json file changing the i6 to the address you wished and the voice to something else.
-
@steve-porter said in Command format on Raspi:
I've never worked with scripts in linux, but I have edited the commands.json file.......
Creating a script is very easy I'll walk you through this simple one.
open the text editor nano at the prompt type- sudo nano X10.sh
- in the window that opens paste the script contents from my previous post or type in the lines.
- hit the ctrl x keys to exit
- you'll get a prompt to save press y for yes
- next you'll get the confirmation of the file name press enter if it is OK
- now you need to make the file executable type chmod +x X10.sh
- to test type sh X10.sh i6 on
- sh X10.sh i6 off should turn off the module
-
@tuicemen Thank you for your replies, I appreciated it very much. Creating the shell script would shorten the amount of text in the commands.json triggers. It apprears that I would still need a trigger for each x10 unit on, x10 unit off.
I would really like to be able to send the variables [i6 on], or [i6 off] to the same trigger. In the TriggerCMD web interface you can trigger with parameters, but I just don't see how to get those parameters into the trigger command string.
Something like this:
{"trigger":"Living Room Fan On","command":"echo "pl $1 $2" | nc -w 1 localhost 1099","ground":"background","voice":"Living Room Fan Off","allowParams": "true"}and be able to pass the i6, on. (just my attempt at a guess, this doesn't work)
-
This post is deleted! -
@steve-porter, that should work fine.
All parameters get appended to the end of the command you put in the command field.
If you need to embedded parameters in the middle of your command, you'll need to use a script, and refer to the positional parameters as $1 and $2 inside the script.
Also if you need to put quotes in your command (in commands.json), you'll need to escape them with a backslash like this:
\"
That way the json parser won't think the quotes are part of the json field start/end. The GUI editor handles that for you, so if you're building a command for a Raspberry Pi you could copy paste the json from a Windows computer.
-
@steve-porter said in Command format on Raspi:
I would really like to be able to send the variables [i6 on], or [i6 off] to the same trigger. In the TriggerCMD web interface you can trigger with parameters, but I just don't see how to get those parameters into the trigger command string.
you would only need one line in your commands.json file per X10 address
your line would be this{"trigger":"Living Room Fan","command":"/home/pi/scripts/X10.sh i6","ground":"background","voice":"Living Room Fan","allowParams": "true"
To turn the living room fan on you'd say "Alexa turn On Living Room Fan" or "Alexa Living Room Fan On"
To turn the living room fan off you'd say "Alexa turn Off Living Room Fan" or "Alexa Living Room Fan Off"
Alexa adds the condition on or off to the end of your request thats why a script is needed in your case so that the on/off condition gets place in the correct location.
-
This post is deleted! -
@russ Ya seen that And fixed it
-
@steve-porter here is the script : X10.sh
you can test in in the command line by typing sh X10.sh i6 on
to turn your fan off simply change the on to off -
@steve-porter, I brushed up on Mochad, reading from early posts made by the original developer here https://forums.x10.com/index.php?topic=22045.0
It seems it is possible to send RF as well as PLC and even dim.
though it seems the dimming function was a bit clunky and depended on the age of the Lamp modules.
The current script (I provided) will do on/off for all 256 X10 addresses for PLC only if you wish RF, the script could be modified to handle it easy enough. Your commands.json lines would needed to be edited with an additional parameter.
Dimming functions (not currently available with TRIGGER) would be a little more complicated and depending on how Alexa sends the dim may need some conversion. -
You guys ROCK! Thanks for your guidance for an old 80's c programmer (I'm 63 and still learning *-).....)
K, so I got all my desktop commands into the Raspi .json file. Had to delete my desktop and Raspi from Trig website, then reinstall the Raspi. K, so now commands half way work. Funny thing, Alexa can turn things on , but not off. Hmmmm.....Really just for the paper trail.....just was wondering why, Hmmmmm?
K, so I'll work on the script route, sounds like the best way to go....