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

Raise an event when battery replaced #2247

Closed
3 tasks done
andrew-codechimp opened this issue Oct 19, 2024 · 6 comments · Fixed by #2273
Closed
3 tasks done

Raise an event when battery replaced #2247

andrew-codechimp opened this issue Oct 19, 2024 · 6 comments · Fixed by #2273
Assignees
Labels
enhancement New feature or request

Comments

@andrew-codechimp
Copy link
Owner

andrew-codechimp commented Oct 19, 2024

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

I want to know when I use a battery.

Describe the solution you'd like

When the battery replaced button or action are called raise an event with details of the device/battery so that it can be used for shopping lists etc.

Describe alternatives you've considered

None

Additional context

None

@andrew-codechimp andrew-codechimp added the enhancement New feature or request label Oct 19, 2024
@andrew-codechimp andrew-codechimp self-assigned this Oct 20, 2024
@FragMenthor
Copy link

Thank you for considering this 🙏

@andrew-codechimp
Copy link
Owner Author

It's coming soon, just a bit of testing to do.

@andrew-codechimp andrew-codechimp linked a pull request Oct 27, 2024 that will close this issue
@FragMenthor
Copy link

Thank you! Already on your beta, tested and IT WORKS exactly as I intended! 😀 Thanks!!!

@FragMenthor
Copy link

FragMenthor commented Oct 27, 2024

Here is my personal automation:

alias: "Pilhas: Atualizar stock"
description: Atualizar stock de pilhas ao serem usadas
triggers:
  - event_type: battery_notes_battery_replaced
    trigger: event
conditions: []
actions:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.battery_type == 'CR2450' }}"
        sequence:
          - action: input_number.decrement
            metadata: {}
            data:
              amount: |
                {{ trigger.event.data.battery_quantity | int }}
            target:
              entity_id: input_number.pilhas_cr2450_stock
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.battery_type == 'CR2430' }}"
        sequence:
          - action: input_number.decrement
            metadata: {}
            data:
              amount: |
                {{ trigger.event.data.battery_quantity | int }}
            target:
              entity_id: input_number.pilhas_cr2430_stock
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.battery_type == 'CR2032' }}"
        sequence:
          - action: input_number.decrement
            metadata: {}
            data:
              amount: |
                {{ trigger.event.data.battery_quantity | int }}
            target:
              entity_id: input_number.pilhas_cr2032_stock
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.battery_type == 'AA' }}"
        sequence:
          - action: input_number.decrement
            metadata: {}
            data:
              amount: |
                {{ trigger.event.data.battery_quantity | int }}
            target:
              entity_id: input_number.pilhas_aa_stock
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.battery_type == 'AAA' }}"
        sequence:
          - action: input_number.decrement
            metadata: {}
            data:
              amount: |
                {{ trigger.event.data.battery_quantity | int }}
            target:
              entity_id: input_number.pilhas_aaa_stock
mode: queued
max: 5

Did this on phone, can be much improved, but works! 😊

@andrew-codechimp
Copy link
Owner Author

You were very keen to get this then 😄
Glad it's working and thanks for testing, I'll keep this in beta for a week or so but fingers crossed no issues.

@FragMenthor
Copy link

FragMenthor commented Oct 27, 2024

You were very keen to get this then 😄 Glad it's working and thanks for testing, I'll keep this in beta for a week or so but fingers crossed no issues.

I think this will work best, in my case:

alias: "Pilhas: Atualizar stock"
description: Atualizar stock de pilhas ao serem usadas
triggers:
  - event_type: battery_notes_battery_replaced
    trigger: event
conditions: []
actions:
  - action: input_number.decrement
    metadata: {}
    data:
      amount: |
        {{ trigger.event.data.battery_quantity | int }}
    target:
      entity_id: |
        input_number.pilhas_{{ trigger.event.data.battery_type | lower }}_stock

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

Successfully merging a pull request may close this issue.

2 participants