ruby_home 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/README.md +36 -75
- data/examples/air_purifier.rb +67 -0
- data/examples/air_quality_sensor.rb +120 -0
- data/examples/battery_service.rb +59 -0
- data/examples/carbon_dioxide_sensor.rb +79 -0
- data/examples/carbon_monoxide_sensor.rb +79 -0
- data/examples/contact_sensor.rb +67 -0
- data/examples/door.rb +49 -0
- data/examples/fan.rb +31 -0
- data/examples/fan_v2.rb +69 -0
- data/examples/garage_door_opener.rb +72 -0
- data/examples/heater_cooler.rb +93 -0
- data/examples/humidifier_dehumidifier.rb +89 -0
- data/examples/humidity_sensor.rb +63 -0
- data/examples/leak_sensor.rb +67 -0
- data/examples/light_sensor.rb +65 -0
- data/examples/lightbulb.rb +32 -0
- data/examples/lock_mechanism.rb +35 -0
- data/examples/motion_sensor.rb +67 -0
- data/examples/occupancy_sensor.rb +67 -0
- data/examples/outlet.rb +30 -0
- data/examples/security_system.rb +54 -0
- data/examples/smoke_sensor.rb +67 -0
- data/examples/switch.rb +17 -0
- data/examples/temperature_sensor.rb +63 -0
- data/examples/thermostat.rb +114 -0
- data/examples/window.rb +49 -0
- data/examples/window_covering.rb +73 -0
- data/lib/ruby_home/config/characteristics.yml +16 -0
- data/lib/ruby_home/config/services.yml +1 -0
- data/lib/ruby_home/version.rb +1 -1
- data/rubyhome.gemspec +3 -3
- data/sbin/characteristic_generator.rb +23 -1
- data/sbin/service_generator.rb +12 -2
- metadata +37 -9
data/examples/outlet.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
outlet = RubyHome::ServiceFactory.create(:outlet,
|
5
|
+
outlet_in_use: false, # required
|
6
|
+
on: false, # required
|
7
|
+
name: "occupancy sensor", # optional
|
8
|
+
)
|
9
|
+
|
10
|
+
outlet.outlet_in_use.after_update do |outlet_in_use|
|
11
|
+
if outlet_in_use
|
12
|
+
puts "outlet in use"
|
13
|
+
else
|
14
|
+
puts "outlet not in use"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
outlet.on.after_update do |on|
|
19
|
+
if on
|
20
|
+
puts "outlet is on"
|
21
|
+
sleep 1
|
22
|
+
outlet.outlet_in_use = true
|
23
|
+
else
|
24
|
+
puts "outlet is off"
|
25
|
+
sleep 1
|
26
|
+
outlet.outlet_in_use = false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RubyHome.run
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
security_system = RubyHome::ServiceFactory.create(:security_system,
|
5
|
+
security_system_target_state: 0, # required
|
6
|
+
security_system_current_state: 0, # required
|
7
|
+
name: 'security system', # optional
|
8
|
+
security_system_alarm_type: 0, # optional
|
9
|
+
status_tampered: 0, # optional
|
10
|
+
status_fault: 0 # optional
|
11
|
+
)
|
12
|
+
|
13
|
+
security_system_target_state_values = {
|
14
|
+
0 => 'Stay Arm',
|
15
|
+
1 => 'Away Arm',
|
16
|
+
2 => 'Night Arm',
|
17
|
+
3 => 'Disarm'
|
18
|
+
}
|
19
|
+
security_system.security_system_target_state.after_update do |security_system_target_state|
|
20
|
+
state = security_system_target_state_values[security_system_target_state]
|
21
|
+
puts "security system security_system_target_state #{state}"
|
22
|
+
sleep 1
|
23
|
+
security_system.security_system_current_state = security_system_target_state
|
24
|
+
end
|
25
|
+
|
26
|
+
security_system_current_state_values = {
|
27
|
+
0 => 'Stay Arm',
|
28
|
+
1 => 'Away Arm',
|
29
|
+
2 => 'Night Arm',
|
30
|
+
3 => 'Disarmed',
|
31
|
+
4 => 'Alarm Triggered'
|
32
|
+
}
|
33
|
+
security_system.security_system_current_state.after_update do |security_system_current_state|
|
34
|
+
state = security_system_current_state_values[security_system_current_state]
|
35
|
+
puts "security system security_system_current_state state #{state}"
|
36
|
+
end
|
37
|
+
|
38
|
+
security_system.status_tampered.after_update do |status_tampered|
|
39
|
+
if status_tampered == 0
|
40
|
+
puts "security system status_tampered not tampered"
|
41
|
+
elsif status_tampered == 1
|
42
|
+
puts "security system status_tampered tampered"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
security_system.status_fault.after_update do |status_fault|
|
47
|
+
if status_fault == 0
|
48
|
+
puts "security system status_fault no fault"
|
49
|
+
elsif status_fault == 1
|
50
|
+
puts "security system status_fault general fault"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
RubyHome.run
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
smoke_sensor = RubyHome::ServiceFactory.create(:smoke_sensor,
|
5
|
+
smoke_detected: 0, # required
|
6
|
+
name: "smoke sensor", # optional
|
7
|
+
status_low_battery: 0, # optional
|
8
|
+
status_tampered: 0, # optional
|
9
|
+
status_fault: 0, # optional
|
10
|
+
status_active: true # optional
|
11
|
+
)
|
12
|
+
|
13
|
+
smoke_sensor.smoke_detected.after_update do |smoke_detected|
|
14
|
+
if smoke_detected == 0
|
15
|
+
puts "smoke sensor smoke not detected"
|
16
|
+
elsif smoke_detected == 1
|
17
|
+
puts "smoke sensor smoke detected"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
smoke_sensor.status_low_battery.after_update do |status_low_battery|
|
22
|
+
if status_low_battery == 0
|
23
|
+
puts "smoke sensor battery level normal"
|
24
|
+
elsif status_low_battery == 1
|
25
|
+
puts "smoke sensor battery level lormal"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
smoke_sensor.status_tampered.after_update do |status_tampered|
|
30
|
+
if status_tampered == 0
|
31
|
+
puts "smoke sensor status_tampered not tampered"
|
32
|
+
elsif status_tampered == 1
|
33
|
+
puts "smoke sensor status_tampered tampered"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
smoke_sensor.status_fault.after_update do |status_fault|
|
38
|
+
if status_fault == 0
|
39
|
+
puts "smoke sensor status_fault no fault"
|
40
|
+
elsif status_fault == 1
|
41
|
+
puts "smoke sensor status_fault general fault"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
smoke_sensor.status_active.after_update do |active|
|
46
|
+
if active
|
47
|
+
puts "smoke sensor is active"
|
48
|
+
else
|
49
|
+
puts "smoke sensor is inactive"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Thread.new do
|
54
|
+
sleep 30
|
55
|
+
|
56
|
+
loop do
|
57
|
+
smoke_sensor.smoke_detected = (0..1).to_a.sample
|
58
|
+
smoke_sensor.status_low_battery = (0..1).to_a.sample
|
59
|
+
smoke_sensor.status_tampered = (0..1).to_a.sample
|
60
|
+
smoke_sensor.status_fault = (0..1).to_a.sample
|
61
|
+
smoke_sensor.status_active = [true, false].to_a.sample
|
62
|
+
|
63
|
+
sleep 10
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
RubyHome.run
|
data/examples/switch.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
switch = RubyHome::ServiceFactory.create(:switch,
|
5
|
+
on: false, # required
|
6
|
+
name: 'switch', # optional
|
7
|
+
)
|
8
|
+
|
9
|
+
switch.on.after_update do |on|
|
10
|
+
if on
|
11
|
+
puts "switch is on"
|
12
|
+
else
|
13
|
+
puts "switch is off"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RubyHome.run
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
temperature_sensor = RubyHome::ServiceFactory.create(:temperature_sensor,
|
5
|
+
current_temperature: 30, # required
|
6
|
+
name: "temperature sensor", # optional
|
7
|
+
status_low_battery: 0, # optional
|
8
|
+
status_tampered: 0, # optional
|
9
|
+
status_fault: 0, # optional
|
10
|
+
status_active: true # optional
|
11
|
+
)
|
12
|
+
|
13
|
+
temperature_sensor.current_temperature.after_update do |current_temperature|
|
14
|
+
puts "temperature sensor current_temperature #{current_temperature}"
|
15
|
+
end
|
16
|
+
|
17
|
+
temperature_sensor.status_low_battery.after_update do |status_low_battery|
|
18
|
+
if status_low_battery == 0
|
19
|
+
puts "temperature sensor battery level normal"
|
20
|
+
elsif status_low_battery == 1
|
21
|
+
puts "temperature sensor battery level lormal"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
temperature_sensor.status_tampered.after_update do |status_tampered|
|
26
|
+
if status_tampered == 0
|
27
|
+
puts "temperature sensor status_tampered not tampered"
|
28
|
+
elsif status_tampered == 1
|
29
|
+
puts "temperature sensor status_tampered tampered"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
temperature_sensor.status_fault.after_update do |status_fault|
|
34
|
+
if status_fault == 0
|
35
|
+
puts "temperature sensor status_fault no fault"
|
36
|
+
elsif status_fault == 1
|
37
|
+
puts "temperature sensor status_fault general fault"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
temperature_sensor.status_active.after_update do |active|
|
42
|
+
if active
|
43
|
+
puts "temperature sensor is active"
|
44
|
+
else
|
45
|
+
puts "temperature sensor is inactive"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Thread.new do
|
50
|
+
sleep 30
|
51
|
+
|
52
|
+
loop do
|
53
|
+
temperature_sensor.current_temperature = (0..100).to_a.sample
|
54
|
+
temperature_sensor.status_low_battery = (0..1).to_a.sample
|
55
|
+
temperature_sensor.status_tampered = (0..1).to_a.sample
|
56
|
+
temperature_sensor.status_fault = (0..1).to_a.sample
|
57
|
+
temperature_sensor.status_active = [true, false].to_a.sample
|
58
|
+
|
59
|
+
sleep 10
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
RubyHome.run
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
thermostat = RubyHome::ServiceFactory.create(:thermostat,
|
5
|
+
temperature_display_units: 0, # required
|
6
|
+
target_temperature: 18, # required
|
7
|
+
current_temperature: 18, # required
|
8
|
+
target_heating_cooling_state: 0, # required
|
9
|
+
current_heating_cooling_state: 0, # required
|
10
|
+
name: "thermostat", # optional
|
11
|
+
heating_threshold_temperature: 20, # optional
|
12
|
+
cooling_threshold_temperature: 10, # optional
|
13
|
+
target_relative_humidity: 0, # optional
|
14
|
+
current_relative_humidity: 0, # optional
|
15
|
+
)
|
16
|
+
|
17
|
+
thermostat.temperature_display_units.after_update do |temperature_display_unit|
|
18
|
+
if temperature_display_unit == 0
|
19
|
+
puts "thermostat temperature display units Celsius"
|
20
|
+
elsif temperature_display_unit == 1
|
21
|
+
puts "thermostat temperature display units Fahrenheit"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
thermostat.target_temperature.after_update do |target_temperature|
|
26
|
+
puts "thermostat target_temperature #{target_temperature}"
|
27
|
+
|
28
|
+
if target_temperature.to_i > thermostat.current_temperature.to_i
|
29
|
+
thermostat.target_heating_cooling_state = 1
|
30
|
+
elsif target_temperature < thermostat.current_temperature
|
31
|
+
thermostat.target_heating_cooling_state = 2
|
32
|
+
elsif target_temperature.to_i == thermostat.current_temperature.to_i
|
33
|
+
thermostat.target_heating_cooling_state = 0
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
thermostat.current_temperature.after_update do |current_temperature|
|
38
|
+
puts "thermostat current_temperature #{current_temperature}"
|
39
|
+
|
40
|
+
if current_temperature.to_i < thermostat.target_temperature.to_i
|
41
|
+
thermostat.target_heating_cooling_state = 1
|
42
|
+
elsif current_temperature.to_i > thermostat.target_temperature.to_i
|
43
|
+
thermostat.target_heating_cooling_state = 2
|
44
|
+
elsif current_temperature.to_i == thermostat.target_temperature.to_i
|
45
|
+
thermostat.target_heating_cooling_state = 0
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
target_heating_cooling_state_values = {
|
50
|
+
0 => 'Off',
|
51
|
+
1 => 'Heat',
|
52
|
+
2 => 'Cool',
|
53
|
+
3 => 'Auto',
|
54
|
+
}
|
55
|
+
thermostat.target_heating_cooling_state.after_update do |target_heating_cooling_state|
|
56
|
+
state = target_heating_cooling_state_values[target_heating_cooling_state]
|
57
|
+
puts "heater cooler target heating cooler state is #{state}"
|
58
|
+
|
59
|
+
return if thermostat.current_heating_cooling_state == target_heating_cooling_state
|
60
|
+
|
61
|
+
if target_heating_cooling_state == 1
|
62
|
+
thermostat.current_heating_cooling_state = 1
|
63
|
+
elsif target_heating_cooling_state == 2
|
64
|
+
thermostat.current_heating_cooling_state = 2
|
65
|
+
elsif target_heating_cooling_state == 0
|
66
|
+
thermostat.current_heating_cooling_state = 0
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
current_heating_cooling_state_values = {
|
71
|
+
0 => 'Off',
|
72
|
+
1 => 'Heat',
|
73
|
+
2 => 'Cool',
|
74
|
+
}
|
75
|
+
thermostat.current_heating_cooling_state.after_update do |current_heating_cooling_state|
|
76
|
+
state = current_heating_cooling_state_values[current_heating_cooling_state]
|
77
|
+
puts "heater cooler current heating cooler state is #{state}"
|
78
|
+
end
|
79
|
+
|
80
|
+
thermostat.heating_threshold_temperature.after_update do |heating_threshold_temperature|
|
81
|
+
# maximum_value: 25
|
82
|
+
# minimum_value: 0
|
83
|
+
# step_value: 0.1
|
84
|
+
puts "heater cooler heating threshold temperature #{heating_threshold_temperature}"
|
85
|
+
end
|
86
|
+
|
87
|
+
thermostat.cooling_threshold_temperature.after_update do |cooling_threshold_temperature|
|
88
|
+
# maximum_value: 35
|
89
|
+
# minimum_value: 10
|
90
|
+
# step_value: 0.1
|
91
|
+
puts "heater cooler cooling threshold temperature temperature #{cooling_threshold_temperature}"
|
92
|
+
end
|
93
|
+
|
94
|
+
thermostat.target_relative_humidity.after_update do |target_relative_humidity|
|
95
|
+
puts "thermostat target_relative_humidity #{target_relative_humidity}"
|
96
|
+
end
|
97
|
+
|
98
|
+
thermostat.current_relative_humidity.after_update do |current_relative_humidity|
|
99
|
+
puts "thermostat current_relative_humidity #{current_relative_humidity}"
|
100
|
+
end
|
101
|
+
|
102
|
+
Thread.new do
|
103
|
+
loop do
|
104
|
+
sleep 5
|
105
|
+
|
106
|
+
if thermostat.target_temperature.to_i > thermostat.current_temperature.to_i
|
107
|
+
thermostat.current_temperature += 1
|
108
|
+
elsif thermostat.target_temperature.to_i < thermostat.current_temperature.to_i
|
109
|
+
thermostat.current_temperature -= 1
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
RubyHome.run
|
data/examples/window.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
window = RubyHome::ServiceFactory.create(:window,
|
5
|
+
target_position: 0, # required
|
6
|
+
position_state: 1, # required
|
7
|
+
current_position: 0, # required
|
8
|
+
name: "window", # optional
|
9
|
+
obstruction_detected: false, # optional
|
10
|
+
)
|
11
|
+
|
12
|
+
window.target_position.after_update do |target_position|
|
13
|
+
puts "window target position #{target_position}"
|
14
|
+
|
15
|
+
if target_position < window.current_position
|
16
|
+
window.position_state = 0
|
17
|
+
elsif target_position > window.current_position
|
18
|
+
window.position_state = 1
|
19
|
+
end
|
20
|
+
|
21
|
+
sleep 1
|
22
|
+
|
23
|
+
window.current_position = target_position
|
24
|
+
window.position_state = 2
|
25
|
+
end
|
26
|
+
|
27
|
+
position_state_values = {
|
28
|
+
0 => 'Decreasing',
|
29
|
+
1 => 'Increasing',
|
30
|
+
2 => 'Stopped'
|
31
|
+
}
|
32
|
+
window.position_state.after_update do |position_state|
|
33
|
+
state = position_state_values[position_state]
|
34
|
+
puts "window position state #{state}"
|
35
|
+
end
|
36
|
+
|
37
|
+
window.current_position.after_update do |current_position|
|
38
|
+
puts "window current position #{current_position}"
|
39
|
+
end
|
40
|
+
|
41
|
+
window.obstruction_detected.after_update do |obstruction_detected|
|
42
|
+
if obstruction_detected
|
43
|
+
puts "window obstruction detected"
|
44
|
+
else
|
45
|
+
puts "window no obstruction detected"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
RubyHome.run
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
window_covering = RubyHome::ServiceFactory.create(:window_covering,
|
5
|
+
target_position: 0, # required
|
6
|
+
position_state: 1, # required
|
7
|
+
current_position: 0, # required
|
8
|
+
name: "window_covering", # optional
|
9
|
+
obstruction_detected: false, # optional
|
10
|
+
current_vertical_tilt_angle: 0, # optional
|
11
|
+
target_vertical_tilt_angle: 0, # optional
|
12
|
+
current_horizontal_tilt_angle: 0, # optional
|
13
|
+
target_horizontal_tilt_angle: 0 # optional
|
14
|
+
)
|
15
|
+
|
16
|
+
window_covering.target_position.after_update do |target_position|
|
17
|
+
puts "window covering target position #{target_position}"
|
18
|
+
|
19
|
+
if target_position < window_covering.current_position
|
20
|
+
window_covering.position_state = 0
|
21
|
+
elsif target_position > window_covering.current_position
|
22
|
+
window_covering.position_state = 1
|
23
|
+
end
|
24
|
+
|
25
|
+
sleep 1
|
26
|
+
|
27
|
+
window_covering.current_position = target_position
|
28
|
+
window_covering.position_state = 2
|
29
|
+
end
|
30
|
+
|
31
|
+
position_state_values = {
|
32
|
+
0 => 'Decreasing',
|
33
|
+
1 => 'Increasing',
|
34
|
+
2 => 'Stopped'
|
35
|
+
}
|
36
|
+
window_covering.position_state.after_update do |position_state|
|
37
|
+
state = position_state_values[position_state]
|
38
|
+
puts "window covering position state #{state}"
|
39
|
+
end
|
40
|
+
|
41
|
+
window_covering.current_position.after_update do |current_position|
|
42
|
+
puts "window covering current position #{current_position}"
|
43
|
+
end
|
44
|
+
|
45
|
+
window_covering.obstruction_detected.after_update do |obstruction_detected|
|
46
|
+
if obstruction_detected
|
47
|
+
puts "window covering obstruction detected"
|
48
|
+
else
|
49
|
+
puts "window covering no obstruction detected"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
window_covering.current_vertical_tilt_angle.after_update do |current_vertical_tilt_angle|
|
54
|
+
puts "window covering current_vertical_tilt_angle #{current_vertical_tilt_angle}"
|
55
|
+
end
|
56
|
+
|
57
|
+
window_covering.target_vertical_tilt_angle.after_update do |target_vertical_tilt_angle|
|
58
|
+
puts "window covering target_vertical_tilt_angle #{target_vertical_tilt_angle}"
|
59
|
+
sleep 1
|
60
|
+
window_covering.current_vertical_tilt_angle = target_vertical_tilt_angle
|
61
|
+
end
|
62
|
+
|
63
|
+
window_covering.current_horizontal_tilt_angle.after_update do |current_horizontal_tilt_angle|
|
64
|
+
puts "window covering current_horizontal_tilt_angle #{current_horizontal_tilt_angle}"
|
65
|
+
end
|
66
|
+
|
67
|
+
window_covering.target_horizontal_tilt_angle.after_update do |target_horizontal_tilt_angle|
|
68
|
+
puts "window covering target_horizontal_tilt_angle #{target_horizontal_tilt_angle}"
|
69
|
+
sleep 1
|
70
|
+
window_covering.current_horizontal_tilt_angle = target_horizontal_tilt_angle
|
71
|
+
end
|
72
|
+
|
73
|
+
RubyHome.run
|