Python script to call external URL

Hey guys,

I have been working with rest_command with hass.services.call()
I am not sure what is the correct syntax. (maybe there is a better way? like http call directly from my python code?)

To be precise, this is what I have in my setup:

configuration.yaml:

rest_command:
  home_1:
    url: 'my external URL here'

my code in python_script/panic.py:
A) This works:

hass.services.call(‘rest_command’, ‘home_1’)

B) Do not work without Error:

hass.services.call(‘rest_command’, ‘my external URL here’)
hass.services.call(‘rest_command’, ‘url:my external URL here’)

What I am trying to do is to avoid editing the configuration file every time I need to add/remove a link (under rest_command urls), since my list will be quite long.
So I prefer to plug in the list of URLs in my python code directly.

Any help would be highly appreciated.
Thank you All!

hass.services.call only calls home assistant objects, that’s why your top method works. You are feeding it a domian but not a entity_id in the domain.

You might be able to maintain a list of urls in your python code, then set the state of rest_command.home_1.attributes.url (not sure if that’s the correct syntax) to one of the items in your list, then call your service hass.services.call(‘rest_command’,‘home_1’)

1 Like

Thank you very much @petro!
This sounds like a good idea. But I think, and you might agree, AppDaemon helps better in this area.
I am interested in complex automations with data from serial input and API calls as outputs so I have already moved on to AppDaemon and things are going well so far. Not much hassle with urls over there.

Thank you again!

Yep, I moved to appdaemon myself. Haven’t looked back!

1 Like