A PC is a device, right? :)

I haven't seen this addressed here, but I only did a quick search. Apologies if it's been covered.

Is there a way to use hotkeys on a PC to control devices in Hubitat (for instance, using the F7 key to toggle a scene on/off)?

I got the ide after running across the PCPanel device. I figured something like that would allow control over my lighting for my Zoom sessions, as well as my video switching and audio mixing, all in one place. Now I've got this idea in my head, and I want to see if I can do it. :slight_smile:

Installing the Maker API built-in app on your HE hub and linking various device to Maker API (inside it's configuration page), allows HTTP calls to be made from outside the HE hub to interact with those devices. So for example you could link scene devices with Maker API and issue commands from your PC. You just need to work out how you want / can issue those commands. There is another thread looking at using Event Ghost, but can't remember if it can issue commands back the other way or detect hot keys like you describe.

Simon

Sweet! I got it to work with the command line typed into a web browser. Now, to make that command line launch from a hotkey. That was easier than I thought it would be. Thanks much!

EDIT: how to execute the URL without launching the browser might be the next thing to work out. :frowning:

1 Like

I setup a virtual motion sensor based on activity on my laptop, but that is a batch script that just runs periodically, not triggered like you want. Perhaps a simple script on the desktop might be a good start...

Getting closer. I figured out how to send the command in Powershell, without launching the browser. Now, to figure out how to send the command without having to open Powershell.

I'm kind of a neophyte at this stuff. Can you tell?

1 Like

I think I was able to do that as well, let me grab a link to my code for you to take a look.

Here's a link to the folder.

I think the vbs script may have been the thing that helped stop PS from opening. There was a thread here somewhere that people gave me a hand with this. Might try and find it later if you are still stuck.

Simon

Thanks. A little looking around revealed I can put 'curl' before the URL- but I still have to launch Powershell to be able to do it. Maybe I have to make a batch file that opens Powershell, then initiates the command. It's fun trying to figure all this out. :slight_smile:

1 Like

I got it working OK with a batch file. It flashes a command window for a fraction of a second, but I can deal with that. Now, I need to see if I can work the commands to make it a toggle, so I don't need a second hotkey (and batch file) to turn it off again. That's a matter for tomorrow. If I were someone who understood more scripting, I'd probably be in bed right now. :slight_smile:

1 Like

By sheer coincidence @sburke781 gave me advice on exactly the same topic yesterday! :astonished:

Unfortunately no way to avoid this with batch or powerscript scripts.

Use a button virtual device and trigger your actual device within HE via RM or simple automation.

1 Like

I'm sure I got this to work, in fact it is running now and doesn't show up. Let me go back through my code and the thread somewhere where I discussed it. I'm pretty sure it was why I introduced the vbs script...

Here it is, @reachjeffs posted about it on the thread for my Virtual Motion Sensor, it is the VBS script which then runs the PS script, with the sole purpose of the VBS script being to supress the PS window. I talk about having made some minor tweaks to what Jeff proposed, which I include in the original post of the thread.

This is the PC Controller thread I mentioned earlier, which only came up recently. Looks like it may include something like what you're trying to achieve @uncleflip, but can understand if you want to tinker away on it yourself :slight_smile: All part of the fun...

1 Like

Just tried that. I created a vbscript (exactly like your helper script but substituting my ps1 file for your motion sensor script). However when I launch the vbs file nothing happens to the state of my virtual device and I'm not sure why especially as there were no error messages. Pretty sure I've missed something but don't know what it is.

My ps1 file works fine when run from a batch file or via the powershell.

Going to retract my words in the post following yours and say another thanks to @sburke781. If you use his vb helper script from his github (post #5) and just substitute your powershell script then running the vbscript file like so:

C:\Windows\System32\wscript.exe "C:.......\scriptname.vbs"

no powershell/CMD window will appear.

3 Likes

@uncleflip indeed PC Controller will do the job. Check the thread and if you have any questions post it there and I'll assist

1 Like

Hmmm....you're teaching me more about this system. (I'm pretty new to it.) I saw that there are virtual buttons, but had no idea what their intended purpose/use was. Now I will experiment with that. Thanks for leading me to another aspect of Hubitat!

2 Likes

Thanks again for the VBS stuff. I have never created a VBS file, and have never knowingly used one (though I'm sure VBS files have been part of many things I've done in the past.)

Now I need to tinker with it and figure out what I'm doing. I'm sure with enough analysis, I could pare down your examples to just the bits that will suppress the PowerShell window, and hopefully also launch my batch file- or incorporate the command into the VBS itself. (As I may have mentioned, I'm not experienced at scripting....but I do tend to pick up concepts and figure things out in time.....so It will take a little trial and error, but shouldn't stop me in my tracks. It'll probably be easier than figuring out why I couldn't get a proximity sensor to properly trigger a servo unit....)

1 Like

The VBscript file is all of 3 lines (exactly per @sburke781's pc motion sensor PC_VirtualMotionSensor.vbs):

Set objShell = CreateObject("Wscript.shell")
objShell.run "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
-executionpolicy bypass -File " & Chr(34) & "[insert path and name of your ps1 file here].ps1" & Chr(34), 0
Set objShell = Nothing

and create a shortcut link with the target like :

C:\Windows\System32\wscript.exe "C:.......[xxxxx].vbs"

1 Like

OK, Tried using the altered VBS to launch my batch file. True to expectation, the Powershell window did not appear. Also, the batch file failed to do anything. (It worked fine launched on its own.) Time to do more digging and figure out the problem..

You don't use a batch file. You just need to create a powershell (.ps1) script file with the contents, and then reference it in the vbscript file eg

Invoke-WebRequest -Uri "http://XXX.XXX.X.X/apps/api/XXX/devices/XXX/[command]?
access_token=XXXXXXXX"

In this case the URI is a maker api url.

1 Like

Ah! I didn't realize I couldn't use it with a batch file. Got it. (I'm very new to all this, if you hadn't picked up on that... :slight_smile: )

The VBS is pretty much exactly what your example shows, just with my file name. I'll go make it a ps1 file, and see if that works the way it should. If not, I will cry like a little girl. :grinning:

Thanks for your help!

2 Likes