So my goal is to pass a local to do list from home assistant to esphome so I can display it. I’ve tried using a template as a sensor but I’ve failed passing the info. My plan was to create four items/sensors based on the first four on my Todo list.
Nice task you got yourself here.
Haven’t done such a thing myself, but I’d go at it this way:
- Setup a trigger-based template sensor
This sensor needs to have anaction
, where you call the servicetodo.get_items
. If you call that service, it will give you back a response variable. This variable can than be used in the state of that template sensor. In this case, I’d use it to populate the items from the todo list as attributes for that sensor. - In ESPHome you can use a “Home Assistant Text Sensor” and get the attributes from it, aka. the items on the todo list.
- Display it
As I said, this is of the top of my head, not tested!
Hope this helps to get you started.
I tried this without success:
template:
- trigger:
- platform: state
entity_id: todo.google_keep_things_to_do_today
- platform: event
event_type: event_template_reloaded
action:
- service: todo.get_items
data:
status: needs_action
target:
entity_id: todo.google_keep_things_to_do_today
response_variable: todo_list_list
sensor:
- name: to do listed
unique_id: todo_list_list
# Add the missing "state" key and define the desired state
state: > # Use Jinja2 templating for dynamic state
{{ todo_list_list[todo.google_keep_things_to_do_today]['items'] | map(attribute='summary') | list | count > 0 }}
'''
Please format your code properly, we can’t see, if there are errors in it, without proper formatting.
See here:
Thanks!
Added correct format
Thanks!
Something like that, but I’d safe the items as attributes. State has the disadvantage, that it is limited to 255 characters.
Like so:
template:
- trigger:
- platform: state
entity_id: todo.google_keep_things_to_do_today
action:
- service: todo.get_items
data:
status: needs_action
target:
entity_id: todo.google_keep_things_to_do_today
response_variable: todo_list_list
sensor:
- name: to_do_listed
unique_id: todo_list_list
state: >-
# this is the number of items/entries on the to-do list
{{ states('todo.google_keep_things_to_do_today') }}
attributes:
items: >-
{% for item in todo_list_list['todo.google_keep_things_to_do_today']['items'] %}
{{ item }}
{% endfor %}
This saves each of the items (all of them!) as one list entry in the attributes from the template sensor.
You can get these attributes in ESPHome in the text sensor
text_sensor:
- platform: homeassistant
id: todo_list
entity_id: sensor.to_do_listed
attribute: items
I have been trying to assign each to do list item as a separate attribute, but I am failling. Any ideas on how to fix it?
- trigger:
- platform: state
entity_id: todo.google_keep_things_to_do_today
- platform: event
event_type: event_template_reloaded
action:
- service: todo.get_items
data:
status: needs_action
target:
entity_id: todo.google_keep_things_to_do_today
response_variable: todo_list_list
sensor:
- name: to_do_listed
unique_id: todo_listed
state: "{{ now().isoformat() }}"
attributes:,
{% for i in range(todo_list_list['todo.google_keep_things_to_do_today']['items'] | length) %}
{{ i }}_summary: "{{ todo_list_list['todo.google_keep_things_to_do_today']['items'][i].summary }}"
{% endfor %}
Any ideas with this? I am able to pass all items on the list to one attribute but not separate them.
I’d say that’s not possible, at least I don’t know a way. You can’t template the key (name) of an attribute, just the value.
But the question is, why? You can loop through the attribute in ESPHome.