Can I use Inform 6/7 as a parser for a smart home

This is completely left field , but let my try and explain. ( sorry this maybe a bit of a ramble)

15 years ago .I used inform 7 with my son to help with his languages skills to write interactive fiction. I always remember how elegant the language was for describing objects and how to manipulate them.

I am now working with Home assistant to control my house . They have introduced a very rudimentary language parser so you can ask Home assistant to manipulate objects in the house like lights and switches, but the parser requires exact matches , which is very painful to program. So I can program “turn on the kitchen light” but if I vary that command or ask in a different way I have to program every response individually

Could I use inform to describe all the objects in the house and how they interact with each other. For instance I could ask “turn on all the lights in the house expect the kitchen lights” and inform could return all lights it has turned on

My question is can I pass text and data ( current state of all the objects in the house) and return the response as a command line, that I could then pass to Home assistant , use Inform as a data model ? and give the responses some personality


Using Inform as a command translator is pretty easy. That is, you could write a small game which accepts commands in Adventure English and prints them out again in exact home-assistant syntax. Just have some objects and some verbs whose action is to print “[TURNON KITCHEN LIGHT]” or what have you.

Then you have to figure out how to place this translator in front of the software you’ve got. This is probably doable, but the details depend on how the software works. Is it a web interface? Command-line tool? How hackable is it?

The second part of the problem is reading the current state of the house from the software you’ve got. Again, there are various ways this could work.


Thanks for quick reply .

Home assistant is very hack-able , it will accept input and output in just about any format. The input I want to push into inform is from a microphone that’s converted speech to text

In simplistic form . Can I call call the inform “adventure” from a linux bash shell and push command line variables into Inform with all the current values of the lights, switches, etc, location in the house ( so Inform can reply in the correct context) and of course the text. Can the output then be send back to the command line ?. If the call for above is made via Home assistant it can pickup the output.

Is there any documentation for this ?

Basically I want to add a bit fun and personality to the answers

1 Like

You can use a command line interpreter, like glulxe with cheapglk.

Then, in your inform story, you can use the convention that your first command is a representation of the state of your house (format is up to you, within the parser limitations) and the second one is the speech input. Your story’s response will be printed on stdout, which you’ll be able to capture.

To intercept a somewhat arbitrary format (for the state), you’ll need After reading a command and to bypass the 20 words limits of this method, you’ll need to access the full input buffer.

Here’s untested code on how to parse JSON from the command (with Dannii Willis’ extension) but if your state is simple, you can come up with a simpler text format:

Include JSON by Dannii Willis.

	When reading a command, we are limited to 20 "words", delimited by < >, <,> or <"> which happens pretty fast with JSON.
	With this phrase, we access the full command.
To say full buffer: (-

Include (-
[PrintFullBuffer ix;
	for (ix=WORDSIZE: ix<(buffer-->0)+WORDSIZE: ix++) print (char) buffer->ix;

After reading a command (this is the parse JSON command rule):
	if character number 1 in the player's command is "{":
		let the JSON command is parse "[full buffer]";
		if the type of JSON command is JSON error type:
			[say "Error in JSON command.";]
			[ Do something with the json. ]
		reject the player's command;
1 Like

This is a really cool use case for Inform. It has me thinking now of other potential non-standard uses.


Thank you all :slight_smile:

Time to dust down my inform 7 skills , not touched in more years than I care to remember.

1 Like

If you build with RemGlk instead, you get a JSON-based api.It’s harder to set up, but cleaner to work with once it’s set up.

That’s what I use indeed, but since I suggested using JSON in the commands, I didn’t want to talk about escaping JSON inside JSON. But I guess that if one is able to call a CLI, write in stdin & read stdout, JSON inside JSON shouldn’t be too difficult.

Another interesting possibility is to write the state in a file and to read it from inform.

Also, with glulxe, you can run in “single turn mode” (launch, process input, print output, exit). It can be easier to deal with, depending on what you use to run the process.

You are standing west of a white house.

A hollow voice says "Fool..." and the lights in your house go out.