With the RESTful integration, I am pulling all subscriptions from my money software as a list into an attribute of an entity. The order in which the subscriptions are in the list is unknown but each list element contains an ID attribute. Example below.
What I would like to do is create (template-) sensors for some entries in that list, based on the ID attribute, e.g. sensor.money_subscription_ocs for ID 46.
I would recommend the command_line with curl approach, this allows to pipe the feedback through templates like above. Alternatively you can pipe it through JQ to do the select and pre-format the output too (a bit complex unless you are familiar)
- name: "firefly_iii_bill_rent"
unique_id: "firefly_iii_bill_rent"
device_class: "problem"
state: >-
{% set data = state_attr("sensor.firefly_iii_bills","data") | selectattr("id", "eq", "4") | list %}
{{ "off" if data[0]["attributes"]["paid_dates"][0] is defined else "on"}}
attributes:
paid: >-
{% set data = state_attr("sensor.firefly_iii_bills","data") | selectattr("id", "eq", "4") | list %}
{{ data[0]["attributes"]["paid_dates"][0]["date"] if data[0]["attributes"]["paid_dates"][0] is defined else none }}
Well. it is A solution for you so that is good … but it does not address your initial question by itself. For completeness you should add above on how you resolved this as the final answer is not resttul-only.
Using command_line + curl and jq you can put all in one entity, now you need more
Actually, it does . The question was how do I create (template-) sensors from the list which resides in the RESTful sensor attribute. I do use that RESTful sensor. The other issue is that if I do CLI/curl for every subscription, that would be much more traffic on the finance software. The way it is now, the RESTfull sensor makes one API call, pulls the list and that data is used to populate also the binary sensors for the subscriptions.
The OP has a fine solution. How is relying on an external command better? You can use the template in a restful sensor just as well. Your assumption that this requires anything extra is wrong. As is the assumption that needing anything extra is bad. IMHO relying on curl is a huge unneccesary waste of resources and the chances of it breaking at some point are bigger.
Yeah…sorry, I over-interpreted it. Just as additional info (which you may not care at all ) … With a curl output through JQ you can create a single json selecting only those attributes you want and then use the command_line json_attributes to put it in the single entity.
It would have neen nice that restul had the option to template things as well, guess there are good reasons for not having it
?? I just responded…this is new to me … can one use templates in the restful integration? The doc does not show this
Added, not sure why curl is bad vs rest(ful), do detail …
Yep, sorry, I didn’t see the response while typing. My bad. An example using templates is at the bottom of the docs of the Restful integration. Plus, the state is provided by a value_template so it should be obvious?