Rest command only when the "state" changes

i have an snom 360 phone and can trigger over an url the dnd state of that phone. sadly the button that it is triggers only flips over from on to off or the other way around.
so i would love to build some kind of “fake” sensor, that keps track of the state it is in and just runs the rest command when the states changes - does anyone have an idea where to start? my google / forum searches didnt brough up something that i could ease