Customizing Weather Widget

I’m trying to customize the weather widget to add a high/low temp for the day. I’ve already got Darksky pulling the appropriate info and I’ve edited homeassistant.rb to add two entries - one for high temp and one for low temp

response = ha_api("states/sensor.dark_sky_daily_high_temperature", "get")
tempmax = response["state"]

response = ha_api("states/sensor.dark_sky_daily_low_temperature", "get")
tempmin = response["state"]

And also added this to the bottom of the send_event section:

tempmax: tempmax,
tempmin: tempmin

I’ve edited to haweather.html file to add High/Low section, and it shows it correctly, except I get no values, just the degree symbol. I’ve tried restarting dashing, with no change either. What did I miss?

You will need to edit the widget to actually add the fields.

When you say edit the widget, what file are you referring to specifically?

I think he means the haweather.coffee file.

1 Like

Yes, plus the .html file

1 Like

They are found in the widgets subdirectory.

1 Like

I’ve already edited the html file to add the fields, and they do show up on the widget, but there are no values listed. I’m not sure what to add into the .coffee file though, as I don’t see any other of the fields listed in that file.

I’m travelling at the moment so I can;t really check up - but make sure the data bindings in your HTML file match what you are sending in the .rb file.

No problems. Here are the appropriate sections of the files in case anyone can assist:

Homeassistant.rb:

#Update the weather ever so often
SCHEDULER.every '15m', :first_in => 0 do |job|
    #Current weather
    response = ha_api("states/sensor.dark_sky_temperature", "get")
    temp = response["state"]

    response = ha_api("states/sensor.dark_sky_humidity", "get")
    humidity = response["state"]

    response = ha_api("states/sensor.dark_sky_precip_probability", "get")
    precip = response["state"]

    response = ha_api("states/sensor.dark_sky_precip_intensity", "get")
    precipintensity = response["state"]

    response = ha_api("states/sensor.dark_sky_wind_speed", "get")
    windspeed = response["state"]

    response = ha_api("states/sensor.dark_sky_pressure", "get")
    pressure = response["state"]

    response = ha_api("states/sensor.dark_sky_wind_bearing", "get")
    windbearing = response["state"]

    response = ha_api("states/sensor.dark_sky_daily_high_temperature", "get")
    tempmax = response["state"]

    response = ha_api("states/sensor.dark_sky_daily_low_temperature", "get")
    tempmin = response["state"]

    response = ha_api("states/sensor.dark_sky_apparent_temperature", "get")
    tempchill = response["state"]

    response = ha_api("states/sensor.dark_sky_icon", "get")
    icon = response["state"].gsub(/-/, '_')

    #Emit the event
    send_event('weather', {
            temp: temp,
            humidity: humidity,
            icon: icon,
            tempchill: tempchill,
            precipintensity: precipintensity,
            precip: precip,
            windspeed: windspeed,
            windbearing: windbearing,
            pressure: pressure,
            tempmax: tempmax,
            tempmin: tempmin
    })

Haweather.coffee:

class Dashing.Haweather extends Dashing.Widget
constructor: ->
super
@_icons =
  rain: '&#xe009',
  snow: '&#xe036',
  sleet: '&#xe003',
  wind: '&#xe021',
  fog: '&#xe01b',
  cloudy: '&#xe000',
  clear_day: '&#xe028',
  clear_night: '&#xe02d',
  partly_cloudy_day: '&#xe001',
  partly_cloudy_night: '&#xe002'

@accessor 'climacon', ->
new Batman.TerminalAccessible (attr) =>
  @_icons[attr]

@accessor 'now_temp',
get: -> if @_temp then Math.floor(@_temp) else 0
set: (key, value) -> @_temp = value

ready: ->
if @get('bgcolor')
  $(@node).css("background-color", @get('bgcolor'))

onData: (data) ->

Haweather.html:

<p class="secondary-info colored">Today's High/Low:</p>
<p class="secondary-info colored" data-bind="tempmax | append '&deg;'"></p>
<p class="secondary-info colored">/</p>
<p class="secondary-info colored" data-bind="tempmin | append '&deg;'"></p>

Anyone see anything that I have missed?

Looks OK to me - can you double check in your HA GUI that the Dark Sky sensors exist and have values in them?

Yes, I have sensor.dark_sky_daily_high_temperature and sensor.dark_sky_daily_high_temperature, both showing correct values.

If I set up hasensor widgets for both of those, they do show the correct values as well.

Ok, managed to get this one working. Turns out there was nothing wrong with any of the setup, I just didn’t remember correctly how I had dashing running. I was thinking I had set it up using systemctl, then remembered I never did get that working right. So… when I thought I was restarting it, I was really doing nothing at all. A quick ‘dashing stop’ and ‘dashing start -d’ later, widget shows the correct info.

Oops…

Hehe, glad you fixed it :slight_smile:

Sorry to revive an old thread but I’ve been trying desperately to display a simple today and tomorrow forecast but don’t know which files to edit. The current information displayed but the weather widget is not that helpful to me (don’t really care about humidity and wind speed etc…).

Any tips on where to start would be greatly appreciated.

edit - Preferably like this.

We now have a custom widget API, so you could build your own :slight_smile:

The docs are here:

http://appdaemon.readthedocs.io/en/latest/WIDGETDEV.html

1 Like

I would love to find the code for that other widget I’ve seen. Simple current and tomorrow. I might try and mess with this soon, don’t count on me though I’m brand new lol

2 Likes