{"id":13583814,"url":"https://github.com/SirGoodenough/Availability-Template","last_synced_at":"2025-04-06T21:33:06.395Z","repository":{"id":189625993,"uuid":"680978332","full_name":"SirGoodenough/Availability-Template","owner":"SirGoodenough","description":"Custom Template for checking the availiability of an entity.","archived":false,"fork":false,"pushed_at":"2024-07-03T06:32:00.000Z","size":58,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-06T00:39:28.602Z","etag":null,"topics":["availability","custom-template","home-assistant","jinja2-templates","template"],"latest_commit_sha":null,"homepage":"","language":"Jinja","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SirGoodenough.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"WhatAreWeFixingToday","custom":["https://www.paypal.com/paypalme/SirGoodenough","https://www.buymeacoffee.com/SirGoodenough"]}},"created_at":"2023-08-21T02:01:39.000Z","updated_at":"2024-10-03T19:56:51.000Z","dependencies_parsed_at":"2023-11-14T23:31:48.185Z","dependency_job_id":"ef3c3e98-2c9b-4014-ba3d-bc3f985888ff","html_url":"https://github.com/SirGoodenough/Availability-Template","commit_stats":null,"previous_names":["sirgoodenough/availability-template"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirGoodenough%2FAvailability-Template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirGoodenough%2FAvailability-Template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirGoodenough%2FAvailability-Template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirGoodenough%2FAvailability-Template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SirGoodenough","download_url":"https://codeload.github.com/SirGoodenough/Availability-Template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247556551,"owners_count":20957998,"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":["availability","custom-template","home-assistant","jinja2-templates","template"],"created_at":"2024-08-01T15:03:49.596Z","updated_at":"2025-04-06T21:33:06.121Z","avatar_url":"https://github.com/SirGoodenough.png","language":"Jinja","funding_links":["https://patreon.com/WhatAreWeFixingToday","https://www.paypal.com/paypalme/SirGoodenough","https://www.buymeacoffee.com/SirGoodenough","https://img.buymeacoffee.com/button-api/?text=Buy"],"categories":["Jinja"],"sub_categories":[],"readme":"Custom Template for checking the availability of an entity.\n\n[![hacs_badge](https://img.shields.io/badge/HACS-Default-41BDF5.svg)](https://github.com/custom-components/hacs)\n![Version](https://img.shields.io/github/v/release/SirGoodenough/Availability-Template)\n\n\u003ca href=\"https://www.buymeacoffee.com/SirGoodenough\"\u003e\u003cimg src=\"https://img.buymeacoffee.com/button-api/?text=Buy me a coffee\u0026emoji=\u0026slug=SirGoodenough\u0026button_colour=5F7FFF\u0026font_colour=ffffff\u0026font_family=Poppins\u0026outline_colour=000000\u0026coffee_colour=FFDD00\" width=auto, height=30/\u003e\u003c/a\u003e\n\u003cbase target=\"_blank\"\u003e\n\n# 🧯 Availability-Template\n\nThe main reason for using this template is not because it's complicated, it's because availability is something you will be using over and over when you are dealing with sensors, so being able to repeat the same action over and over is better if there is 1 place in your project that the code exists.\n\nDocumentation for this Custom Template can be found at:\n\n- The Description in the template itself.\n- The github readme: https://github.com/SirGoodenough/Availability-Template/blob/master/README.md.\n- Home Assistant Community Forum: https://community.home-assistant.io/t/availability-template/659955.\n\nThis requires HomeAssistant version 2023.11.0 or greater due to the use of the list test in the code.\n\n# 🔩 Installation\n\nInstall this in HACS or download the `availability_template.jinja` from [this repository](https://github.com/SirGoodenough/Availability-Template) and place the files into your `config\\custom_templates` directory.\n[![Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.](https://my.home-assistant.io/badges/hacs_repository.svg)](https://my.home-assistant.io/redirect/hacs_repository/?owner=SirGoodenough\u0026repository=Availability-Template\u0026category=template)\n\n#### If you cannot see templates in your HACS listing\n\nYou *may* need to enable 'experimental features' mode. To do this find the HACS section of the Home Assistant Integration page. Click on the '\u003e' arrow to bring you to the custom integration page. Then click on configure, and select 'enable experimental features' check box. click submit, then float out and restart the HA server to make sure it takes. When you come back HACS will look slightly different, but the Templates section is now visible and you will be able to select it. At some point in time HACS will update and the new interface and options will be the only available interface.\n\n#### Other help\n\nBefore you report a 'Bug', you need to make sure you have read the accompanying Descriptions on the templates and this README and have followed all the settings required here.\nThis is important because if these instructions are not followed, you will likely have a bad day and be forced to contact me for help.  Not that I don't want to help, but personal interaction takes me a while to respond and is generally non-productive.\n\nAnother good thing to do before you ask for help is try testing what you have in the Developer Tools Template Tab in Home Assistant. There you can adjust this and that until you figure out the answer to your question yourself.  [![Open your Home Assistant instance and show your template developer tools.](https://my.home-assistant.io/badges/developer_template.svg)](https://my.home-assistant.io/redirect/developer_template/)\n\n*********************\n\n# Availability Test\n\n## `avail([entity1, entity2, /])`\n\nThis expects a list of entities.\n\n- The number of entities are counted.\n- The number of entities that are NOT unknown, unavailable, empty, or none are counted.\n- If the 2 counts are the same, true is returned, else false, defaults to false.\n\n### REMEMBER!!\n\n\u003e This always returns text, so cast to bool on the other end to be certain of the result.\n\u003e\n\u003e Use of the - character in the return template ensures no unwanted spacing is pulled back with your answer.\n\n### Examples\n\nGenerically, this can be dropped into many templates to be sure the result will render properly.\n\n```jinja\navailability: \u003e-\n    {% from 'availability_template.jinja' import avail %}\n    {{- avail(['entity_1','entity_2']) | bool -}}\n```\n\nHere is a full example that uses this.  It will give you percent sunshine estimate based on data from sun angle and cloud coverage if you have those integrations in your config. (Found the state statement somewhere a while ago, sorry there is no attribution. I use it in my personal config.)\n\n```yaml\n- template:\n  - sensor:\n    - name: \"sunlight_pct\"\n      unique_id: 9a7586c0-0947-4b41-97e0-c0d2150bd0bb\n      unit_of_measurement: \"%\"\n      state: \u003e-\n        {%- set elevation = state_attr('sun.sun','elevation') | float %}\n        {%- set cloud_coverage = states('sensor.openweathermap_cloud_coverage') | float %}\n        {%- set cloud_factor = (1 - (0.75 * ( cloud_coverage / 100) ** 3 )) %}\n        {%- set min_elevation = -6 %}\n        {%- set max_elevation = 60 %}\n        {%- set adjusted_elevation = elevation - min_elevation %}\n        {%- set adjusted_elevation = [adjusted_elevation,0] | max %}\n        {%- set adjusted_elevation = [adjusted_elevation,max_elevation - min_elevation] | min %}\n        {%- set adjusted_elevation = adjusted_elevation / (max_elevation - min_elevation) %}\n        {%- set adjusted_elevation = adjusted_elevation %}\n        {%- set adjusted_elevation = adjusted_elevation * 100 %}\n        {%- set brightness = adjusted_elevation * cloud_factor %}\n        {{ brightness | round }}\n      availability: \u003e-\n        {% from 'availability_template.jinja' import avail %}\n        {{- avail(['sun.sun','sensor.openweathermap_cloud_coverage']) | bool -}}\n      icon: mdi:sun-angle\n      attributes:\n        friendly_name: \"Sunlight Percentage\"\n\n```\n\n### Other Info\n\nLocation of this code: https://github.com/SirGoodenough/Availability-Template\n\nHome Assistant Community Forum Post: https://community.home-assistant.io/t/availability-template/659955\n\nLet me know if you have a suggestion.\n\nIf you have any questions, comments or additions be sure to add an issue in the above listed github repo and bring them up on my Discord Server:\n\n### 🤹🏾‍♂️ Contact Links or see my other work\n\nWhat are we Fixing Today Homepage / Website: https://www.WhatAreWeFixing.Today/\n\nChannel Link URL: (WhatAreWeFixingToday): https://bit.ly/WhatAreWeFixingTodaysYT\n\nWhat are we Fixing Today Facebook page (Sir GoodEnough): https://bit.ly/WhatAreWeFixingTodaybFB\n\nWhat are we Fixing Today Twitter Account (Sir GoodEnough): https://bit.ly/WhatAreWeFixingTodayTW\n\nDiscord Guild: (Sir_Goodenough#9683): https://discord.gg/Uhmhu3B\n\nBluePrint Library: https://github.com/SirGoodenough/HA_Blueprints/blob/master/README.md\n\n#WhatAreWeFixingToday\n\n#SirGoodEnough\n\n### Disclaimer\n\n⚠️ **DANGER OF ELECTROCUTION** ⚠️\n\nIf your device connects to mains electricity (AC power) there is danger of electrocution if not installed properly. If you don't know how to install it, please call an electrician (***Beware:*** certain countries prohibit installation without a licensed electrician present). Remember: **SAFETY FIRST**. It is not worth the risk to yourself, your family and your home if you don't know exactly what you are doing. Never tinker or try to flash a device using the serial programming interface while it is connected to MAINS ELECTRICITY (AC power).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSirGoodenough%2FAvailability-Template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSirGoodenough%2FAvailability-Template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSirGoodenough%2FAvailability-Template/lists"}