Turning on Boolean Input with a variable entity_id?

I am working on a simple “Pill Minder”. I started with a simple light that gets turned on every morning (that is a reminder to take the pill) using a timer automation. Then a button that is pushed after taking the pill and turns off the light.

Now I want to be fancy and track them over time.

I tried adding toggles, Developer Tools outputs the correct entity_id.

service: input_boolean.turn_on
data:
entity_id: input_boolean.pill_taken_{{["monday","tuesday","wednesday","thursday","friday","saturday","sunday"][now().weekday()]}}

Maybe there is a better way. I am open to suggestions.

Is this the correct approach? Or is there are better way to track this?

could you elaborate what you mean by tracking them over time?

Just for the week. I have an one automation that turns the LED on every morning. The button turns it off. I wanted to make a dashboard to track the progress for the week. Then at the beginning of the week reset all the indicators.

I don’t take any medication, my wife just started and it is a simple prescription that needs to be taken once each morning. I imagine other people might have more elaborate scenarios. Like three times a day, or every other day, and multiple pills.

I thought about hooking it up to google calendar, but for hers it is pretty simple, just one a day.

I beleive there’s no problem, looks like a good solution. One input for every day and at the end of the week an automation that turn them all off… when you click the button light turns off but input remains on, right? I don’t see the problem, it looks fine

This works.

service: input_boolean.turn_on
data: {}
entity_id: input_boolean.pill_taken_thursday

This doesn’t

service: input_boolean.turn_on
data:
entity_id: input_boolean.pill_taken_{{["monday","tuesday","wednesday","thursday","friday","saturday","sunday"][now().weekday()]}}

I get this error…
Message malformed: not a valid value for dictionary value @ data['action'][1]['entity_id']

service: input_boolean.turn_on
data_template:
  entity_id: 'input_boolean.pill_taken_{{["monday","tuesday","wednesday","thursday","friday","saturday","sunday"][now().weekday()]}}'

that should work, you were missing single quotes

Indent the line containing entity_id: by two spaces. You have it vertically aligned with data: and that’s incorrect.


EDIT

Don’t change data to data_template because data_template was deprecated several versions ago. data now performs the same function as data_template.

1 Like

Thank you @obaldius and @123 I can’t believe it was a spacing issue. Thank you! I was misled by the Template area under Developer Tools.

Interesting enough the Automation UI “corrected” the formatting to…

entity_id: >-
  input_boolean.pill_taken_{{["monday","tuesday","wednesday","thursday","friday","saturday","sunday"][now().weekday()]}}