Execute scripts in HA

Posted on
Wed May 15, 2024 7:47 am
durosity offline
User avatar
Posts: 4351
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Execute scripts in HA

Is it possible to run scripts that are in Home Assistant with this plugin? I can see that I can add the script as a generic device, and if I then create an action group I can specify that device and set a 'Genetic Device Command' but even if I leave it blank and execute it I get this error:

Code: Select all
   Home Assistant Agent Error      Error in plugin execution ExecuteAction:

  File "plugin.py", line 1272, in send_generic_command
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
type: Expecting value: line 1 column 1 (char 0)


(I get it even if I try to populate it, although tbh I'm not entirely sure what would need to go into it).

I don't need to pull any data back from HA with the script, all it'll do is set whether a cat is marked as inside or outside using the Sure Petcare Plugin which has a service call option to set their location manually (eg if they've come in via the front door rather than via the catflap)

Computer says no.

Posted on
Wed May 15, 2024 8:17 am
FlyingDiver offline
User avatar
Posts: 7258
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Execute scripts in HA

I wouldn't do it that way. I have no idea what a script entity looks like or how it behaves. I would just write a Python script that uses an HTTP request to HA to run the script. Something like:

Change ABCDEFGHI to the HA Auth Token you're using for the plugin.
Change MYURL to the hostname/port for the HA server.
Change my.script to the script entity.

NOT TESTED
Code: Select all
from requests import post

headers = {
    'Authorization': 'Bearer ABCDEFGHI',
    'content-type': 'application/json',
}

url = 'https://MYURL/api/states/my.script'
data = {
    "state": "office"
}

response = post(url, headers=headers, json=data)
indigo.server.log(response.text)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed May 15, 2024 8:34 am
durosity offline
User avatar
Posts: 4351
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Execute scripts in HA

Oh thanks, that would make a lot more sense and I can just setup individual action groups for that.

Just tried that, but it seems to be deleting the script, then replacing it with a new one.. which is weird? And also doesn't actually run.

Also what does the data = { "state": "office"} element do?

Screenshot of scripts list before actioning (Specifically relating to the top one for Pet - Bianca: Set Inside):

Screenshot 2024-05-15 at 15.40.50.png
Screenshot 2024-05-15 at 15.40.50.png (53.27 KiB) Viewed 177 times


After script has run:

Screenshot 2024-05-15 at 15.41.05.png
Screenshot 2024-05-15 at 15.41.05.png (52.59 KiB) Viewed 177 times

Computer says no.

Posted on
Wed May 15, 2024 9:39 am
FlyingDiver offline
User avatar
Posts: 7258
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Execute scripts in HA

The "data = " line is in case your script takes parameters (arguments). I just grabbed that example from the internet.

This is not a plugin issue. This is not functionality that the plugin will ever support.

If you need help running scripts on your HA server, I recommend the HA forums.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed May 15, 2024 2:54 pm
durosity offline
User avatar
Posts: 4351
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Execute scripts in HA

Thanks for pointing me in the right direction!


Sent from my iPhone using Tapatalk Pro

Computer says no.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest