12345678910111213141516171819202122232425 |
- #!/usr/bin/env python
- import os
- from requests import post
- def get_env(name):
- value = os.getenv(name, None)
- if value is None:
- raise Exception('Missing {} from the environment'.format(name))
- return value
- if __name__ == '__main__':
- endpoint = get_env('HA_ENDPOINT')
- token = get_env('HA_TOKEN')
- url = '{}/api/services/switch/toggle'.format(endpoint)
- data = {'entity_id': 'switch.on_air_switch_switch'}
- headers = {
- "Authorization": "Bearer {}".format(token),
- "content-type": "application/json",
- }
- response = post(url, headers=headers, json=data)
- print(response.text)
|