{"id":13579849,"url":"https://github.com/pmazz/ps_hassio_entities","last_synced_at":"2025-04-05T23:32:48.041Z","repository":{"id":160082135,"uuid":"240900380","full_name":"pmazz/ps_hassio_entities","owner":"pmazz","description":"Python script to handle state and attributes of existing sensors and entities","archived":false,"fork":false,"pushed_at":"2021-03-07T22:15:32.000Z","size":33,"stargazers_count":58,"open_issues_count":4,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-05T18:50:04.655Z","etag":null,"topics":["hacs","home-assistant","python","python-script"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmazz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-02-16T13:54:51.000Z","updated_at":"2024-08-24T08:05:04.000Z","dependencies_parsed_at":"2024-01-16T20:29:25.772Z","dependency_job_id":"64d3c196-a9a9-495e-89df-ee19f88e6b3d","html_url":"https://github.com/pmazz/ps_hassio_entities","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmazz%2Fps_hassio_entities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmazz%2Fps_hassio_entities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmazz%2Fps_hassio_entities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmazz%2Fps_hassio_entities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmazz","download_url":"https://codeload.github.com/pmazz/ps_hassio_entities/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415793,"owners_count":20935383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacs","home-assistant","python","python-script"],"created_at":"2024-08-01T15:01:43.973Z","updated_at":"2025-04-05T23:32:43.031Z","avatar_url":"https://github.com/pmazz.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Home Assistant Entities Script\n\n[![hass_badge](https://img.shields.io/badge/Platform-Home%20Assistant-blue.svg)](https://www.home-assistant.io)\n[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/hacs/integration)\n[![GitHub Release](https://img.shields.io/github/release/pmazz/ps_hassio_entities.svg)](https://github.com/pmazz/ps_hassio_entities/releases)\n[![GitHub Last Commit](https://img.shields.io/github/last-commit/pmazz/ps_hassio_entities.svg)](https://github.com/pmazz/ps_hassio_entities/commits)\n\nPython script for Home Assistant to handle state and attributes of existing sensors and entities.\nUseful if you need to change a sensor's state or attribute from whithin a script, an automation, or your Lovelace UI.\n\n## Installation\n\nYou can install this script via [HACS](https://hacs.xyz) or just download `hass_entities.py` file and save it in your `/config/python_scripts` folder.\n\nThis script use Home Assistant [python_script](https://www.home-assistant.io/integrations/python_script) component and you have to add it to your `configuration.yaml` file.\n\n## Usage\n\n### 1. Set both state and attributes\n\n| Name | Type | Required | Description |\n| ---- | :--: | :------: | ----------- |\n| action | string | Yes | `set_state_attributes` \u003cbr/\u003eAllows to set both state and attributes. |\n| entity_id | string | Yes | Entity ID of the sensor to be set. |\n| state | string | Yes | The state to be set. |\n| attributes | list | Yes | List of attributes to be set (the actual list of attributes depends on the referred entity). |\n| log_enabled | bool | No | Indicates whether to log system messages to the Home Assistant log (see [Logging](#logging) for further details). |\n\n#### 1.1. Automation Sample\n\n```yaml\n- alias: paolo_home_since\n  trigger:\n    - platform: state\n      entity_id: device_tracker.paolo\n      from: \"not_home\"\n      to: \"home\"\n  action:\n    - service: python_script.hass_entities\n      data:\n        action: set_state_attributes\n        entity_id: sensor.paolo_home_from\n        state: \"{{ 'At home since '~ now().strftime('%H.%M') }}\"\n        attributes:\n          - icon: mdi:home\n```\n\n#### 1.2. Script Sample\n\n```yaml\nturn_on_switch:\n  sequence:\n    - service: switch.turn_on\n      data:\n        entity_id: switch.plug_1\n    - service: python_script.hass_entities\n      data:\n        action: set_state_attributes\n        entity_id: sensor.plug_1_status\n        state: \"{{ 'Switched on at '~ now().strftime('%H.%M') }}\"\n        attributes:\n          - icon: mdi:toggle-switch\n```\n\n#### 1.3. Lovelace Sample\n\n```yaml\n- type: entities\n  entities:\n    - sensor.mysensor\n    - type: section\n    - type: call-service\n      name: \"Set Windy\"\n      service: python_script.hass_entities\n      service_data:\n        action: set_state_attributes\n        entity_id: sensor.mysensor\n        state: \"3.02\"\n        attributes:\n          - icon: mdi:weather-windy\n          - friendly_name: Windy\n          - unit_of_measurement: m/s\n        log_enabled: True\n    - type: call-service\n      name: \"Set Rainy\"\n      service: python_script.hass_entities\n      service_data:\n        action: set_state_attributes\n        entity_id: sensor.mysensor\n        state: 30\n        attributes:\n          - icon: mdi:weather-rainy\n          - friendly_name: Rainy\n          - unit_of_measurement: mm/h\n        log_enabled: True\n```\n\n![Sample](sample.gif)\n\n### 2. Set state only\n\n| Name | Type | Required | Description |\n| ---- | :--: | :------: | ----------- |\n| action | string | Yes | `set_state` \u003cbr/\u003eAllows to set a sensor state only. |\n| entity_id | string | Yes | Entity ID of the sensor to be set. |\n| state | string | Yes | The state to be set. |\n| log_enabled | bool | No | Indicates whether to log system messages to the Home Assistant log (see [Logging](#logging) for further details). |\n\n#### 2.1. Automation Sample\n\n```yaml\n- alias: paolo_home_since\n  trigger:\n    - platform: state\n      entity_id: device_tracker.paolo\n      from: \"not_home\"\n      to: \"home\"\n  action:\n    - service: python_script.hass_entities\n      data:\n        action: set_state\n        entity_id: sensor.paolo_home_from\n        state: \"{{ 'At home since '~ now().strftime('%H.%M') }}\"\n```\n\n#### 2.2. Script Sample\n\n```yaml\nturn_on_switch:\n  sequence:\n    - service: switch.turn_on\n      data:\n        entity_id: switch.plug_1\n    - service: python_script.hass_entities\n      data:\n        action: set_state\n        entity_id: sensor.plug_1_status\n        state: \"{{ 'Switched on at '~ now().strftime('%H.%M') }}\"\n```\n\n#### 2.3. Lovelace Sample\n\n```yaml\n- type: entities\n  entities:\n    - sensor.mysensor\n    - type: section\n    - type: call-service\n      name: \"Set Windy State\"\n      service: python_script.hass_entities\n      service_data:\n        action: set_state\n        entity_id: sensor.mysensor\n        state: \"3.02\"\n        log_enabled: True\n    - type: call-service\n      name: \"Set Rainy State\"\n      service: python_script.hass_entities\n      service_data:\n        action: set_state\n        entity_id: sensor.mysensor\n        state: 30\n        log_enabled: True\n```\n\n### 3. Set attributes only\n\n| Name | Type | Required | Description |\n| ---- | :--: | :------: | ----------- |\n| action | string | Yes | `set_attributes` \u003cbr/\u003eAllows to set a sensor attributes only. |\n| entity_id | string | Yes | Entity ID of the sensor to be set. |\n| attributes | list | Yes | List of attributes to be set (the actual list of attributes depends on the referred entity). |\n| log_enabled | bool | No | Indicates whether to log system messages to the Home Assistant log (see [Logging](#logging) for further details). |\n\n#### 3.1. Automation Sample\n\n```yaml\n- alias: paolo_home_since\n  trigger:\n    - platform: state\n      entity_id: device_tracker.paolo\n      from: \"not_home\"\n      to: \"home\"\n  action:\n    - service: python_script.hass_entities\n      data:\n        action: set_attributes\n        entity_id: sensor.paolo_home_from\n        attributes:\n          - icon: mdi:home\n          - time: \"{{ now().strftime('%H.%M') }}\"\n```\n\n#### 3.2. Script Sample\n\n```yaml\nturn_on_switch:\n  sequence:\n    - service: switch.turn_on\n      data:\n        entity_id: switch.plug_1\n    - service: python_script.hass_entities\n      data:\n        action: set_attributes\n        entity_id: sensor.plug_1_status\n        attributes:\n          - icon: mdi:toggle-switch\n          - time: \"{{ now().strftime('%H.%M') }}\"\n```\n\n#### 3.3. Lovelace Sample\n\n```yaml\n- type: entities\n  entities:\n    - sensor.mysensor\n    - type: section\n    - type: call-service\n      name: \"Set Windy Icon\"\n      service: python_script.hass_entities\n      service_data:\n        action: set_attributes\n        entity_id: sensor.mysensor\n        attributes:\n          - icon: mdi:weather-windy\n        log_enabled: True\n    - type: call-service\n      name: \"Set Rainy Icon\"\n      service: python_script.hass_entities\n      service_data:\n        action: set_attributes\n        entity_id: sensor.mysensor\n        attributes:\n          - icon: mdi:weather-rainy\n        log_enabled: True\n```\n\n### 4. Delete an existing attribute\n\n| Name | Type | Required | Description |\n| ---- | :--: | :------: | ----------- |\n| action | string | Yes | `delete_attribute` \u003cbr/\u003eDelete an existing attribute. |\n| entity_id | string | Yes | Entity ID of the sensor to be set. |\n| attribute | string | Yes | Attribute to be deleted from the sensor definition. |\n| log_enabled | bool | No | Indicates whether to log system messages to the Home Assistant log (see [Logging](#logging) for further details). |\n\n#### 4.1. Automation Sample\n\n```yaml\n- alias: paolo_not_home\n  trigger:\n    - platform: state\n      entity_id: device_tracker.paolo\n      from: \"home\"\n      to: \"not_home\"\n  action:\n    - service: python_script.hass_entities\n      data:\n        action: delete_attribute\n        entity_id: sensor.paolo_home_from\n        attribute: time\n```\n\n#### 4.2. Script Sample\n\n```yaml\nturn_on_switch:\n  sequence:\n    - service: python_script.hass_entities\n      data:\n        action: delete_attribute\n        entity_id: sensor.plug_1_status\n        attribute: icon\n```\n\n#### 4.3. Lovelace Sample\n\n```yaml\n- type: entities\n  entities:\n    - sensor.mysensor\n    - type: section\n    - type: call-service\n      name: \"Set Windy Icon\"\n      service: python_script.hass_entities\n      service_data:\n        action: delete_attribute\n        entity_id: sensor.mysensor\n        attribute: icon\n        log_enabled: True\n```\n\n## Logging\n\n**Important**: In addition to the `log_enabled` parameter, make sure the [Logger](https://www.home-assistant.io/components/logger) component has been configured in your `configuration.yaml` (log level must be at least `debug`).\n\n```yaml\nlogger:\n  logs:\n    homeassistant.components.python_script: debug\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmazz%2Fps_hassio_entities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmazz%2Fps_hassio_entities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmazz%2Fps_hassio_entities/lists"}