Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example on how to set last seen attribute #223

Open
regevbr opened this issue Mar 14, 2024 · 1 comment
Open

Add example on how to set last seen attribute #223

regevbr opened this issue Mar 14, 2024 · 1 comment

Comments

@regevbr
Copy link
Contributor

regevbr commented Mar 14, 2024

I created the following HA automation to set the last seen attribute on all ZHA devices, similar to how zigbee2mqtt does. Think it will be informative to people as I couldn't find any other solution published anywhere.

@mdeweerd can you please add it to the docs where relevant?

alias: zha last seen attribute
description: set the last seen attribute on all entities of zha end devices
trigger:
  - platform: time_pattern
    seconds: "5"
condition: []
action:
  - service: zha_toolkit.zha_devices
    response_variable: dev_data
    data:
      command_data: last_seen,device_type,entities
  - repeat:
      for_each: "{{ dev_data.devices }}"
      sequence:
        - condition: template
          value_template: "{{ repeat.item.device_type == 'EndDevice' }}"
        - variables:
            last_seen: "{{ repeat.item.last_seen }}"
        - repeat:
            for_each: "{{ repeat.item.entities }}"
            sequence:
              - service: zha_toolkit.ha_set_state
                data:
                  attr_val: "{{ last_seen }}"
                  state_id: "{{ repeat.item.entity_id }}"
                  state_attr: last_seen
mode: single
@mdeweerd mdeweerd changed the title add exmaple on how to set last seen attribute Add example on how to set last seen attribute Mar 14, 2024
@mdeweerd
Copy link
Owner

I'll add it somewhere, probably to scripts - I need to think of a good way to add it to the readme as well (probably just 'Related examples:' in the proper section).

Any example will help, and this example is surely closer to what users expect.

There are examples that are related:
https://github.com/mdeweerd/zha-toolkit/blob/main/examples/script_use_zha_devices_response.yaml
https://github.com/mdeweerd/zha-toolkit/blob/main/examples/script_use_zha_devices.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants