Skip to main content

I have a working Alexa Skill that can operate my layout, including:

  • Start up and shut down engines with or without dialog
  • Set engine speed, with and without dialogs
  • Reset engines
  • Refuel
  • Blow whistle/horn
  • Ring bell
  • Change direction
  • Stop immediate
  • Open front/rear couplers
  • Smoke level
  • Send Halt command
  • Control engines and/or trains
  • Read out engine/train/accessory/switch/route status (road name/number, engine speed, switch state, etc)
  • Throw switches
  • Fire routes

I'm thinking about adding capabilities to control smoke and momentum as well.

If folks are interested, I can try to generalize it and try to get it certified for others to use. It's based on the PyTrain PyThon code I developed.

  -- Dave

Last edited by cdswindell
Original Post

Replies sorted oldest to newest

The PyTrain Alexa skill is live! There is a bit of setup, and I haven't finished the documentation, but with the skill,  you can perform all of the actions listed above with simple, (somewhat) intuitive voice commands! Examples include:

  • halt or emergency halt
  • start/start up/power on/power up train <tmcc_id>
  • start up engine 5 with dialog
  • accelerate/speed up/set the speed of train 5 to speed step 100 (or "normal speed" or "limited")
  • slow train 6 to slow speed with dialog
  • enable smoke on engine 33
  • reverse train 53
  • tell engine 53 to move forward
  • reset engine 25
  • refuel train 33
  • toggle the bell on engine 54
  • blow the horn/whistle on 53 (blows the horn on engine 53)
  • shut down train 5 [with dialog]
  • release/open/trigger on front/rear coupler on engine 6
  • throw switch 7 out
  • fire route 6
  • get status of train/engine/switch/accessory/route <tmcc_id>

The skill relies on the PyTrain API Server, which you must run locally (the same network as your Base 3). It also must be accessible from the internet and accessed via HTTPs.

Making a host accessible to the internet is relatively easy if you are running a home gateway from NetGear or any of the other major gateway companies. On the advanced setup screen, look for an option named  "Port Forwarding" or "Port Triggering". As you see below, I have specified that requests to port 443 (default HTTPS port) from "the outside" should be directed to port 443 on my local host at 192.168.1.155. The interface to do this will vary by gateway manufacturer.

Screenshot 2025-02-13 at 3.47.42 PM

The hard part (at least for me) is enabling HTTPS access. If others are interested in using this skill, I will provide documentation. It isn't really hard, but it does require some moving pieces, such as setting up SSL certificates and using a dynamic IP service to give a "domain name" to your gateway's external IP address. This is what all the machines on your local network are known as on the internet. I use No-IP.com, but there are others out there as well.

With that all done, you say to your local Alexa "Alexa, open PyTrain", and my skill leads you through a small setup process where you give it the domain name you create with No-IP.com (or whomever you use). In my case, this is "77exeter.servemp3.com". With that connection made, the Alexa skill takes your verbal commands, sends them to your local API server (through the port forwarding process), and then onto your Base 3 (or Ser2). I'll post a YouTube video over the next few days showing the system in operation. Again, all of this can run on a low-cost Raspberry Pi!!

In the near term, I plan to add more commands to control accessories (particularly power districts). I may also add commands to control lighting (ditch, mars, etc.) I have volume control wired into the API, but I haven't added it to the Alexa skill yet. Any interest in changing momentum? I tend to think of this as a set once and forget.

It is pretty cool to be able to control my big layout up in New Hampshire with all of this. It won't replace my Cab 2 (or Cab 3), nor will it preempt the control panels I'm currently fabricating, but it is a fun and effective way to make things happen on my layout!

  -- Dave

Attachments

Images (1)
  • Screenshot 2025-02-13 at 3.47.42 PM

I've modified my API code and the Alexa skill to better handle security. The Alexa skill will now request a token from the API in a secure way that allows PyTrain to know the request is valid and then allows Alexa to access and control your layout via voice control.

The new skill is currently being certified.

Separately, I'll be adding voice commands to control accessories and power districts later this week.

  -- Dave

The new skill is now up on the Alexa Skills store. I also modified it so you can dispense with the HTTPS proxy and just use HTTP, if you want. HTTPs is also supported. I also added a voice command to speak the TMCC ID of an engine given its road number.

Once you set up yourPyTrain API server, simply say "Alexa, open PyTrain". The skill will ask you speak the name (or IP Address) where your local network is accessible externally, and you're set. Say "help" to get a list of some of the things you can say.

  -- Dave

@hokie71 posted:

Impressive project and congratulations on your success. For those of us who don't know about Alexa skills, is the fundamental advantage that this can be used for total voice command of the layout?

The short answer is yes. This provides voice control to pretty much any legacy or TMCC-equipped component on your layout. In a week or two, it will also support control of the LCS ASC2 and BPC2.

