So we have this 255 character limit on sensor states, and all the posts that I can find advise parsing longer sensor output data into attributes. Said posts are related to either JSON or MQTT formatted data, but I’m running an AppleScript that queries Airfoil for connected speakers, and it returns a comma delimited list without any special formatting. This sensor output works but if a fifth speaker connects then it errors out:
«class AFSp» id com.rogueamoeba.group.7191DBCF-1F14-47D5-8CDB-0A951AE966BB, «class AFSp» id 0499B9AEC041@Bedroom, «class AFSp» id 94EA32AF8810@Bath homepod, «class AFSp» id D4A33D6B949B@Near LR HomePod, «class AFSp» id D4A33D6B381A@Far LR HomePod
I can’t figure out how to get this data into an attribute; just one big attribute is fine because my sensors are looking for keys like this:
template:
- binary_sensor:
- name: bedroom_speak
state: '{{ "@Bedroom" in states("sensor.connected_speakers") }}'
Currently I’m hacking up the data like this but it’s not future proof if I add more speakers:
- platform: command_line
name: connected_speakers
command: 'osascript /users/username/.homeassistant/scripts/get_connected_speakers.scpt'
value_template: '{{ value | replace("«class AFSp»", "") | replace("com.rogueamoeba.group.", "") }}'
scan_interval: 5
Do I need to convert the data to JSON first or something?