Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from core.rules import rule
- from core.triggers import when
- from core.utils import send_command_if_different, post_update_if_different
- from core.log import logging, LOG_PREFIX
- from community.gatekeeper import Gatekeeper
- log = logging.getLogger("{}.irrigation".format(LOG_PREFIX))
- gatekeeper = None
- @rule("Reset Irrigation at OH Start")
- @when("System started")
- def reset_irrigation(event):
- log.info("System started, stopping irrigation")
- stop_all_irrigation()
- @rule("Start Irrigation at 08:00")
- @when("Time cron 0 0 8 * * ?")
- #@when("Time cron * * * * * ?")
- @when("Item Irrigation_Manual received command ON")
- def start_irrigation(event):
- #log.info("start_irrigation")
- #log.info(items["Irrigation_Auto"])
- #log.info(items["Irrigation_Manual"])
- if items["Irrigation_Auto"] == ON or items["Irrigation_Manual"] == ON:
- # Reset the gatekeeper
- global gatekeeper
- if gatekeeper:
- gatekeeper.cancel_all()
- gatekeeper = Gatekeeper(start_irrigation.log)
- # Schedule the Irrigation Zone Commands
- def command_zone(zone, cmd):
- start_irrigation.log.info("{} Irrigation for {}".format("Starting" if cmd == ON else "Stopping"))
- # send_command_if_different(zone, cmd)
- post_update_if_different("Irrigation_Curr", zone.name if cmd == ON else "OFF")
- log.info(ir)
- log.info(ir.getItem("gIrrigation"))
- log.info(ir.getItem("gIrrigation").members)
- for zone in sorted(ir.getItem("gIrrigation").members):
- # Turn on the zone
- log.info(zone)
- continue
- gatekeeper.add_command(int(items["{}_Time".format(zone.name)]), lambda: command_zone(zone, ON))
- # Turn off the zone, have one second before turning on the next zone
- gatekeeper.add_command(1, lambda: command_zone(zone, OFF))
- @rule("Cancel Irrigation")
- @when("Item Irrigation_Manual received command OFF ")
- def cancel_irrigation(event):
- scriptUnloaded()
- stop_all_irrigation()
- def scriptUnloaded():
- global gatekeeper
- if gatekeeper:
- log.info("Cancelled gatekeeper")
- gatekeeper.cancel_all()
- gatekeeper = None
- def stop_all_irrigation():
- for valve in [valve for valve in ir.getItem("gIrrigation").members if valve.state != ON]:
- send_command_if_different(valve, OFF)
- post_update_if_different("Irrigation_Curr", "OFF")
- @rule("Test Irrigation")
- @when("Item Irrigation_Test received command ON ")
- def cancel_irrigation(event):
- print("Test")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement