Skip to content

Commit

Permalink
Add nest widget
Browse files Browse the repository at this point in the history
  • Loading branch information
phae committed Dec 2, 2014
1 parent f4e6195 commit 9cb5b96
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Expand Up @@ -8,6 +8,9 @@ gem 'oa-openid'
gem 'omniauth-heroku', '~> 0.2.0.pre'
gem 'oauth2'

# additional widgets
gem 'nest_thermostat'

# JSON
gem 'json'

Expand Down
Binary file added assets/images/nest_leaf.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/nest_leaf_trans.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/nest_logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions dashboards/main.erb
Expand Up @@ -63,6 +63,10 @@
<div data-id="uctemp" data-view="Sttemp" data-title="Downstairs" data-device="Front Door"></div>
</li>

<li data-row="3" data-col="7" data-sizex="1" data-sizey="1">
<div data-id="nest" data-view="Nest" data-title="Nest Temp"></div>
</li>

<!--li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="consolelamp" data-view="Stswitch" data-title="Console" data-device="Console Lamp"></div>
</li>
Expand Down
41 changes: 41 additions & 0 deletions jobs/nest.rb
@@ -0,0 +1,41 @@
require 'nest_thermostat'

nest_user = ENV['NEST_USER']
nest_password = ENV['NEST_PASSWORD']

use_metric_system = false

SCHEDULER.every '1m', :first_in => 0 do |job|
nest = NestThermostat::Nest.new({email: nest_user,password: nest_password})
first_nest = nest.status["shared"][nest.device_id]
temp = nest.temperature.to_i;
if (use_metric_system)
temp = f_to_c(temp)
end
away = nest.away
state = "off"
leaf_src = ""

if(first_nest['hvac_ac_state'])
state = "cooling"
elsif (first_nest['hvac_heater_state'])
state = "heating"
end

if(nest.leaf)
leaf_src = "assets/nest_leaf.png"
else
leaf_src = "assets/nest_leaf_trans.png"
end

if(away)
temp = "Away"
end

send_event('nest', { temp: temp , state: state, away: away, leaf: leaf_src })
end

# Converts fahrenheit to celcius.
def f_to_c(temp)
return (((input - 32) * 5) / 9)
end
16 changes: 16 additions & 0 deletions widgets/nest/nest.coffee
@@ -0,0 +1,16 @@
class Dashing.Nest extends Dashing.Widget

onData: (data) ->
@setBackgroundClassBy data.state

setBackgroundClassBy:(state) ->
@removeBackgroundClass()
$(@node).addClass "nest-state-#{state}"

removeBackgroundClass: ->
classNames = $(@node).attr("class").split " "
for className in classNames
match = /nest-state-(.*)/.exec className
$(@node).removeClass match[0] if match


3 changes: 3 additions & 0 deletions widgets/nest/nest.html
@@ -0,0 +1,3 @@
<img src="assets/nest_logo.png"/>
<h1 data-bind="temp"></h1>
<img data-bind-src="leaf" data-bind-width="width"/>
35 changes: 35 additions & 0 deletions widgets/nest/nest.scss
@@ -0,0 +1,35 @@
.widget-nest {
background: linear-gradient(to bottom, #3b4248 0%,#2a2f34 40%,#222529 100%);
transition: background-color 2s linear;
-moz-transition: background-color 2s linear;
-o-transition: background-color 2s linear;
-webkit-transition: background-color 2s linear;

h1{
vertical-align: middle;
font-size: 80px;
font-family: Helvetica;
}

h3{
margin-top: -5px;
}
}

.nest-state-cooling {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1b96ff), color-stop(40%,#0c7bfb), color-stop(100%,#0259f0)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #1b96ff 0%,#0c7bfb 40%,#0259f0 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(to bottom, #1b96ff 0%,#0c7bfb 40%,#0259f0 100%); /* W3C */
}

.nest-state-heating {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ff7c0a), color-stop(40%,#f94c00), color-stop(100%,#f32800)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ff7c0a 0%,#f94c00 40%,#f32800 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(to bottom, #ff7c0a 0%,#f94c00 40%,#f32800 100%); /* W3C */
}

.nest-state-off {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#3b4248), color-stop(40%,#2a2f34), color-stop(100%,#222529)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #3b4248 0%,#2a2f34 40%,#222529 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(to bottom, #3b4248 0%,#2a2f34 40%,#222529 100%); /* W3C */
}

0 comments on commit 9cb5b96

Please sign in to comment.