Automation to add custom number to counter based on VoiceAssistant

Hi! So I have a few alexas and a Google puck. I have a counter in HA that keeps track of something. Is there a way to say (example) “Alexa can you add 3 to the pill counter.” “alexa can you add 1 to the pill counter” I have a convoluted setup that uses a smart outlet and a timer but it takes a lot of work to add more so I only have the capabilities for adding 1 and 2. long story short tell alexa a specific number and she adds that number to a counter. Thanks!

I haven’t had much luck getting these kind of things to work directly with Alexa since counters and other number entities are not supported in the integration. It might be possible with an actionable notification but I haven’t bothered trying it.

It is possible to do with HA Assist…

Automation for use with Assist
alias: Add to counter by sentence
description: ""
trigger:
  - platform: conversation
    command: "[can you] add [{number}] to pill counter"
condition: []
action:
  - variable:
      target: counter.EXAMPLE
  - service: counter.set_value
    target:
      entity_id: "{{ target }}"
    data:
      value: |
        {% set x = trigger.slots.number %}
        {%- if x is undefined %} 
          {%- set number = 1 %}
        {%- elif x | is_number %} 
          {%- set number = x %}
        {%- else %}
          {%- from 'numerals.jinja' import to_numeral -%}
          {%- set number = to_numeral(x) %}
        {%- endif %}
        {{ states(target) | int + number | int }}
mode: single

The numerals.jinja custom template macro is available at https://gist.github.com/Didgeridrew/88175322bf8028b43fc3612246fb8416

1 Like

Thanks so much! When i get the time i will give this a try! Thanks again!