This gives one of three possible numerical values, 0 for stopped, 1 for paused and 2 for playing. Can somebody please tell me how I can get those as human readable values instead of the numbers?
Thanks for answering! I have probably made a mistake, but neither version did work. The sensor value was empty. I tried both this:
- name: "JRMC-avspillingsstatus"
unique_id: jrmc_avspillingsstatus
value_template: >
{% set ix = (value_json['Response']['Item']|selectattr('@Name','==','State')|first)['#text'] %} {{ ['Stopped','Paused','Playing'][ix] }}
And this:
- name: "JRMC-avspillingsstatus"
unique_id: jrmc_avspillingsstatus
value_template: >
{% set ix = (value_json['Response']['Item']|selectattr('@Name','==','State')|first)['#text'] %}
{{ ['Stopped','Paused','Playing'][ix] }}
Edit: The versions above are the correct version of the sensor name in Norwegian, I translated “avspillingsstatus” to “playback state” to make it clearer what it was. But I don’t think that should matter, right?
ix is just used to collect the value from the array with strings, it must be a number though so 0 and not ‘0’ and I cannot replicate your rest sensor so not sure
Right, I would assume that the problem is that the zero comes as string instead of an integer because of the track name and artist name being the same format. I know how to change string to integer in Python, but is it possible in this YAML string?
Edit: Sorry, I did’t see your message! Just a sec, I’l test it.
Yes, I saw that. I just don’t know where to put it. As I wrote in the previous post I tried to put it before ‘State’, but that gave an error. Sorry if I’m dense.