Adding daily counter value to weekly counter helper

I am trying to figure out the way to create a dependent counter. Essentially I use one Counter connected to some automations to grant points to a kiddo for doing her chores. This counter resets every day sending me a notification just before to let me know the total points tally for the day.

Now I want to create a weekly counter which will daily increase to the value of the daily counter just before the daily resets. Right now I am doing it manually through the number helper, but wanted to find a way to automate this flow

Set another input helper to store the weekly value and just add to it? :slight_smile: You can increase the value or set a new one. Something like value_weekly == value_weekly + value_daily

Post your automation for the daily points, so we can see how you handle this and built upon that. :slight_smile:

That’s a thing - not sure how to add to weekly helper automagically.

Below is the current daily automation:

alias: Princess Behavioral Points
description: ""
trigger:
  - platform: time
    at: "21:00:00"
condition: []
action:
  - service: notify.haas
    data:
      message: >-
        STATISTICS --> Princess scored
        {{states('counter.princess_points_counter')}} points today
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: counter.reset
    data: {}
    target:
      entity_id: counter.princess_points_counter
mode: single

I haven’t used counters for this, but it seems a nice little helper. :+1: I’d have done it with a simple input_number helper, but that’s a personal choice and honestly, not sure if counter isn’t the better way. :laughing:

Anyway, just add a new counter (wherever you normally do that UI or YAML), name it like you want, for the example I’ll call it counter.princess_points_weekly. Just for my inner Monk, I’d change the other counter to counter.princess_points_daily. :crazy_face:

And here we go:

alias: Princess Behavioral Points
description: ""
trigger:
  - platform: time
    at: "21:00:00"
condition: []
action:
  - service: counter.set_value
    entity_id: counter.princess_points_weekly
    value: >
      {% set weekly points = states('counter.princess_points_weekly') %}
      {% set weekly_points = weekly_points + states('counter.princess_points_counter') %}
      {{ weekly_points }}
  - service: notify.haas
    data:
      message: >-
        STATISTICS --> Princess scored
        {{states('counter.princess_points_counter')}} points today
        and has already gotten {{ states('counter.princess_points_weekly') }} points this week
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: counter.reset
    data: {}
    target:
      entity_id: counter.princess_points_counter
mode: single

I’m not at home, so couldn’t test it, but should work. You can write this in a one liner as well, it’s just for clarity, so you can see, what we’re doing here. :slight_smile:

What you have to do in a seperate automation is deleting these weekly points (or set it 0) at the end of the week.

Let me know how many errors I hid in this code or if it works as planned :laughing:

so far got this:

Message malformed: extra keys not allowed @ data['action'][0]['value']
Selection deleted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

and in templating something ain’t right either:

TemplateSyntaxError: expected token 'end of statement block', got 'points'

more generally I really got into counters recently not just for a kid, but for myself - to keep the discipline up (specifically cans of coke I consume a day) and monitor some supplies (Dishwasher tablets, Washing Machine pods etc.). they are easily managed from the smart watch, buttons, nfc tags so I am hooked :slight_smile:

I shouldn’t answer questions on my phone, at least not before I paid my optician a visit. Sorry!

But here we go, now at home on my laptop :laughing: Found two typos and two forgotten “defaults”… :grimacing:

alias: Princess Behavioral Points
description: ""
trigger:
  - platform: time
    at: "21:00:00"
condition: []
action:
  - service: counter.set_value
    entity_id: counter.princess_points_weekly
    value: >-
      {%- set weekly_points = states('counter.princess_points_weekly') | int(default=0) %}
      {%- set weekly_points = weekly_points + states('counter.princess_points_counter') | int(default=0) %}
      {{ weekly_points }}
  - service: notify.haas
    data:
      message: >-
        STATISTICS --> Princess scored
        {{states('counter.princess_points_counter')}} points today  
        and has already gotten {{ states('counter.princess_points_weekly') }} points this week
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: counter.reset
    data: {}
    target:
      entity_id: counter.princess_points_counter
mode: single

You might want to try it in the dev tools first…

Seems, I need to read up on counters. :smiley: Makes sense, especially for food and non-food things, that are already tracked in Grocy, but where a counter should come in handy. :+1: Thanks, I’ll def take a look at them.

hmmm… still getting the same error in Automations even though Developer Tools check seems to be fine with it. I have a feeling counter.set_value doesn’t support templates.

ok, after a lengthy dance with it I found the culprit! data was missing from counter.set_value
Thanks for help!

Complete code below:

alias: Princess Behavioral Points (Notify)
description: ""
trigger:
  - platform: time
    at: "21:00:00"
condition: []
action:
  - service: counter.set_value
    entity_id: counter.princess_points_weekly
    data:
      value: >-
        {%- set weekly_points = states('counter.princess_points_weekly') |
        int(default=0) %} {%- set weekly_points = weekly_points +
        states('counter.princess_points_counter') | int(default=0) %} {{
        weekly_points }}
  - service: counter.set_value
    entity_id: counter.princess_points_monthly
    data:
      value: >-
        {%- set monthly_points = states('counter.princess_points_monthly') |
        int(default=0) %} {%- set monthly_points = monthly_points +
        states('counter.princess_points_counter') | int(default=0) %} {{
        monthly_points }}
  - service: notify.haaswb
    data:
      message: >-
        STATISTICS --> Princess scored
        {{states('counter.princess_points_counter')}} points today and has
        already gotten {{ states('counter.princess_points_weekly') }} points
        this week. Monthly score stands at {{ states('counter.princess_points_monthly') }}
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: counter.reset
    data: {}
    target:
      entity_id: counter.princess_points_counter
  - if:
      - condition: time
        weekday:
          - sun
    then:
      - service: counter.reset
        data: {}
        target:
          entity_id: counter.princess_points_weekly
mode: single