A PC is a device, right? :)

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

If this happens just come back and we'll give you some milk and cookies :laughing:

2 Likes

In theory, everything should work now on the HE end.........except: I apparently don't understand virtual button creation.

At the top of the device page, I have command buttons (push, hold, Double tap, etc). There is an input filed below them asking 'type: NUMBER Button number to [command name]'.

I have tried inserting numbers here, and saving. Yet every time I load the device page, the numbers are gone, and pressing the command buttons results in an error message to fill in required fields. Those number fields appear to be the only empty required ones- yet I cannot enter numeric values that will stay when I save.

What am I missing?

Thanks, from a frustrated noob.

Figured out my button issue. I was definitely doing it wrong. I can get the toggle to work with my basic rule in a dashboard, but now the batch file I made with the remote command from my PC doesn't work. (I changed the device ID and command name to match what the Maker API calls for.) Stuck again. Will Work on what's missing.

Here's the command for the scene itself, to turn it on:

curl http://192.x.x.x/apps/api/52/devices/11/on?access_token=xxxxxxxxxxxxxxxx

Works just fine from the batch file. The command for the virtual button corrects the device ID and command, but does nothing:

    curl http://192.x.x.x/apps/api/52/devices/15/push?access_token=xxxxxxxxxxxxxxxx

Selecting the push command on the device page works. The virtual button on my dashboard works. Feels like something is amiss in the command I'm using, but I cannot for the life of me figure it out.

For the Button CURL command, I believe you also need to pass in the button number, in addition to the “push” command.

1 Like

Yes! That's it! My understanding was not correct. I obviously figured Simply the command name would do the trick. Thanks much! Now, to wrap all this in VBS to suppress Powershell.....

2 Likes

Dangit. Got it all working, except the VBS. I've got this in the VBS:

Set objShell = CreateObject("Wscript.shell")
objShell.run "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -File " & Chr(34) & "C:\tmp\test22.sp1" & Chr(34), 0
Set objShell = Nothing

And this in the .SP1:

Invoke-WebRequest -Uri "http://192.x.x.x/apps/api/52/devices/15/push/1?access_token=xxxxx"

Obviously, some pertinent numbers are removed. :slight_smile: I can't see any issues. But you folks know an awful lot more than I do!

OK, don't mind me. Just a bad typist. I may see the problem! Silly old fart here transposed two letters. Fixing that, to see if it works.