awair 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/exe/awair_mqtt_bridge +69 -0
  3. metadata +142 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 788ff24e23ac2945b69b285a3a1b449f87927072d4f4e80367146304d85ff1cd
4
+ data.tar.gz: 69b050275c5b63911f9cf32e35cdd692ab09d52452f726ce0e965a16ba22688d
5
+ SHA512:
6
+ metadata.gz: f78ab06856013674cbfd8702a4e15926860124dd04aafa8161b0374f1940bb00b746eb674143f9e6d328b4891d9f9e5dc0ab4b448aee785267380268c4ce506a
7
+ data.tar.gz: 9d25f750205b8a66e3a037c86c437bf5e9c961c7e8bb6de11d6e48aa409fd5e2549b1711c41b64c93f9db165fe6262b8191a3b1acb87d33d98996bdc1df07965
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "faraday_middleware"
5
+ require "homie-mqtt"
6
+ require "optparse"
7
+
8
+ refresh = 30.0
9
+ fahrenheit = false
10
+
11
+ options = OptionParser.new do |opts|
12
+ opts.banner = "Usage: awair_mqtt_bridge SENSOR_IP MQTT_URI [options]"
13
+
14
+ opts.on("--refresh-interval=INTERVAL", "Refresh interval (default 30s)") { |v| refresh = v.to_f }
15
+ opts.on("-f", "--fahrenheit", "Convert to fahrenheit before publishing") { fahrenheit = true }
16
+ opts.on("-h", "--help", "Prints this help") do
17
+ puts opts
18
+ exit
19
+ end
20
+ end
21
+
22
+ options.parse!
23
+
24
+ unless ARGV.length == 2
25
+ puts options
26
+ exit 1
27
+ end
28
+
29
+ awair = Faraday.new(url: "http://#{ARGV[0]}/air-data/latest") do |f|
30
+ f.request :retry
31
+ f.response :raise_error
32
+ f.response :json
33
+ f.adapter :net_http_persistent
34
+ end
35
+
36
+ config = awair.get("/settings/config/data").body
37
+ data = awair.get.body
38
+
39
+ unit = fahrenheit ? "°F" : "°C"
40
+ def convert_unit(number, use_fahrenheit)
41
+ return number unless use_fahrenheit
42
+
43
+ number * 9 / 5 + 32
44
+ end
45
+
46
+ homie = MQTT::Homie::Device.new(MQTT::Homie.escape_id(config["device_uuid"]), "Awair Sensor", mqtt: ARGV[1])
47
+ device = homie.node("device", "Device", "Device")
48
+ device.property("score", "Air Quality Score", :integer, data["score"], format: 0..100, unit: "%")
49
+ device.property("dewpoint", "Dew Point", :float, convert_unit(data["dew_point"], fahrenheit), unit: unit)
50
+ device.property("temperature", "Current Temperature", :float, convert_unit(data["temp"], fahrenheit), unit: unit)
51
+ device.property("relative-humidity", "Current Relative Humidity", :float, data["humid"], format: 0..100, unit: "%")
52
+ device.property("co2", "CO₂ Concentration", :integer, data["co2"], unit: "ppm")
53
+ device.property("tvocs", "TVOCs Concentration", :integer, data["voc"], unit: "ppb")
54
+ device.property("pm2-5", "Fine particle concentration", :integer, data["pm25"], unit: "µg/m³")
55
+
56
+ homie.publish
57
+
58
+ loop do
59
+ data = awair.get.body
60
+ device["score"].value = data["score"]
61
+ device["dewpoint"].value = convert_unit(data["dew_point"], fahrenheit)
62
+ device["temperature"].value = convert_unit(data["temp"], fahrenheit)
63
+ device["relative-humidity"].value = data["humid"]
64
+ device["co2"].value = data["co2"]
65
+ device["tvocs"].value = data["voc"]
66
+ device["pm2-5"].value = data["pm25"]
67
+
68
+ sleep refresh
69
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awair
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cody Cutrer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday_middleware
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: homie-mqtt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-http-persistent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.19'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.19'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.6'
111
+ description:
112
+ email: cody@cutrer.com'
113
+ executables:
114
+ - awair_mqtt_bridge
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - exe/awair_mqtt_bridge
119
+ homepage: https://github.com/ccutrer/ruby-awair
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '2.5'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.1.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Publish Awair sensor data to mqtt
142
+ test_files: []