<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Run one of your TRIGGERcmd commands from a python script via Home Assistant]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">You should see this at the top of the page:<br />
<img src="/forum/assets/uploads/files/1735345259641-f9d78abf-2992-4714-86d1-df45a2813cf5-image.png" alt="f9d78abf-2992-4714-86d1-df45a2813cf5-image.png" class=" img-fluid img-markdown" /></p>
<pre><code>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)
</code></pre>
<p dir="auto">The above script shows how to flip a switch, including the virtual switches you get from the official <a href="https://www.triggercmd.com/forum/topic/193/how-to-run-commands-from-home-assistant">TRIGGERcmd integration</a>.</p>
]]></description><link>https://www.triggercmd.com/forum/topic/3191/run-one-of-your-triggercmd-commands-from-a-python-script-via-home-assistant</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 21:39:29 GMT</lastBuildDate><atom:link href="https://www.triggercmd.com/forum/topic/3191.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 28 Dec 2024 00:25:32 GMT</pubDate><ttl>60</ttl></channel></rss>