chroma / source /Home Assistant Python Script to set an entity state.html
anubhav77's picture
initial commit
e6eabd3
<html><head><title> Home Assistant Python Script to set an entity state</title><meta name="Additional Keywords" content="Github"/>
<meta name="URL" content="https://github.com/xannor/hass_py_set_state"/>
<meta name="Source" content="internet"/>
<meta name="Created" content="2023-02-25T03:08:00.000Z"/>
<meta name="Already Read" content="false"/>
<meta name="Name" content=" Home Assistant Python Script to set an entity state"/>
<meta name="parent" content="References"/>
</head><body><H1> Home Assistant Python Script to set an entity state</H1><a href="https://www.notion.so/Home-Assistant-Python-Script-to-set-an-entity-state-627562a55308499cadddef18da343737">Link to original Notion Page</a></p><table border='1'><tr><td><b>Property</b></td><td><b>Value</b></td></tr><tr><td>Additional Keywords</td><td>Github</td></tr>
<tr><td>URL</td><td>https://github.com/xannor/hass_py_set_state</td></tr>
<tr><td>Source</td><td>internet</td></tr>
<tr><td>Created</td><td>2023-02-25T03:08:00.000Z</td></tr>
<tr><td>Already Read</td><td>false</td></tr>
<tr><td>Name</td><td> Home Assistant Python Script to set an entity state</td></tr>
<tr><td>parent</td><td>References</td></tr>
</table>&nbsp;<div><h1 class='n_heading_1'>Set State</h1 ><p class='n_paragraph'>Home Assistant Python Script to force set an entity state</p ><h2 class='n_heading_2'>How it works</h2 ><p class='n_paragraph'>This script adds a service that lets you update the state and/or attributes of any entity, similar to the developer tools</p ><p class='n_paragraph'>Requires <code>python_script:</code> to be enabled in you configuration</p ><h2 class='n_heading_2'>Installation</h2 ><h3 class='n_heading_3'>HACS</h3 ><p class='n_paragraph'>Requirements:</p ><ul><li class='n_bulleted_list_item'>HACS version 0.9 or higher</li ><li class='n_bulleted_list_item'>Enabled <code>python_scripts:</code> in your Home Assistant configuration</li ><li class='n_bulleted_list_item'>Enabled <code>python_scripts</code> as option, in the HACS configuration. (If you missed this, kindly read below!)</li ></ul><p class='n_paragraph'>You are only able to use this custom repo with HACS, if Python Scripts is enabled in Home Assistant. Also, "python_scripts" should have been enabled during the HACS setup through "Integrations" in Home Assistant.</p ><img src='https://s3.us-west-2.amazonaws.com/secure.notion-static.com/010abb0c-125f-47c8-9b12-6b092c16cdd8/68747470733a2f2f692e696d6775722e636f6d2f494741344c567a2e706e67?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20230225%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20230225T213404Z&X-Amz-Expires=3600&X-Amz-Signature=f27f63efb9b30f17b2250f7e8229d235a803a91e9df8ca290dff50330e9ebb01&X-Amz-SignedHeaders=host&x-id=GetObject'/><p class='n_paragraph'>If you missed that part, you need to remove HACS, and add it again, in order to find the "Python Script" category! This time, remember to set a checkmark in "Enable python_scripts discovery & tracking":</p ><img src='https://s3.us-west-2.amazonaws.com/secure.notion-static.com/5de3240b-8bbb-4579-93ab-e5fdec5a0431/68747470733a2f2f692e696d6775722e636f6d2f626a445577447a2e706e67?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20230225%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20230225T213404Z&X-Amz-Expires=3600&X-Amz-Signature=8996bb479c10d4e5508938a385d517cbd72d881f093c1dddcf9a2895ff19b5cf&X-Amz-SignedHeaders=host&x-id=GetObject'/><p class='n_paragraph'>Find more information about the HACS configuration <a href='https://hacs.xyz/docs/configuration/basic#changing-the-configuration'>here</a> and <a href='https://hacs.xyz/docs/categories/python_scripts'>here</a>. If you used the YAML-way to configure HACS, it's a bit easier. Just edit the YAML configuration for HACS. That parts is also mentioned <a href='https://github.com/xannor/hass_py_set_state/blob/master/here'>https://hacs.xyz/docs/categories/python_scripts#enable-if-you-used-yaml-to-configure-hacs</a>.</p ><img src='https://s3.us-west-2.amazonaws.com/secure.notion-static.com/fd06b67f-a514-4975-9283-088e6b225bc3/68747470733a2f2f692e696d6775722e636f6d2f6f64505639386a2e706e67?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20230225%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20230225T213404Z&X-Amz-Expires=3600&X-Amz-Signature=f3f99ff8e00f22cc64e1cb4594494b8549880c01388b0156ded2e67f3892d4f5&X-Amz-SignedHeaders=host&x-id=GetObject'/><h3 class='n_heading_3'>Manual</h3 ><p class='n_paragraph'>Copy the Python script in to your <code>/config/python_scripts</code> directory.</p ><h2 class='n_heading_2'>Service arguments</h2 ><h2 class='n_heading_2'>Usage</h2 ><p class='n_paragraph'>Each call requires at least an entity_id and a state or attributes (otherwise it wont do anything)</p ><p class='n_paragraph'>example:</p ><pre>entity_id: sensor.random_sensor
state: 0
allow_create: true
&nbsp;</pre><p class='n_paragraph'>(Thanks to <a href='https://community.home-assistant.io/u/rodpayne'>@rodpayne</a> for the initial script: (<a href='https://community.home-assistant.io/t/how-to-manually-set-state-value-of-sensor/43975'>https://community.home-assistant.io/t/how-to-manually-set-state-value-of-sensor/43975</a>)</p ><p class='n_paragraph'>I'm not that used to HACS, but i spotted <a href='https://github.com/xannor/hass_py_set_state/issues/1'>#1</a> - so i guess it's better with more details about HACS here.</p ><p class='n_paragraph'>It would be even better to ask the HACS team to add a disclaimer on the "hacs/settings" page, about missing categories. I guess most users just started using HACS, would like that. But i don't have the time to do that, right now.</p ><p class='n_paragraph'>Thanks for making the scrip ready for HACS, btw :-)</p ></div></body></html>