Skip to content

Instantly share code, notes, and snippets.

@ashzure-github
Created August 13, 2023 18:13
Show Gist options
  • Save ashzure-github/46a41f9ab9c6e1d3f67d0cdb11e7ca24 to your computer and use it in GitHub Desktop.
Save ashzure-github/46a41f9ab9c6e1d3f67d0cdb11e7ca24 to your computer and use it in GitHub Desktop.
furnace-watchdog.lua
-- Configuration
SAMPLE_INTERVAL_SECONDS = 5
SAMPLE_TRIGGER_COUNT = 6
FURNACE_SIDE = "left"
-- Startup banner
term.setCursorPos(1, 1)
term.clear()
print("Watchdog: starting")
print(string.format("Watchdog: polling every %d seconds", SAMPLE_INTERVAL_SECONDS))
print(string.format("Watchdog: trigger at %d samples", SAMPLE_TRIGGER_COUNT))
print()
-- Program loop
furnaceEmptySamples = 0
while (true) do
os.sleep(SAMPLE_INTERVAL_SECONDS)
local furnaceEmpty = redstone.getAnalogInput(FURNACE_SIDE) == 0
if (furnaceEmpty) then
furnaceEmptySamples = furnaceEmptySamples + 1
else
-- The furnace has been refilled, reset the watchdog.
furnaceEmptySamples = 0
end
if (furnaceEmptySamples > 0 and furnaceEmptySamples < SAMPLE_TRIGGER_COUNT) then
print(string.format("Watchdog: furnace found empty %d times", furnaceEmptySamples))
elseif (furnaceEmptySamples == SAMPLE_TRIGGER_COUNT) then
print(string.format("Watchdog: furnace found empty %d times, alerting", SAMPLE_TRIGGER_COUNT))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment