1if not modules then modules = { } end modules ['mtx-evohome'] = {
2 version = 1.002,
3 comment = "script to fetch data from a evohome device",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE",
6 license = "see context related readme files"
7}
8
9local evohome = require("util-evo")
10
11local formatters = string.formatters
12
13
14
15local helpinfo = [[
16<?xml version="1.0"?>
17<application>
18 <metadata>
19 <entry name="name">mtx-evohome</entry>
20 <entry name="detail">Evohome Fetcher</entry>
21 <entry name="version">1.00</entry>
22 </metadata>
23 <flags>
24 <category name="basic">
25 <subcategory>
26 <flag name="collect"><short>collect data from device</short></flag>
27 <flag name="update"><short>update data from device</short></flag>
28 <flag name="presets"><short>file with authenciation data</short></flag>
29 <flag name="auto"><short>fetch temperature data every hour</short></flag>
30 <flag name="port"><short>server port when running the service, default: 8068</short></flag>
31 <flag name="host"><short>server host when running the service, default: localhost</short></flag>
32 </subcategory>
33 </category>
34 </flags>
35 <examples>
36 <category>
37 <title>Example</title>
38 <subcategory>
39 <example><command>mtxrun --script evohome --collect --presets=c:/data/develop/domotica/code/evohome-presets.lua</command></example>
40 <example><command>mtxrun --script evohome --server --presets=c:/data/develop/domotica/code/evohome-presets.lua</command></example>
41 </subcategory>
42 </category>
43 </examples>
44</application>
45]]
46
47local application = logs.application {
48 name = "mtx-evohome",
49 banner = "Evohome Fetcher 1.00",
50 helpinfo = helpinfo,
51}
52
53local report = application.report
54
55scripts = scripts or { }
56scripts.evohome = scripts.evohome or { }
57
58local arguments = environment.arguments
59local files = environment.files
60
61function scripts.evohome.collect()
62 local presets = arguments.presets
63 local delay = tonumber(arguments.delay) or 15*60*60
64 if presets then
65 presets = evohome.helpers.loadpresets(presets)
66 end
67 if presets then
68 local function fetch()
69 report("current time %a",os.now())
70 evohome.helpers.updatetemperatures(presets)
71 end
72 if arguments.auto then
73 while true do
74 fetch()
75 report("sleeping for %i seconds",delay)
76 io.flush()
77 os.sleep(delay)
78 end
79 else
80 fetch(presets)
81 end
82 else
83 report("invalid preset file")
84 end
85end
86
87function scripts.evohome.update()
88 local presets = arguments.presets
89 if presets then
90 presets = evohome.helpers.loadpresets(presets)
91 end
92 if presets then
93 evohome.helpers.geteverything(presets)
94 else
95 report("invalid preset file")
96 end
97end
98
99function scripts.evohome.server()
100 local presets = arguments.presets
101 if presets then
102 require("util-evo-imp-server")
103 evohome.server {
104 filename = presets,
105 host = arguments.host,
106 port = tonumber(arguments.port),
107 }
108 else
109 report("invalid preset file")
110 end
111end
112
113if environment.argument("collect") then
114 scripts.evohome.collect()
115elseif environment.argument("update") then
116 scripts.evohome.update()
117elseif environment.argument("server") then
118 scripts.evohome.server()
119elseif environment.argument("exporthelp") then
120 application.export(environment.argument("exporthelp"),environment.files[1])
121else
122 application.help()
123end
124 |