It is said already in other answers that you should use MQTT in your case.
But why?
MQTT is The Protocol if your things are behind a firewall in a private network [1]. All tricks are an outbound rule for port 1833 or with some configuration maybe not even that [2].
How will the things change after taking MQTT and not http?
You will need one block more to your combo of
Turn On Light (from internet) --> Digital Ocean Server--> My Home Router --> Raspberry Pi
Your flow would be:
- Subscribe for Lights on event on Raspberry Pi (message between Broker and RP)
..later night:
- Publish Lights on event on Server (message goes Server -> Broker -> RP)
What is Broker?
Message Broker is a service, that can run in the Digital Ocean and it takes in Publish andSubscription requests. [3]
One such Broker is called Mosquitto and it is open source and easy to install. You install the service and run it. No coding involved, maybe little config. [4]
Publish and subscribe?
If you are familiar with php, you may use it also with Mosquitto [5]. Sample code at least looks straight forward, link contains more examples:
<?php
$c = new Mosquitto\Client;
$c->onConnect(function() use ($c) {
$c->publish('mgdm/test', 'Hello', 2);
});
$c->connect('test.mosquitto.org');
for ($i = 0; $i < 100; $i++) {
// Loop around to permit the library to do its work
$c->loop(1);
}
echo "Finished\n";
Sources:
[1] https://mongoose-os.com/blog/why-mqtt-is-getting-so-popular-in-iot/
[2] https://stackoverflow.com/questions/32174272/how-mqtt-works-behind-the-firewall
[3] http://www.hivemq.com/blog/mqtt-essentials-part2-publish-subscribe
[4] https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-ubuntu-16-04
[5] https://github.com/mgdm/Mosquitto-PHP