Run one of your TRIGGERcmd commands from a python script via Home Assistant
-
Get your HA "Long-lived access tokens" from the Security page under your user profile. Click your HA username in the lower left, to open your user profile.
You should see this at the top of the page:
import requests # Home Assistant settings BASE_URL = "http://(your HA server IP):8123/api" TOKEN = "(your long-lived HA access token)" # Headers for authentication HEADERS = { "Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json" } def toggle_light(entity_id): """Toggle a light entity in Home Assistant.""" url = f"{BASE_URL}/services/light/toggle" data = {"entity_id": entity_id} response = requests.post(url, json=data, headers=HEADERS) if response.status_code == 200: print(f"Successfully toggled {entity_id}.") else: print(f"Failed to toggle {entity_id}. Status code: {response.status_code}, Response: {response.text}") # Example usage if __name__ == "__main__": light_entity_id = "switch.laptop_calculator" # Replace with your entity ID toggle_light(light_entity_id)
The above script shows how to flip a switch, including the virtual switches you get from the official TRIGGERcmd integration.