Live data from Hacker News

Ask HN: Why are you programming your hobby projects in a niche language?

news.ycombinator.com

171–172 of 172 posts

Re: Ask HN: Why are you programming your hobby projects in a niche language?

#171
post #34

I thought it would be interesting and appropriate to write the high level behavior code for a home automation system in Prolog so I did. It has evolved a lot, but has been running things in the house for almost 20 years now. It currently sends commands and receives stimuli via MQTT and is running in a Docker container.

I'd love to see this! That exact idea has been tingling through my mind for a while. I did some experiments, but Prolog (and anything logic programming, really) is a bit of a pain to integrate nicely with Python, which is what I'm building my system with. I'm looking to make things declarative as much as possible, but having Prolog manage the automation rules would be next level. I imagine it abstracts away a lot of…

See my reply to ojford with a bigger description below.

Re: Ask HN: Why are you programming your hobby projects in a niche language?

#172
post #34

I thought it would be interesting and appropriate to write the high level behavior code for a home automation system in Prolog so I did. It has evolved a lot, but has been running things in the house for almost 20 years now. It currently sends commands and receives stimuli via MQTT and is running in a Docker container.

I'd love to see this! That exact idea has been tingling through my mind for a while. I did some experiments, but Prolog (and anything logic programming, really) is a bit of a pain to integrate nicely with Python, which is what I'm building my system with. I'm looking to make things declarative as much as possible, but having Prolog manage the automation rules would be next level. I imagine it abstracts away a lot of…

Instead of trying to directly integrate for example Prolog and Python I set up services in whatever language/hardware and communicate between then using JSON messages transported via MQTT. With this method I've got Docker containers running Java, Python, and Prolog code interoperating with ESP8266 and ESP32 devices I programmed in C++ and anyone can talk to anyone. I also wrote a Java server that interfaces with an Insteon gateway so my little MQTT cluster can respond to devices turning on/off or send a MQTT message to control a device. The pieces don't know or care what language the other pieces are written in.

On the Prolog side of things with not that much framework code here is a trivial example:

message(['Smarthome','Notify','brain','ping'],_):- publish(['Smarthome', 'Notify', 'brain', 'ping_response']).

This code receives a MQTT message with a topic of Smarthome/Notify/brain/ping ignoring the message body and then publishes a return message on topic Smarthome/Notify/brain/ping_response

I even have a container that runs nothing but cron with a mqtt client installed that sends mqtt messages at various times of the day and all Prolog has to do is subscribe to those topics and handle those messages.

Post reply on HN