Counter component help

Hi, I have just setup the counter component. My config is valid and I am not seeing any errors in the setup. The problem I am having is that the item is simply not “counting”

Herewith my counter config:

counter:
  counter:
    name: Finn Meds Today
    icon: mdi:counter

When I go to services in developer tools, and try to fire off an increment, nothing happens…

Herewith the automation I intend to use:

- id: finn_meds_counter
  alias: Finn Meds Counter
  hide_entity: false
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.neo_coolcam_doorwindow_detector_sensor_11_0 
      to: 'on'
  condition:
    condition: or
    conditions:
      - condition: time
        after: '05:30:00'
        before: '06:45:00'
      - condition: time
        after: '11:45:00'
        before: '12:30:00'
      - condition: time
        after: '15:30:00'
        before: '16:30:00'
      - condition: time
        after: '21:30:00'
        before: '22:30:00'
  action:
  - service: service.counter/increment
    entity_id: counter.counter

I’m thinking “Where in the world would this person get the idea that you would use “service.counter/increment” as a service call”. So I’ll just post a link to the documentation and help him out. So much to my surprise, that’s exactly what it says in the documentation.
I have no idea why.

Here’s the real way to call the increment service:

service: counter.increment

I thought that was odd myself, but have to default to rtfm🤗

This still doesnt however explain why it does not fire when i call it from dev tools services in ui… do you have this working?

Thanks for your help…

`Yes, I have a working counter.

- service: counter.increment
  entity_id: counter.count1
1 Like
1 Like

Hi,

This has not resolved my issue, this potentially solved my automation but not the counter functionality itself.

When I go to Developer Tools -> Services and call increment with the following JSON,

{
  "entitiy": "counter.countmeds"
}

nothing happens. I have renamed my Counter to be counter0 now so in config this looks like this:

counter:
  countmeds:
    name: Finn Meds Today
    icon: mdi:counter

and this is the results in my states tab under developer tools

counter.countmeds	0	initial: 0
step: 1
friendly_name: Finn Meds Today
icon: mdi:counter

THis is the entry in my log file:

2017-10-05 09:27:06 ERROR (MainThread) [homeassistant.core] Invalid service data for counter.increment: extra keys not allowed @ data[‘entitiy’]. Got ‘counter.countmeds’

You’re misspelling “entity”, try this:

{
“entity”: “counter.countmeds”
}

OK, good spot, another typo in the documentation… However this has still not resolved the issue…

OK, I got it to fire… If you place anything in the Service data field (marked optional) this does not work. If you leave it blank then it fires…

This is not the expected behaviour based on the documentation.

Please let me know if I can help modify the documentation, otherwise, AFAIK, this seems to be a bug as the service does not operate as described…

So I went ahead and setup a counter and I figured out the reason why it was not working.

It was not calling entity_id, but instead entity.

Here is the proper JSON:

{
“entity_id”: “counter.countmeds”
}

That should work for you. The documentation is incorrect.

Hi All,

Thanks for all your help. End to end solution up and running. Details and code can be found here: Son's Daily Meds Checker

Thanks

not to bump the solved issue, but my working counters stopped counting, hope you can help me solve this:

i have 2 counters, for error and warning logging in the homeassistant.log (or thats what i thought)

counter:
  warning_counter:
    name: Warnings
    icon: mdi:alert
  error_counter:
    name: Errors
    icon: mdi:alert-circle

  - alias: Count warnings
    id: '1511601478028'
    initial_state: 'on'
    trigger:
      platform: event
      event_type: system_log_event
      event_data:
        level: WARNING
    action:
      service: counter.increment
      entity_id: counter.warning_counter

  - alias: Count errors
    id: '1511601478029'
    initial_state: 'on'
    trigger:
      platform: event
      event_type: system_log_event
      event_data:
        level: ERROR
    action:
      service: counter.increment
      entity_id: counter.error_counter

the only remote reason i can think of that happened around the same time these counters stopped counting is me deleting the home-assistant.db file, because it kept growing, wouldn’t be purged no matter what.
So I started using MariaDB again.
The logfile is there of course, and it is still logging errors and warnings. I can see that in the log tail i have also setup.

What could be wrong here?

Thanks for having a look!
Marius

Hi,
Is it possible initialise counter on a automation?

yes, you need a trigger and these would be some options:

  - service_template: '{% if states.counter.mobile_status.state == "5" or states.sensor.phone_battery_jp.state|int >= 10 %} counter.reset {% else %} counter.increment {% endif %}'  
    entity_id: counter.mobile_status

I mean initialise counter with another value than that defined in initial.
Something like this:

- service: counter
  entity_id: counter.mobile_status
  data:
   - initial : {{ states.sensor.phone_battery_jp.state }}

you can set an initial default value