This is more or less as good as it gets - You can save a few more chars with something like this:
badgeColor: =dayjs().diff(dayjs(items[loop.i.name].state),"h")<1?"green":dayjs().diff(dayjs(items[loop.i.name].state),"d")<1?"orange":"red"
//edit
Based on the best practice mentioned here by Yannick, I updated the above expression to use items[loop.i.name].state instead of loop.i.state