How Do I Write a Script/Automation to Reset a Device Value

I’m having a problem with motion sensors getting stuck ‘on’ and showing motion long after it has stopped. I have tried pinging the device, and refreshing the sensors and it doesn’t work. The only way I’ve found to fix it is using Developer Tools to manually reset the state

I can detect the condition, I just don’t know how to script/automate the process of resetting the value.

The entity ID is:
‘binary_sensor.kitchen_motion_detector_any_4’

The friendly name is:
‘KITCHEN: Motion’

You can’t set the state of sensors outside Developer Tools… except maybe with a Python script. Search the forum I think I’ve seen that solution somewhere.

Is getting better hardware an option?

As @tom_l mentioned there is a python script (available through HACS) GitHub - pmazz/ps_hassio_entities: Python script to handle state and attributes of existing sensors and entities