Persisting large text strings (JSON)

Hi there! I’m finally getting into the groove of HA and wanting to migrate over a few of my more complex automations from OpenHAB.

However, hit a road block early on. My TV/photo frame has 2 lists of photos on it, which are accessible as JSON arrays (["photo1", "photo2","etc"])

In OpenHAB, I have those exposed as point sensors. Not ideal for huge blocks of JSON but it works. On Home Assistant, however, there seems to be a character limit for sensor content, and it’s not coming through.

The automations I want to do are

  • Select a random photo from List 1.
  • Select a random photo from List 2.
  • Combine List 1 and List 2, then select a random photo from the new list.

Now the lists don’t actually change much, so I am happy to store them somewhere on Home Assistant as an actual object or whatever and update them manually as needed - so long as those automations are possible to implement.

What would be the best way to go about it?

Yes on states, but not in attributes.
Just make sure the data is in attributes and it will work.

Thanks, that’s good to know :slight_smile: Though no matter where I put the JSON it seems the automation builder doesn’t let you do much with it.

Since to put the values on the attribute would require forking the integration I was using, I decided to go ham and write a map so that it would convert the JSON to a drop down entity, which will be nice if I can get it to work.

The automation builder seems quite limited though - is there one I can write actual code? I want to get all the options from both lists, select a random one and then set that as the active photo.

You are not supposed to use an automation to create entities.
Where is the JSON from? Most likely you could set up a rest sensor to grab the values to attributes of a sensor.

I am not creating entities on the fly, sorry. I’ll try to explain.

The JSON is coming out of the device’s API directly as a list of all photos on it. There are two separate JSON lists for different categories of images.

I am routing it through OpenHAB as there’s no HA integration. I have modified the openHAB to Home Assistant integration so that instead of outputting sensors for the text fields, it detects if they’re JSON and creates a drop down list in Home Assistant for them (I also attach the raw JSON as an attribute)

Another entity is also exposed - which is the currently selected image on the frame. I have that exposed as a text entity - when that changes, the photo displayed on the tv changes.

So what I want is to press a button to set a random photo, which will combine the two lists coming off the TV to get a full list of all photos on it, then select a random one from that aggregated collection and pass that value to the text entity which will trigger the change on the device.

It’s been an absolute pain to work with this TV haha but I’ve had the results working in openHAB for a while now and love it so it would be nice to be able to port all of my automations to one place.

I bet that integration in OpenHAB is just a rest sensor in the back.
Google the TV model and API and you will probably find what you need to integrate it directly with HA.

This is probably verging into a different topic now.

It’s not in a restful format and not an official API, but yeah I can expose it as a rest sensor or whatever else if I want - I now have it successfully in home assistant. The thing I don’t know how to do now is the automations I want and I’m not sure how exposing it as a different sensor allows me to grab random values or combine values.

This grabs a random value.

{{ ["photo1", "photo2","etc"] | random }}