{"id":13585943,"url":"https://github.com/enkama/hass-variables","last_synced_at":"2025-04-07T10:32:12.341Z","repository":{"id":37567829,"uuid":"307678069","full_name":"enkama/hass-variables","owner":"enkama","description":"Home Assistant variables component","archived":false,"fork":true,"pushed_at":"2024-04-28T14:18:12.000Z","size":357,"stargazers_count":79,"open_issues_count":3,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-28T15:29:25.693Z","etag":null,"topics":["counter","homeassistant-integration","keypad","last-motion","python","sensor","timer","variables"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"rogro82/hass-variables","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/enkama.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-10-27T11:28:10.000Z","updated_at":"2024-04-28T14:18:16.000Z","dependencies_parsed_at":"2023-10-12T01:10:25.089Z","dependency_job_id":null,"html_url":"https://github.com/enkama/hass-variables","commit_stats":null,"previous_names":["enkama/hass-variables"],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enkama%2Fhass-variables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enkama%2Fhass-variables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enkama%2Fhass-variables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enkama%2Fhass-variables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enkama","download_url":"https://codeload.github.com/enkama/hass-variables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247637040,"owners_count":20971051,"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":["counter","homeassistant-integration","keypad","last-motion","python","sensor","timer","variables"],"created_at":"2024-08-01T15:05:14.207Z","updated_at":"2025-04-07T10:32:12.101Z","avatar_url":"https://github.com/enkama.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Variables+History\n### aka. `variable`\n\n  \u003cimg alt=\"Variable Logo\" src=\"https://github.com/enkama/hass-variables/raw/master/logo/icon.png\"\u003e\n\nA Home Assistant Integration to declare and set/update variables.\n\nForked and updated from initial integration developed by [rogro82](https://github.com/rogro82)\n\n# Home Assistant versions starting with v2024.7.2 will prevent Variables+History versions earlier than v3.4.5 from working. Be sure to upgrade.\n\n## Upgrading from v2 to v3\n**Existing variables will remain as yaml variables but instead of starting with `variable.`, they will now start with `sensor.` If you would like to manage the variable using the UI configuration, you will need to delete the entity from your yaml and recreate it in the UI. This is also the only change needed when migrating from rogro82's version to this one**\n\n## Installation\n\n### HACS *(recommended)*\n1. Ensure that [HACS](https://hacs.xyz/) is installed\n2. [Click Here](https://my.home-assistant.io/redirect/hacs_repository/?owner=enkama\u0026repository=hass-variables) to directly open `Variables+History` in HACS **or**\u003cbr/\u003e\n  a. Navigate to HACS\u003cbr/\u003e\n  b. Click `+ Explore \u0026 Download Repositories`\u003cbr/\u003e\n  c. Find the `Variables+History` integration \u003cbr/\u003e\n3. Click `Download`\n4. Restart Home Assistant\n5. See [Configuration](#configuration) below\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch3\u003eManual\u003c/h3\u003e\u003c/summary\u003e\n\nYou probably **do not** want to do this! Use the HACS method above unless you know what you are doing and have a good reason as to why you are installing manually\n\n1. Using the tool of choice open the directory (folder) for your HA configuration (where you find `configuration.yaml`)\n2. If you do not have a `custom_components` directory there, you need to create it\n3. In the `custom_components` directory create a new folder called `variable`\n4. Download _all_ the files from the `custom_components/variable/` directory in this repository\n5. Place the files you downloaded in the new directory you created\n6. Restart Home Assistant\n7. See [Configuration](#configuration) below\n\u003c/details\u003e\n\n## \u003ca name=\"configuration\"\u003e\u003c/a\u003ePreferred Configuration\n1. [Click Here](https://my.home-assistant.io/redirect/config_flow_start/?domain=variable) to directly add a `Variables+History` sensor **or**\u003cbr/\u003e\n  a. In Home Assistant, go to Settings -\u003e [Integrations](https://my.home-assistant.io/redirect/integrations/)\u003cbr/\u003e\n  b. Click `+ Add Integrations` and select `Variables+History`\u003cbr/\u003e\n2. Add your configuration ([see Configuration Options below](#configuration-options))\n3. Click `Submit`\n* Repeat as needed to create additional `Variables+History` sensors\n* Options can be changed for existing `Variables+History` sensors in Home Assistant Integrations by selecting `Configure` under the desired `Variables+History` sensor.\n\n## Configuration Options\n\n### First choose the `variable` type.\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch3\u003eSensor\u003c/h3\u003e\u003c/summary\u003e\n\n| Name                    | Required | Default        | Description                                                                                                                     |\n|-------------------------|----------|----------------|---------------------------------------------------------------------------------------------------------------------------------|\n| `Variable ID`           | `Yes`    |                | The desired id of the new sensor (ex. `test_variable` would create an entity_id of `sensor.test_variable`)                      |\n| `Name`                  | `No`     |                | Friendly name of the variable sensor                                                                                            |\n| `Icon`                  | `No`     | `mdi:variable` | Icon of the Variable                                                                                                            |\n| `Initial Value`         | `No`     |                | Initial value/state of the variable. If `Restore on Restart` is `False`, the variable will reset to this value on every restart |\n| `Initial Attributes`    | `No`     |                | Initial attributes of the variable. If `Restore on Restart` is `False`, the variable will reset to this value on every restart  |\n| `Restore on Restart`    | `No`     | `True`         | If `True` will restore previous value on restart. If `False`, will reset to `Initial Value` and `Initial Attributes` on restart |\n| `Force Update`          | `No`     | `False`        | Variable's `last_updated` time will change with any service calls to update the variable even if the value does not change      |\n| `Exclude from Recorder` | `No`     | `False`        | For Variables with large attributes (\u003e16 kB), enable this to prevent Recorder Errors.                                           |\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch3\u003eBinary Sensor\u003c/h3\u003e\u003c/summary\u003e\n\n| Name                    | Required | Default        | Description                                                                                                                                    |\n|-------------------------|----------|----------------|------------------------------------------------------------------------------------------------------------------------------------------------|\n| `Variable ID`           | `Yes`    |                | The desired id of the new binary sensor (ex. `test_variable` would create an entity_id of `binary_sensor.test_variable`)                       |\n| `Name`                  | `No`     |                | Friendly name of the variable binary sensor                                                                                                    |\n| `Icon`                  | `No`     | `mdi:variable` | Icon of the Variable                                                                                                                           |\n| `Initial Value`         | `No`     | `False`        | Initial `True`/`False` value/state of the variable. If `Restore on Restart` is `False`, the variable will reset to this value on every restart |\n| `Initial Attributes`    | `No`     |                | Initial attributes of the variable. If `Restore on Restart` is `False`, the variable will reset to this value on every restart                 |\n| `Restore on Restart`    | `No`     | `True`         | If `True` will restore previous value on restart. If `False`, will reset to `Initial Value` and `Initial Attributes` on restart                |\n| `Force Update`          | `No`     | `False`        | Variable's `last_updated` time will change with any service calls to update the variable even if the value does not change                     |\n| `Exclude from Recorder` | `No`     | `False`        | For Variables with large attributes (\u003e16 kB), enable this to prevent Recorder Errors.                                                          |\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch3\u003eDevice Tracker\u003c/h3\u003e\u003c/summary\u003e\n\n| Name                    | Required | Default        | Description                                                                                                                                                                                                                        |\n|-------------------------|----------|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `Variable ID`           | `Yes`    |                | The desired id of the new device tracker (ex. `test_variable` would create an entity_id of `device_tracker.test_variable`)                                                                                                         |\n| `Name`                  | `No`     |                | Friendly name of the variable device tracker                                                                                                                                                                                       |\n| `Icon`                  | `No`     | `mdi:variable` | Icon of the Variable                                                                                                                                                                                                               |\n| `Initial Latitude`      | `Yes`    |                | Latitude                                                                                                                                                                                                                           |\n| `Initial Longitude`     | `Yes`    |                | Longitude                                                                                                                                                                                                                          |\n| `Initial Location Name` | `No`     |                | If set, will show this as the state                                                                                                                                                                                                |\n| `Initial GPS Accuracy`  | `No`     |                | Accuracy in meters                                                                                                                                                                                                                 |\n| `Initial Battery Level` | `No`     |                | Battery level from 0-100%                                                                                                                                                                                                          |\n| `Initial Attributes`    | `No`     |                | Initial attributes of the variable                                                                                                                                                                                                 |\n| `Restore on Restart`    | `No`     | `True`         | If `True` will restore previous value on restart. If `False`, will reset to `Initial Latitude`, `Initial Longitude`, `Initial Location Name`, `Initial GPS Accuracy`, `Initial Battery Level`, and `Initial Attributes` on restart |\n| `Force Update`          | `No`     | `False`        | Variable's `last_updated` time will change with any service calls to update the variable even if the value does not change                                                                                                         |\n| `Exclude from Recorder` | `No`     | `False`        | For Variables with large attributes (\u003e16 kB), enable this to prevent Recorder Errors.                                                                                                                                              |\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch2\u003eAlternate YAML Configuration\u003c/h2\u003e\u003c/summary\u003e\n\n**Variables created via YAML will all start with `sensor.` and cannot be edited in the UI.**\n\n_You can have a combination of Variables created via the UI and via YAML._\n\nAdd the component `variable` to your configuration and declare the variables you want.\n\n| Name                  | yaml                    | Required | Default | Description                                                                                                                     |\n|-----------------------|-------------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------|\n| Variable ID           | `\u003ckey\u003e:`                | `Yes`    |         | The desired id of the new sensor (ex. `test_variable` would create an entity_id of `sensor.test_variable`)                      |\n| Name                  | `name`                  | `No`     |         | Friendly name of the variable sensor                                                                                            |\n| Initial Value         | `value`                 | `No`     |         | Initial value/state of the variable. If `Restore on Restart` is `False`, the variable will reset to this value on every restart |\n| Initial Attributes    | `attributes`            | `No`     |         | Initial attributes of the variable. If `Restore on Restart` is `False`, the variable will reset to this value on every restart  |\n| Restore on Restart    | `restore`               | `No`     | `True`  | If `True` will restore previous value on restart. If `False`, will reset to `Initial Value` and `Initial Attributes` on restart |\n| Force Update          | `force_update`          | `No`     | `False` | Variable's `last_updated` time will change with any service calls to update the variable even if the value does not change      |\n| Exclude from Recorder | `exclude_from_recorder` | `No`     | `False` | For Variables with large attributes (\u003e16 kB), set to `True` to prevent Recorder Errors.                                         |\n\n#### Example:\n\n```yaml\nvariable:\n  countdown_timer:\n    value: 30\n    attributes:\n      friendly_name: 'Countdown'\n      icon: mdi:alarm\n  countdown_trigger:\n    name: Countdown\n    value: False\n  light_scene:\n    value: 'normal'\n    attributes:\n      previous: ''\n    restore: true\n  current_power_usage:\n    force_update: true\n\n  daily_download:\n    value: 0\n    restore: true\n    attributes:\n      state_class: measurement\n      unit_of_measurement: GB\n      icon: mdi:download\n```\n\n\u003c/details\u003e\n\n## Services\n\nThere are instructions and selectors when the service is called from the Developer Tools or within a Script or Automation.\n\n### `variable.update_sensor`\n\nUsed to update the value or attributes of a Sensor Variable\n\n| Name                 | Key                                     | Required | Default | Description                                                                           |\n|----------------------|-----------------------------------------|----------|---------|---------------------------------------------------------------------------------------|\n| `Targets`            | `target:`\u003cbr /\u003e\u0026nbsp;\u0026nbsp;`entity_id:` | `Yes`    |         | The entity_ids of one or more sensor variables to update (ex. `sensor.test_variable`) |\n| `New Value`          | `value`                                 | `No`     |         | Value/state to change the variable to                                                 |\n| `New Attributes`     | `attributes`                            | `No`     |         | What to update the attributes to                                                      |\n| `Replace Attributes` | `replace_attributes`                    | `No`     | `False` | Replace or merge current attributes (`False` = merge)                                 |\n\n### `variable.update_binary_sensor`\n\nUsed to update the value or attributes of a Binary Sensor Variable\n\n| Name                 | Key                                     | Required | Default | Description                                                                                         |\n|----------------------|-----------------------------------------|----------|---------|-----------------------------------------------------------------------------------------------------|\n| `Targets`            | `target:`\u003cbr /\u003e\u0026nbsp;\u0026nbsp;`entity_id:` | `Yes`    |         | The entity_ids of one or more binary sensor variables to update (ex. `binary_sensor.test_variable`) |\n| `New Value`          | `value`                                 | `No`     |         | Value/state to change the variable to                                                               |\n| `New Attributes`     | `attributes`                            | `No`     |         | What to update the attributes to                                                                    |\n| `Replace Attributes` | `replace_attributes`                    | `No`     | `False` | Replace or merge current attributes (`False` = merge)                                               |\n\n### `variable.update_device_tracker`\n\nUsed to update the value or attributes of a Device Tracker Variable\n\n| Name                   | Key                                     | Required | Default | Description                                                                                           |\n|------------------------|-----------------------------------------|----------|---------|-------------------------------------------------------------------------------------------------------|\n| `Targets`              | `target:`\u003cbr /\u003e\u0026nbsp;\u0026nbsp;`entity_id:` | `Yes`    |         | The entity_ids of one or more device tracker variables to update (ex. `device_tracker.test_variable`) |\n| `Latitude`             | `latitude`                              | `No`     |         | Latitude                                                                                              |\n| `Longitude`            | `longitude`                             | `No`     |         | Longitude                                                                                             |\n| `Location Name`        | `location_name`                         | `No`     |         | If set, will show this as the state                                                                   |\n| `Delete Location Name` | `delete_location_name`                  | `No`     |         | Remove the Location Name so state will be based on Lat/Long (`boolean`)                               |\n| `GPS Accuracy`         | `gps_accuracy`                          | `No`     |         | Accuracy in meters                                                                                    |\n| `Battery Level`        | `battery_level`                         | `No`     |         | Battery level from 0-100%                                                                             |\n\n### `variable.toggle_binary_sensor`\n\nUsed to toggle the state or update attributes of a Binary Sensor Variable. If the binary_sensor state is None, the toggle service will not change the state.\n\n| Name                 | Key                                     | Required | Default | Description                                                                                         |\n|----------------------|-----------------------------------------|----------|---------|-----------------------------------------------------------------------------------------------------|\n| `Targets`            | `target:`\u003cbr /\u003e\u0026nbsp;\u0026nbsp;`entity_id:` | `Yes`    |         | The entity_ids of one or more binary sensor variables to toggle (ex. `binary_sensor.test_variable`) |\n| `New Attributes`     | `attributes`                            | `No`     |         | What to update the attributes to                                                                    |\n| `Replace Attributes` | `replace_attributes`                    | `No`     | `False` | Replace or merge current attributes (`False` = merge)                                               |\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch2\u003eLegacy Services\u003c/h2\u003e\u003c/summary\u003e\n\n#### These will only work for Sensor Variables\n_These services are from the previous version of the integration and are being kept for pre-existing automations and scripts. In general, the new `variable.update_` and `variable.toggle_` services above should be used going forward._\n\nBoth services are similar and used to update the value or attributes of a Sensor Variable. `variable.set_variable` uses just the `variable_id` and `variable.set_entity` uses the full `entity_id`. There are instructions and selectors when the service is called from the Developer Tools or within a Script or Automation.\n\n### `variable.set_variable`\n\n| Name                 | Key                  | Required | Default | Description                                                                                                   |\n|----------------------|----------------------|----------|---------|---------------------------------------------------------------------------------------------------------------|\n| `Variable ID`        | `variable`           | `Yes`    |         | The id of the sensor variable to update (ex. `test_variable` for a sensor variable of `sensor.test_variable`) |\n| `Value`              | `value`              | `No`     |         | Value/state to change the variable to                                                                         |\n| `Attributes`         | `attributes`         | `No`     |         | What to update the attributes to                                                                              |\n| `Replace Attributes` | `replace_attributes` | `No`     | `False` | Replace or merge current attributes (`False` = merge)                                                         |\n\n### `variable.set_entity`\n\n| Name                 | Key                  | Required | Default | Description                                                                 |\n|----------------------|----------------------|----------|---------|-----------------------------------------------------------------------------|\n| `Entity ID`          | `entity`             | `Yes`    |         | The entity_id of the sensor variable to update (ex. `sensor.test_variable`) |\n| `Value`              | `value`              | `No`     |         | Value/state to change the variable to                                       |\n| `Attributes`         | `attributes`         | `No`     |         | What to update the attributes to                                            |\n| `Replace Attributes` | `replace_attributes` | `No`     | `False` | Replace or merge current attributes (`False` = merge)                       |\n\n\u003c/details\u003e\n\n## Example service calls\n\n```yaml\naction:\n  - service: variable.update_sensor\n    data:\n      value: 30\n    target:\n      entity_id: sensor.test_timer\n```\n```yaml\naction:\n  - service: variable.update_sensor\n    data:\n      value: \u003e-\n        {{trigger.to_state.name|replace('Motion Sensor','')}}\n      attributes:\n        history_1: \"{{states('sensor.last_motion')}}\"\n        history_2: \"{{state_attr('sensor.last_motion','history_1')}}\"\n        history_3: \"{{state_attr('sensor.last_motion','history_2')}}\"\n    target:\n      entity_id: sensor.last_motion\n```\n```yaml\naction:\n  - service: variable.update_binary_sensor\n    data:\n      value: true\n      replace_attributes: true\n      attributes:\n        country: USA\n    target:\n      entity_id: binary_sensor.test_binary_var\n```\n\n## Example timer automation\n\n* Create a sensor variable with the Variable ID of `test_timer` and Initial Value of `0`\n\n```yaml\nscript:\n  schedule_test_timer:\n    sequence:\n      - service: variable.update_sensor\n        data:\n          value: 30\n        target:\n          entity_id: sensor.test_timer\n      - service: automation.turn_on\n        data:\n          entity_id: automation.test_timer_countdown\n\nautomation:\n  - alias: test_timer_countdown\n    initial_state: 'off'\n    trigger:\n      - platform: time_pattern\n        seconds: '/1'\n    action:\n      - service: variable.update_sensor\n        data:\n          value: \u003e\n            {{ [((states('sensor.test_timer') | int(default=0)) - 1), 0] | max }}\n        target:\n          entity_id: sensor.test_timer\n  - alias: test_timer_trigger\n    trigger:\n      platform: state\n      entity_id: sensor.test_timer\n      to: '0'\n    action:\n      - service: automation.turn_off\n        data:\n          entity_id: automation.test_timer_countdown\n```\n\n## Examples\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch3\u003ePlay and Save TTS Messages + Message History - Made by \u003ca href=\"https://github.com/jazzyisj\"\u003ejazzyisj\u003c/a\u003e\u003c/h3\u003e\u003c/summary\u003e\n\n#### https://github.com/jazzyisj/save-tts-messages\n\nThis is more or less an answering machine (remember those?) for your TTS messages. When you play a TTS message that you want saved under certain conditions (i.e. nobody is home), you will call the script Play or Save TTS Message script.play_or_save_message instead of calling your tts service (or Alexa notify) directly. The script will decide whether to play the message immediately, or save it based on the conditions you specify. If a saved tts message is repeated another message is not saved, only the timestamp is updated to the most recent instance.\n\nMessages are played back using the Play Saved TTS Messages script \"script.play_saved_tts_messages\". Set an appropriate trigger (for example when you arrive home) in the automation Play Saved Messages automation.play_saved_messages automation to call this script automatically.\n\nSaved messages will survive restarts.\n\nBONUS - OPTIONAL TTS MESSAGE HISTORY\n\nYou can find the full documentation on how to do this and adjust this to your needs in [here](https://github.com/enkama/hass-variables/tree/master/examples/save-tts-message/tts.md).\n\u003c/details\u003e\n\n#### More examples can be found in the [examples](https://github.com/enkama/hass-variables/tree/master/examples) folder.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenkama%2Fhass-variables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenkama%2Fhass-variables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenkama%2Fhass-variables/lists"}