Counter Issue

I am trying to set up a counter to count the number of times i announce that the washer is done so it does not go on for ever.

If i dont put in the initial or step the sate on load is unknown and increment and reset do not work.

counter:
  washer_done_announce_counter:
    name: "Washer Done Announce Counter"

If i do put in the initial or step the counter does not show up in states and i have this error in my logs.

counter:
  washer_done_announce_counter:
    name: "Washer Done Announce Counter"
    initial: 1
    step: 1
2019-08-16 11:40:17 WARNING (MainThread) [homeassistant.setup] Setup of counter is taking over 10 seconds.
2019-08-16 11:40:17 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 400, in _async_add_entity
    await entity.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/counter/__init__.py", line 173, in async_added_to_hass
    self._state = self.compute_next_state(int(state.state))
ValueError: invalid literal for int() with base 10: 'unknown'

Any way to fix this or is there another way to keep a count?

Another way to do it would be using a timer, so a conditional in automation would prevent it to be annouced again until the timer is finished.

Thanks but i have it every hour on the hour. The issue is i only want it to announce up to 4 times then stop.

what it does now is
Announce when the washer is done.
If they dryer turns on then we know its been moved over.
If not then continue to announce every hour on the hour for 3 additional hours.
If the dryer turns on then stop announcing

Alerts support max number of repeats and interval between them:

Still that counter config looks fine. So there may be an issue. I’m off to bed now but if no one else confirms the problem I’ll try making one tomorrow night and see what happens.

I have got what i needed to work by using input_number and using it like a counter.

configuration.yaml

input_number:
  washer_done_announce_counter:
    name: "Washer Done Announce Counter"
    initial: 0
    min: 0
    max: 5
    step: 1
    mode: box

Automation stepping up one

 - service: input_number.set_value
        data_template:
          entity_id: input_number.washer_done_announce_counter
          value: "{{ states('input_number.washer_done_announce_counter')|int + 1}}" 

Trigger when it hits 5 and reset it back to 0 for next time

  - alias: "Washer/Dryer - Reset Washing Machine Ready Switch With Counter"
    trigger:
    - platform: template
      value_template: "{{states('input_number.washer_done_announce_counter')|int == 5}}"
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.washing_machine_needs_to_move_switch
      - service: input_number.set_value
        data_template:
          entity_id: input_number.washer_done_announce_counter
          value: "{{0}}"

hopefully this will help anyone having issues with the built in counters not working.

To actually help we need to check if the counter is broken and raise an issue if it is, so it can be fixed.

It s not working for me.

It would be nice if someone else could confirm though. I’ll make a counter tonight. If I see the same thing I’ll raise an issue.

Nothing wrong with the counter integration:

com-video-to-gif

Counter

test:
  name: "Test"
  initial: 1
  step: 1

Automations:

- id: test_counter_incremant
  alias: 'Test Counter Increament'
  trigger:
  - platform: state
    entity_id: input_boolean.test
  action:
  - service: counter.increment
    entity_id: counter.test

- id: test_counter_reset
  alias: 'Test Counter Reset'
  trigger:
  - platform: state
    entity_id: input_boolean.reset
    to: 'on'
  action:
  - service: counter.reset
    entity_id: counter.test

This is on Hassio 0.97.2

I dont know what to tell you. It throws the error that i show in my original post for me using the same version.

Sorry, that post probably seems a bit dismissive. Yes it works for me but why does it not work for you?

That’s what we have to work out. If you are interested. Or are you happy with your work around?

All good. Im ok with my work around for now. It could be one of the custom components i have installed interfering with it. I have spent to much time on it so far. Thanks for your help though.

1 Like

Counter is broken on my side - I’m on 2020.12.7 hassio
No method worked to increment the counter.
-Directly on the entity
-Service call
-Node Red

Nothing happens.

I think the issue is simply that when you create a counter via the “Helpers” UI, it sets the maximum value to 0. Which makes incrementing it impossible. Probably not an ideal default, since the min and max are optional when you do it via yaml. Doesn’t look like you can set it to undefined, either. Again, probably not ideal.

1 Like