Your code looks fine, but the error leads me to believe that your hass user does not have sudo rights.
When you try it by logging in through ssh, are you running the command as the hass user or as root or pi? It will always work when testing from ssh as root or pi, but the hass account by default does not have a password and is not in the sudoers list, so unless you set a password for hass, I assumed you were testing as root or pi.
All commands from within Home Assistant are run as the hass user, so in order to use sudo from any command within Home Assistant, the hass user has to be in the sudoers list.
Edit /etc/sudoers as root, and at the bottom you will see a line:
pi ALL=(ALL) NOPASSWD: ALL
Add hass down there so that it looks like this:
pi ALL=(ALL) NOPASSWD: ALL
hass ALL=(ALL) NOPASSWD: ALL
lol yeah, I’m an addict… I work from home, so I often take breaks throughout the day to work on my own home automation setup, and the first thing I do is check to see if there are any new updates to Home Assistant, AppDaemon or HADashboard before I get started, then I pop over to the forums to see whats new and I get sucked in reading every single new post, and before I know it, I’ve spent a few hours doddling around, not getting my own crap done in the house and not getting back to the day job LOL
There is still a lot I don’t know, so I’m learning things every day, so the least I can do is help out where I can