Hi All,
I have 209 sensors like this first one. Now try to shorten the rest of them as show below 2.
This is working. Only this I need is to repeat the attributes part, but must replace the ‘KMD’ part with unique codes:
eur_kmd_test:
value_template: "ok"
friendly_name: "KMD"
<<: &CRYPTO_ATTR_TEMPLATE
attribute_templates:
buy: >-
{% set item = state_attr('sensor.bitladon_all', 'result') | selectattr('ticker', 'eq', 'KMD') | first %}
{{ item.buy }}
sell: >
{% set item = state_attr('sensor.bitladon_all', 'result') | selectattr('ticker', 'eq', 'KMD') | first %}
{{ item.sell }}
change24h: >-
{% set item = state_attr('sensor.bitladon_all', 'result') | selectattr('ticker', 'eq', 'KMD') | first %}
{{ item.change24h }}
volume24h: >-
{% set item = state_attr('sensor.bitladon_all', 'result') | selectattr('ticker', 'eq', 'KMD') | first %}
{{ item. volume24h }}
eur_gvt_test:
value_template: "ok"
friendly_name: "GVT"
<<: * CRYPTO_ATTR_TEMPLATE
eur_ftt_test:
value_template: "ok"
friendly_name: "FTT"
<<: * CRYPTO_ATTR_TEMPLATE
Idea is to replace the ‘KMD’ with a code that read the friendly_name of each sensor. So then every sensor will get the right code based on the friendly_name. But I really don’t know how to add this. This was working:
{% set item = state_attr('sensor.bitladon_all', 'result') | selectattr('ticker', 'eq', state_attr('sensor.eur_kmd', 'friendly_name')) | first %}
{{ item.buy }}
Only thing the sensor.eur_kmd is coded hard. That is not the solution.
Cheers,