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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login