Now, with that said, I in no way think this will replace a handheld remote. Or a nicely crafted control panel. It has some practical uses, as you can now be anywhere in your layout room and say "Emergency Halt" and everything will stop. But it will be fun to blow whistles, start up and shut down engines, and do some other layout operations by Voice.

I have added a few features that remotes cannot do. For example, there's a command that lets you get the TMCC ID of any engine given its road number. I've also added some features to let you ring a bell or blow a whistle for a spoken time duration (Hopefully only seconds, but you never know.)

I've been a professional software developer for over 45 years. I enjoy this aspect of the hobby as much (if not even a little more) as seeing my trains run. 😉

  -- Dave

Last edited by cdswindell

The PyTrain skill has been updated to use HTTP or HTTPs  to communicate with your local PyTrain Api server. I’ve also streamlined how API tokens are automatically assigned. Bottom line, it is easier to configure and get everything up and running!

I resubmitted the skill again tonight to add support for Boost and Brake speed voice commands . These features should be live in a few days.

  — Dave

Ive changed the name of the Alexa skill from "PyTrain" to "My Layout", It turns out that the phrase "pytrain" confused Alexa and it sometimes tried to launch "Potty training" or "pantry". First world problems.

The new invocation name makes for better syntax as well. For example, you can now say:

  • Alexa, ask my layout to stop engine 67
  • Alexa, ask my layout to Emergency Halt

Of course, you can still say Alexa, run my layout and your device will listen for commands for up to 30 seconds before timing out (an Alexa requirement to keep someone from writing an application that just listened to everything you said in your home...)

I will publish a list of all the supported voice commands in a day or so. I've tried to make the commands intuitive but allow shortcuts to avoid length sentences. For example, you don't have to say the word "engine" every time. But if you want to control a train (lash-up), you do have to specify "train" or "lash up" or "consist": Alexa, ask my layout to accelerate train 20 to restricted.

  -- Dave

Here is a complete list of the voice commands supported by the "My Layout" Alexa Skill:

Voice Commands:
  • Accessories:
    • Turn off | on accessory {tmcc_id} [for {duration}]
    • Turn off | on track|power district {tmcc_id}
  • Routes:
    • Activate | Fire | Trigger route {tmcc_id}
  • Switches:
    • Throw switch {tmcc_id} [to thru | out]
  • Train/Engine:
    • Accelerate/Decelerate [engine | train] {tmcc_id} to {speed step | official railroad speed} [with dialog]
    • Blow the horn | whistle on [engine | train] {tmcc_id} [for {duration}]
    • Boost [engine | train]  {tmcc_id}  [for {duration}]
    • Brake [engine | train]  {tmcc_id}  [for {duration}]
    • Enable | Disable sequence control on [engine | train] {tmcc_id}
    • Forward | Reverse [engine | train] {tmcc_id}
    • Open front | rear coupler of [engine | train]  {tmcc_id}
    • Refuel [engine | train] {tmcc_id} [for {duration}]
    • Reset [engine | train] {tmcc_id}
    • Ring | Toggle bell on [engine | train] {tmcc_id} [for {duration}]
    • Raise | Lower volume of [engine | train] {tmcc_id}
    • Set the smoke level of [engine | train] {tmcc_id} to on | off | low | medium | high
    • Start up | Shut down [engine | train]  {tmcc_id} [with dialog]
    • Stop [engine | train] {tmcc_id}
    • Set the momentum of [engine | train] {tmcc_id} to low | medium | high
  • Miscellaneous
    • Find the TMCC ID of engine {road_number}
    • Get the status of accessory | engine | route | switch | train {tmcc_id}
    • Emergency Halt | Halt
Notes:
  • Terms in [square brackets] are optional; [engine | train] defaults to “engine”
  • Terms in {squiggle brackets} take specific values;
    • {tmcc_id}: say the TMCC ID of the equipment to control (1 to 99)
    • {duration}: say the duration to repeat the action (seconds or minutes, max of 120 seconds)
  • Terms separated by “|” represent options
  • Most commands have alternative forms, for example, you can say:
    • Accelerate  [engine | train] {tmcc_id} to {speed step | official railroad speed} [with dialog]  OR
    • Set the speed of  [engine | train] {tmcc_id} to {speed step | official railroad speed} [with dialog]  OR
    • Set speed of  [engine | train] {tmcc_id} to {speed step | official railroad speed} [with dialog]  OR
    • Speed up | Slow down [engine | train] {tmcc_id} to {speed step | official railroad speed} [with dialog]


The skill is currently being certified and should be up in a day or so. I have hidden the "PyTrain" skill because of the name confusion I mentioned above.

  -- Dave

Last edited by cdswindell

Add Reply

Post
×
×
×
×
Link copied to your clipboard.
×
×