how to programmatically set unpublish_on
Follow the examples set by the scheduler module when it loads, inserts, and builds the form. Add the unpublish_on property to the node object with the value of the UNIX timestamp (of when it will unpublish). When the node is saved, the scheduler module will save the unpublish date.

$node = node_load(123);
$node-&gt;unpublish_on = strtotime("2018-06-25 12:23:11");
node_save($node);