Custom button card coding

So this, copied from the developer’s github works.

                  [[[
                    return `<ha-icon
                      icon="mdi:clock"
                      style="width: 12px; height: 12px; color: yellow;">
                      </ha-icon><span>${entity.state}</span>`
                  ]]]

However if the entity state returns unavailable I want to return a piece of text not the entity.state.

Is this possible?

Background I am using a button card to report on the progress of an Octoprint 3D print, the above returns the remaining time until finished, but when the print stops the state becomes ‘unavailable’.

I know I could create a new template entity to report what I want to see, but I’d like to learn how, if possible, it can be manipulated here.