diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index e64aaf1..a985aa6 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -11,16 +11,16 @@ jobs: runs-on: ubuntu-latest steps: - name: 📥 Check out repository - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4 - name: 🚀 Run YAMLlint - uses: frenck/action-yamllint@v1.4.1 + uses: frenck/action-yamllint@v1 remarklint: name: 🧹 Remark Lint runs-on: ubuntu-latest steps: - name: 📥 Check out repository - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4 - name: 🚀 Run Remark lint uses: "docker://pipelinecomponents/remark-lint:latest" continue-on-error: true diff --git a/README.md b/README.md index 413fe63..2b774ff 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ # Zanix's Home Assistant Blueprints | zanix/home-assistant-blueprints | Home Assistant Community | -| :---: | :---: | -| [![Last Commit][github-last-commit]][github-main] [![Github Linter Status][github-linter-status-shield]][github-linter-status] | [![Home Assistant Community Forum][forum-shield]][forum] | -| [![GitHub Activity][commits-shield]][commits] | [![Discord][discord-shield]][discord] | +| ----- | ----- | +| [![GitHub issues][issues-shield]][issues] [![GitHub pull requests][pull-requests-shield]][pull-requests] [![GitHub forks][forks-shield]][forks] [![GitHub stars][stars-shield]][stars]
[![Linter Status][linter-status-shield]][linter-status] [![Last Commit][last-commit-shield]][last-commit] [![Commits][commits-shield]][commits] | [![Home Assistant Community Forum][forum-shield]][forum]
[![Discord][discord-shield]][discord] ## Current Blueprints @@ -11,12 +10,12 @@ #### Inovelli Blue LED (Zigbee2MQTT) -Set LED effects for Inovelli VZM31-SN Blue Series 2-1 Switches +Set LED effects for Inovelli Blue Series 2-1 Switches (VZM31-SN, VZM35-SN) [Forum](https://community.home-assistant.io/t/z2m-inovelli-blue-series-switch-led-notification-script-vzm31-sn-vzm35-sn/489620) | [YAML](https://github.com/zanix/home-assistant-blueprints/blob/main/script/inovelli_blue_led_zigbee2mqtt.yaml) -[![Import Blueprint][blueprint-import]](https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url=https%3A%2F%2Fgithub.com%2Fzanix%2Fhome-assistant-blueprints%2Fblob%2Fmain%2Fscript%2Finovelli_blue_led_zigbee2mqtt.yaml) +[![Import Blueprint][blueprint-import-button]](https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url=https%3A%2F%2Fgithub.com%2Fzanix%2Fhome-assistant-blueprints%2Fblob%2Fmain%2Fscript%2Finovelli_blue_led_zigbee2mqtt.yaml) ## Thanks @@ -29,19 +28,31 @@ Set LED effects for Inovelli VZM31-SN Blue Series 2-1 Switches **All files are edited with [Visual Studio Code](https://code.visualstudio.com).** -[github-linter-status-shield]: https://img.shields.io/github/actions/workflow/status/zanix/home-assistant-blueprints/linters.yaml?branch=main&style=flat-square&label=linters&logo=github-actions&logoColor=838B95 -[github-linter-status]: https://github.com/zanix/home-assistant-blueprints/actions/workflows/linters.yaml +[issues]: https://github.com/zanix/home-assistant-blueprints/issues +[issues-shield]: https://img.shields.io/github/issues/zanix/home-assistant-blueprints?style=flat-square -[github-last-commit]: https://img.shields.io/github/last-commit/zanix/home-assistant-blueprints/main?style=flat-square&logo=github&logoColor=838B95 -[github-main]: https://github.com/zanix/home-assistant-blueprints/commits/main +[pull-requests]: https://github.com/zanix/home-assistant-blueprints/pulls +[pull-requests-shield]: https://img.shields.io/github/issues-pr/zanix/home-assistant-blueprints?style=flat-square + +[forks]: https://github.com/zanix/home-assistant-blueprints/network +[forks-shield]: https://img.shields.io/github/forks/zanix/home-assistant-blueprints?style=flat-square + +[stars]: https://github.com/zanix/home-assistant-blueprints/stargazers +[stars-shield]: https://img.shields.io/github/stars/zanix/home-assistant-blueprints?style=flat-square + +[linter-status]: https://github.com/zanix/home-assistant-blueprints/actions/workflows/linters.yaml +[linter-status-shield]: https://img.shields.io/github/actions/workflow/status/zanix/home-assistant-blueprints/linters.yaml?branch=main&style=flat-square&label=linters&logo=github-actions&logoColor=838B95 + +[last-commit]: https://github.com/zanix/home-assistant-blueprints/commits/main +[last-commit-shield]: https://img.shields.io/github/last-commit/zanix/home-assistant-blueprints/main?style=flat-square&logo=github&logoColor=838B95 -[commits-shield]: https://img.shields.io/github/commit-activity/m/zanix/home-assistant-blueprints/main?style=flat-square&logo=github&logoColor=838B95 [commits]: https://github.com/zanix/home-assistant-blueprints/commits/main +[commits-shield]: https://img.shields.io/github/commit-activity/m/zanix/home-assistant-blueprints/main?style=flat-square&logo=github&logoColor=838B95 -[forum-shield]: https://img.shields.io/discourse/topics?style=flat-square&label=community&logo=discourse&color=46B4ED&logoColor=46B4ED&server=https%3A%2F%2Fcommunity.home-assistant.io [forum]: https://community.home-assistant.io +[forum-shield]: https://img.shields.io/discourse/topics?style=flat-square&label=community&logo=discourse&color=46B4ED&logoColor=46B4ED&server=https%3A%2F%2Fcommunity.home-assistant.io -[discord-shield]: https://img.shields.io/discord/330944238910963714?style=flat-square&color=7289da&label=discord&logo=discord [discord]: https://discord.gg/c5DvZ4e +[discord-shield]: https://img.shields.io/discord/330944238910963714?style=flat-square&color=7289da&label=discord&logo=discord -[blueprint-import]: https://my.home-assistant.io/badges/blueprint_import.svg +[blueprint-import-button]: https://my.home-assistant.io/badges/blueprint_import.svg diff --git a/script/inovelli_blue_led_zigbee2mqtt.yaml b/script/inovelli_blue_led_zigbee2mqtt.yaml index a4ab74f..09aec17 100644 --- a/script/inovelli_blue_led_zigbee2mqtt.yaml +++ b/script/inovelli_blue_led_zigbee2mqtt.yaml @@ -3,27 +3,64 @@ blueprint: description: | Set LED effects for Inovelli Blue Series Switches using Zigbee2MQTT. - Features: + ℹ️ Version: 2024.4.0 - - Select one or multiple devices, entities, or areas with Inovelli switches + To update this blueprint, read [Re-importing a blueprint](https://www.home-assistant.io/docs/automation/using_blueprints/#re-importing-a-blueprint) + + ✨ Features: + + - Select one or multiple devices, entities, floors, labels, or areas with Inovelli switches - Selectors for LED Number, Color, Brightness Level, Effect, and Duration - LED Number, Color, Effect, and Duration can accept direct values or the “friendly name” listed in the dropdown - Debug info to diagnose issues - Warning: Debug mode will create a persistent message for every entity called in the script plus 1 - Supported Models: + ✅ Supported Models: - Inovelli 2-in-1 switch + dimmer (VZM31-SN) - Inovelli Fan Controller (VZM35-SN) - Forum: https://community.home-assistant.io/t/z2m-inovelli-blue-series-switch-led-notification-script-vzm31-sn-vzm35-sn/489620 + 💬 Forum: https://community.home-assistant.io/t/z2m-inovelli-blue-series-switch-led-notification-script-vzm31-sn-vzm35-sn/489620 + + 📜 GitHub: https://github.com/zanix/home-assistant-blueprints + + ## Using this Blueprint + + See [Using the Blueprint](https://community.home-assistant.io/t/z2m-inovelli-blue-series-switch-led-notification-script-vzm31-sn-vzm35-sn/489620#using-the-blueprint-13) in the forum topic. + + > The main idea is you set the LED values when you call the script, the inputs below are for default values. - GitHub: https://github.com/zanix/home-assistant-blueprints + ## Default Values + + The fields below are set as defaults for the instance of the script created from this blueprint. - ℹ️ Version: 2023.10.3 domain: script + author: zanixmechanix + homeassistant: + min_version: 2024.4.0 source_url: https://github.com/zanix/home-assistant-blueprints/blob/main/script/inovelli_blue_led_zigbee2mqtt.yaml + input: + command_path_base: + name: Default Command Path Base + description: Set the base path for the MQTT command path. This is `zigbee2mqtt` by default. + default: zigbee2mqtt + selector: + text: + command_path_map: + name: Default Command Path Map + description: | + Map of Entity IDs with a MQTT command path map when HA and Z2M do not match up. + + Enter a new row for each mapping: + + ``` + light.entity_name: "zigbee2mqtt/path/to/device/set" + ``` + default: "" + selector: + object: + fields: target: name: Target @@ -181,12 +218,20 @@ fields: constant: value: true label: Enabled + command_path_base: + name: Command Path Base + description: | + Set the base path for the MQTT command path. This is 'zigbee2mqtt' by default. + This overrides the Blueprint input `command_path_base`. + selector: + text: command_path_map: name: Command Path Map description: | Map of Entity IDs with a MQTT command path map when HA and Z2M do not match up. - Enter a new row for each mapping: light.entity_name: "zigbee2mqtt/path/to/device/set"'. - You can also use a template but you need to use YAML mode to do so. + Enter a new row for each mapping: `light.entity_name: "zigbee2mqtt/path/to/device/set"`. + You can use a template but you need to use YAML mode to do so. + This overrides the Blueprint input `command_path_map`. selector: object: @@ -202,15 +247,53 @@ variables: - VZM31-SN - VZM35-SN - # Create a list of provided targets (areas, devices, entities) + # Create a list of provided targets (floors, areas, labels, devices, entities) target: '{{ target|default([])|map(lower) }}' + floor: '{{ target.floor_id|default([])|lower }}' area: '{{ target.area_id|default([])|lower }}' device: '{{ target.device_id|default([])|lower }}' entity: '{{ target.entity_id|default([])|lower }}' - command_path_map: '{{ command_path_map|default([]) }}' + label: '{{ target.label_id|default([])|lower }}' + + # Get default values set in the blueprint. + input_command_path_base: !input command_path_base + command_path_base: '{{ command_path_base|default(input_command_path_base|default("zigbee2mqtt")) }}' + input_command_path_map: !input command_path_map + command_path_map: '{{ command_path_map|default(input_command_path_map|default([])) }}' + + # Parse target selector for entities entity_list: > {% set switch = namespace(entities=[]) %} + {# Floors #} + {% set floors = namespace(floors=[]) %} + {% if floor %} + {# Convert to a list #} + {% if ',' in floor %} + {% set floornum = floor.split(',') | count %} + {% for i in range(0, floornum) %} + {% set floors.floors = floors.floors + [floor.split(',')[i]|string|trim ] %} + {% endfor %} + {% elif floor[0]|count == 1 %} + {# if the first item in the list has only a single character, it can't be a valid entity #} + {% set floors.floors = floors.floors + [floor|string|trim] %} + {% else %} + {% set floors.floors = floor %} + {% endif %} + {# Detect switches #} + {% for floor in floors.floors %} + {% for area in floor_areas(floor) %} + {% for ent in area_entities(area) %} + {% for model in models %} + {% if model in device_attr(ent, 'model') | default('', true) and ent.split('.')[0] in domains %} + {% set switch.entities = switch.entities + [ent|string|trim] %} + {% endif %} + {% endfor %} + {% endfor %} + {% endfor %} + {% endfor %} + {% endif %} + {# Areas #} {% set areas = namespace(areas=[]) %} {% if area %} @@ -288,6 +371,33 @@ variables: {% endfor %} {% endif %} + {# Labels #} + {% set labels = namespace(labels=[]) %} + {% if label %} + {# Convert to a list #} + {% if ',' in label %} + {% set labelnum = label.split(',') | count %} + {% for i in range(0, labelnum) %} + {% set labels.labels = labels.labels + [label.split(',')[i]|string|trim ] %} + {% endfor %} + {% elif label[0]|count == 1 %} + {# if the first item in the list has only a single character, it can't be a valid entity #} + {% set labels.labels = labels.labels + [label|string|trim] %} + {% else %} + {% set labels.labels = label %} + {% endif %} + {# Detect switches #} + {% for label in labels.labels %} + {% for ent in label_entities(label) %} + {% for model in models %} + {% if model in device_attr(ent, 'model') | default('', true) and ent.split('.')[0] in domains %} + {% set switch.entities = switch.entities + [ent|string|trim] %} + {% endif %} + {% endfor %} + {% endfor %} + {% endfor %} + {% endif %} + {# Output #} {{ switch.entities|unique|list|lower }} @@ -453,6 +563,7 @@ sequence: level: {{ level }} effect: {{ effect }} ({{ effect_value }}) duration: {{ duration }} ({{ duration_value }}) + command_path_base: {{ command_path_base }} command_path_map: {{ command_path_map }} - alias: "Check for an empty entity list" @@ -488,12 +599,15 @@ sequence: for_each: '{{ entity_list }}' sequence: - variables: - # Check for a command_path override. + device_identifier: >- + {% set identifiers = device_attr(repeat.item, "identifiers") | first %} + {{ identifiers[1].split('_')[1] }} + # Check for command_path override. command_path: >- {% if repeat.item in command_path_map %} {{ command_path_map[repeat.item] }} {% else %} - zigbee2mqtt/{{ device_attr(repeat.item, "name") }}/set + {{ command_path_base }}/{{ device_identifier }}/set {% endif %} - alias: "Debug: Send notification" @@ -508,6 +622,7 @@ sequence: message: |- entity: {{ repeat.item }} device name: {{ device_attr(repeat.item, "name") }} + device identifier: {{ device_identifier }} topic: {{ command_path }} payload: {{ payload }}