Powershell command no longer working after update

Hey! Is there any way for me to log commands? I have a custom powershell command that's just blank so I can run anything I need via home assistant through it, and I have in my path a script called "bt.ps1" Before updating & migrating from the old version, this worked perfectly fine as such:
service: mqtt.publish
data:
topic: homeassistant/button/MainPC/PowershellCustom/action
payload: bt.ps1 -BluetoothStatus {{ btstatus }}
service: mqtt.publish
data:
topic: homeassistant/button/MainPC/PowershellCustom/action
payload: bt.ps1 -BluetoothStatus {{ btstatus }}
But now it doesn't work. Running the powershell command manually works just fine
Solution:
yeah i found out, because the apps have the exact same name and I started them from windows I kept starting different ones each time The windows bar has a nifty feature when you have 2 programs with the same program name whenever you type it in the search bar it ALTERNATES between the two So that messed up the config somehow, looks like on the new version the mqtt topic changed...
Jump to solution
41 Replies
HASS.Agent Helper
HASS.Agent Helper•10mo ago
Help us Help Others!
To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution
From An unknown user
HASS.Agent Helper
HASS.Agent Helper•10mo ago
Help us Help You!
Please don't delete messages or posts because it makes it impossible to understand what happened. If you don't want your messages to be seen then don't post here. Please provide us with the version number of your client.
You can find it in the HA device info page after 'Firmware'.
Make sure to provide detailed reports of bugs.
Please include error log uploads and info about the bug.
HASS.Agent Helper
HASS.Agent Helper•10mo ago
@Amadeo
barrelltitor
barrelltitorOP•10mo ago
https://github.com/hass-agent/HASS.Agent/pull/47 using the script from here to test won't even show up anything
GitHub
Fix: Powershell command argument binding by amadeo-alex · Pull Requ...
This PR fixes how action arguments are passed on to the PowershellCommand. Previously whole action string was passed as a one argument, this prevented parameter binding - after the changes the acti...
derailius
derailius•10mo ago
I'm just a newb, but I'm pretty sure you need the full path to bt.ps1 in your payload? at least, that's how mine are configured
barrelltitor
barrelltitorOP•10mo ago
I have it in a folder that's declared in my environment so anything I put in there can be used as a "command", e.g if I put the test.ps1 in that folder I can just run "test.ps1" from any powershell window Even running it with the full path won't work The key point here is that the only difference between when it worked before 1 hour ago and when it stopped working is me updating to the new client, so there must be something going on there
derailius
derailius•10mo ago
see? this is why i prefaced my comment! lol
barrelltitor
barrelltitorOP•10mo ago
Yeah all good, you learn something new every day, I'm a powershell noob too
derailius
derailius•10mo ago
that is clever though, and you've just made me change my entire setup, declaring once, is sooo much cleaner than having to do it for every script. thanks! ok, enough derailing 😉
Amadeo
Amadeo•10mo ago
FYI that PR has been merged into a development branch of 2.1.0 release (that's not released yet :D)
barrelltitor
barrelltitorOP•10mo ago
Yeah I'm just saying it doesn't pop up anything at all, no arguments or anything Nothing runs Just running a custom command not a powershell one works fine, I just add powershell to my command in HA and im all good
DrR0x
DrR0x•10mo ago
Well I guess that works but this seems really weird @Amadeo doesn't the extended logs report when commands are run and info about them or is that something you enable in visual studio?
barrelltitor
barrelltitorOP•10mo ago
Should I make a PR for a feature request to be added in? I'd say that fits into extended logs and is quite useful, e.g Command X ran with arguments <here>
DrR0x
DrR0x•10mo ago
You definitely could but I think we might have this so let's check with Amadeo first. Would fit best as an extra toggle or even file but this will work. We can add stuff like this for v3
Amadeo
Amadeo•10mo ago
I think I missed smth, example from the PR mentioned below will not work with current version, are we talking right now about adding extended logging "always" ("always" because there will be "[POWERSHELL] [{name}] Launching PS {descriptor} with action '{action}' failed" logged when execution fails) or about some bug 😄 there were additional changes before this PR that could of broken compatibility with the original one
DrR0x
DrR0x•10mo ago
Adding it always. Hence the reason I reckon an extra toggle but that's more complex. (And requires another 5 minute walk)😂
Amadeo
Amadeo•10mo ago
@barrelltitor can I please have the ps script? I'll test it on the PR branch to see it it'll start working again oh wait you've been providing command and the parameters as one payload
payload: bt.ps1 -BluetoothStatus {{ btstatus }}
payload: bt.ps1 -BluetoothStatus {{ btstatus }}
I'm not quite certain that it was ever supported, hmm if the "action" doesn't end with ".ps1" it will be treated as a command and not script, this really worked before? how is the command configured within HASS.Agent?
barrelltitor
barrelltitorOP•10mo ago
It worked before i updated
barrelltitor
barrelltitorOP•10mo ago
Changed nothing before or after updating, the only change was that it stopped working I did get it working like this using just "Custom" instead of custom powershell, so that works for me
No description
barrelltitor
barrelltitorOP•10mo ago
I can revert back to hass agent and take a video of it working if it helps in any way, but I've had it working like this forever I didn'[t even know I had to provide an "action" lol It always worked just with "payload" set to the entire command
Amadeo
Amadeo•10mo ago
na, not worth it 😄
barrelltitor
barrelltitorOP•10mo ago
I'd give logs but the logs don't record commands For me personally it's kinda fixed as I can use custom Oh @Amadeo I actually got it from the docs Docs example:
action:
- service: mqtt.publish
data:
topic: "homeassistant/switch/test-vm/test-vm_custom/action"
payload: "\"C:\\Program Files\\BowPad\\BowPad.exe\""
action:
- service: mqtt.publish
data:
topic: "homeassistant/switch/test-vm/test-vm_custom/action"
payload: "\"C:\\Program Files\\BowPad\\BowPad.exe\""
Amadeo
Amadeo•10mo ago
when you configure a powershell command it'll be executed differently base of if it's "script" (ending with .ps1) or "command" (anything else) - in the "Command or Script" text box - if you then use payload it'll be added as a parameter to the "script" one oh yeah, with "Custom" it should work as expected
barrelltitor
barrelltitorOP•10mo ago
How would it execute differently though? If the script is available in the path it's just a command I can run it anywhere in my system by just doing "bt.ps1" as it's in my path
Amadeo
Amadeo•10mo ago
with "Custom" HASS.Agent says to system basicall "yo, here you have X, execute it", with powershell one it's appropriately passed on to powershell.exe either as a command or script hm, that would partially explain why it worked before
barrelltitor
barrelltitorOP•10mo ago
(has no output, but it succeeded)
No description
No description
barrelltitor
barrelltitorOP•10mo ago
No description
barrelltitor
barrelltitorOP•10mo ago
Could it have been something from a failed migration? I edited the action a few times, and now all of a sudden it works lol
barrelltitor
barrelltitorOP•10mo ago
was actually recording to show you at the time, the video shows it not working then working again after removing "test.ps1" from the field and confirming again To clarify: I did have it empty before, I set it to test.ps1 a few minutes ago testing it
Amadeo
Amadeo•10mo ago
Mind you Bt control is integrated in HASS.Agent itself It's caled RadioCommand if memory serves me right :D
Amadeo
Amadeo•10mo ago
No description
Amadeo
Amadeo•10mo ago
Not likely, the way that payload is passed on to the scripts/commands was changed with one of the PRs to fix a bug (not the PR mentioned above, other one) - most likely it was the cause Wait so what was not working before works now? And if you choose the "switch" as entity type in HASS.Agent it'll be feedback as well (will update when you change it on the system)
barrelltitor
barrelltitorOP•10mo ago
yup, no idea why, I've tried removing the command from the configuration and re-adding it several times before
Amadeo
Amadeo•10mo ago
now I'm more interested 😄 do you have a copy of the old config maybe? so we could compare and check
barrelltitor
barrelltitorOP•10mo ago
I didn't take a backup unfortunately, I just took screenshots of everything as I didn't know where it stored stuff, figured I could quickly re-do them in case of anything is it possible maybe it didn't properly subscribe to the topic or something and only did it when I changed something? I didn't uninstall the old agent before, I just closed it, not sure if that could have caused issues too
DrR0x
DrR0x•9mo ago
They can both be installed at the same time so it should have been fine @barrelltitor did you ever sort this out? or more so figure out what couldve caused the issue?
Solution
barrelltitor
barrelltitor•9mo ago
yeah i found out, because the apps have the exact same name and I started them from windows I kept starting different ones each time The windows bar has a nifty feature when you have 2 programs with the same program name whenever you type it in the search bar it ALTERNATES between the two So that messed up the config somehow, looks like on the new version the mqtt topic changed
barrelltitor
barrelltitorOP•9mo ago
i did a bunch of stuff though in testing but I don't know if it was necessary, i removed hass integration + deleted the mqtt device and let the new version properly do its stuff, and I haven't had issues since
DrR0x
DrR0x•9mo ago
Why tf would they go to effort to make it alternate 🤣 unless for some reason it favours the oldest oppened one? meaning its a bug?
barrelltitor
barrelltitorOP•9mo ago
yeah it opens the oldest opened one, not the latest, idk why
DrR0x
DrR0x•9mo ago
so weird
Want results from more Discord servers?
Add your server