Command format on Raspi
-
@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....
-
@steve-porter Just realized that "Alexa, Turn off living Room Fan" also turns the fan ON......another Hmmmmmm.....
-
@steve-porter you only have a year on me I'm still learning too.
I find I have to go through my TRIGGER calls and scripts a couple of times to catch my typos. I seem to have more of them lately
The Script route really is the best route.
I've read several posts on other Home Automation sites complaining about mochad not working correctly for them. It was one reason I chose not to use that Home Automation software.
Mochad was originally created for the North American market and it seems like that maybe why some users have problems though I think it is mainly the RF side of it.
Are you using mochad as a addon for another Home Automation software?
What X10 hardware are you interfaceing with? -
@tuicemen I'm mostly now using smart plugs and light bulbs via WiFi but still have a bunch of X10 stuff. My pool light and waterfall both have 220v X10 modules, and the smart plugs won't work with fan motors. And for my house ceiling fans I installed X10 "relay" switches cause they're way cheaper than the smart switches that would work.
I moved all the X10 stuff from my Windows Desktop to the Raspi. Mochad wouldn't compile without a bunch of errors, which is why I modified it. The version I started with was mochad-0.1.17. I've heard rumblings of a mochad-0.1.19 version floating around somewhere, so I'm bumping this one to mochad-0.1.21 just to be sure. Mochad recognized my X10 CM15a with no problem. That's the same hardware I was using with my Windows installation for years.
I'm going to be setting up the script stuff you and Russ pointed my towards today.
Cheers
(P.S: I'm in California, what region are you?)
-
@steve-porter I'm in Ontario Canada.
My setup is still mostly x10 though I have wemo, zwave, sonoff modules (WiFi), mylight (rf & wifi), Broadlink RM (for IR and some RF ) I've integrated most of my setup with HomeGenie so I can control it all from anywhere, schedule things and view status of things and my cameras. I move my stuff from windows to the PI mainly due to my off grid place so I could reduce power consumption of a PC Running.
I actually moded a CM15A so a PI zero W fits inside.
https://forums.x10.com/index.php?topic=30322.0
I did this mod to 3 different CM15As all are running HomeGenie.
One I added a hat to give me extra USB ports and I'm thinking of upgrading that one pi to the ZeroW2. -
@tuicemen Oh, SWEET! So sounds as if this was a consulting gig for someone else? Very nice!
-
@steve-porter said in Command format on Raspi:
Oh, SWEET! So sounds as if this was a consulting gig for someone else? Very nice!
No, not really. I did create a CM15A Pi combo for the new owners of X10 (Authinix) mainly to show the CM15A could be upgraded as a Pro option to their limited WiFi Module(WM100).
The other two were for myself. I do know of a few others that created these combos for their CM15As based of my shared info. -
@tuicemen Got it all working tonight. YAY! Thanks again guys. Just to get it all in one place, here's what works for me:
/root/.TRIGGERcmdData/commands.json
[
{"trigger":"Living Room Fan","command":"/home/pi/scripts/X10.sh i6","ground":"background","voice":"Living Room Fan","allowParams": "true"},
](duplicated for each X10 house unit, i.e. i6, i5, etc.)
Script:
"/home/pi/scripts/X10.sh i6"echo "pl $1 $2" | nc -w 1 localhost 1099
echo "sent powerline command $1 $2 to mochad"Even with you guys' help this was a bit of a pain. This really should all be put into a simple install guide. But, it works great!
Cheers!
-
@steve-porter Oops,
"home/pi/scripts/X10.sh" -
@steve-porter glad to see you have it all setup and working.
setup is a bit of a pain for new users especially with a large number of devices possible in a X10 setup.
A setup wizard sure would help even for me just adding one new device once in a while. -
-
@steve-porter Actually, I just noticed in my example .json command I left a comma in at the end of the line. That'll be a gotcha. The LAST command line in that file can not have a comma, it won't tell you that, it'll just not update the .json file.