编辑:2019年3月3日

深蓝天气卡

图像

黑暗的天气卡使用深浅平台提供当前和预测的天气条件。您可以通过从黑暗的天空传感器平台传输传感器实体来配置卡。

该卡是非常可定制的。您可以通过传递定制标志和定义可选传感器来配置它的外观和景点的许多方面以及所展示的许多方面。如果需要,也可以重新排列内容。

如果已启用该选项,将在预测日悬停在预测日将在工具提示弹出中显示日常天气摘要。

可以找到完整的自述文件这里。它包含有关如何设置卡以及如何使用各种功能的最新说明。

可以找到最新版本的卡这里

GitHub网站是这里。请使用GitHub问题来请求新功能,因为它使它们更容易跟踪。


原帖:
仅供参考。
请参阅上面的链接到当前卡和说明书

几个人询问了使用非常好的自定义动画天气卡@arsaboo.有黑暗的天空。我根据我的需求修改了这张卡片。- 所有信用都是创建原创的人和那些修改它的人,以便将其赶到我能够破解的东西。

我的修改版使用Dark Sky Sensor平台如下所示:

传感器.YAML代码:

- 平台:Darksky API_KEY:预测: -  1  -  2  -  3  -  4  -  5 Monitored_Conditions: - 图标 - 摘要 - 最近的_storm_Beartance  - 湿度 - 温度 - 温度 - 温度 - 温度 - 温度_温度 -  Apparent_Temperature  -  Apparent_temperature  -  ThaneNt_temperature_High  -PROCIP_TYPE  -  PROCIT_PROBABITY  -  PROCIT_ACCUMULATION  -  PROCIT_INTESSICS  -  PROCIT_INTESS_MAX  -  UV_INDEX  -  DAIL_SUMM_SUMMARY  - 压力 - 可见性UPDATE_INTERVAL:分钟:5

我通过传感器实体卡需要。注意预测_Low_Temp实体被交错了1.这将在特定日子的早晨使用低温,这与Dark Sky App显示它的方式匹配。

注意:下面列出的所有实体都是必需的。

ui-lovelace.yaml代码:

- 类型:定制:黑暗天空全天候卡entity_sun:sun.sun entity_daily_summary:sensor.dark_sky_daily_summary entity_current_conditions:sensor.dark_sky_icon entity_humidity:sensor.dark_sky_humidity entity_pressure:sensor.dark_sky_pressure entity_temperature:sensor.dark_sky_temperature entity_visibility:sensor.dark_sky_visibility entity_wind_bearing:传感器。dark_sky_wind_bearing entity_wind_speed: sensor.dark_sky_wind_speed entity_forecast_high_temp_1: sensor.dark_sky_daytime_high_temperature_1 entity_forecast_high_temp_2: sensor.dark_sky_daytime_high_temperature_2 entity_forecast_high_temp_3: sensor.dark_sky_daytime_high_temperature_3 entity_forecast_high_temp_4: sensor.dark_sky_daytime_high_temperature_4 entity_forecast_high_temp_5: sensor.dark_sky_daytime_high_temperature_5 entity_forecast_low_temp_1: sensor.dark_sky_overnight_low_temperature entity_forecast_low_temp_2: sensor.dark_sky_overnight_low_temperature_1 entity_forecast_low_temp_3: sensor.dark_sky_overnight_low_temperature_2 entity_forecast_low_temp_4: sensor.dark_sky_overnight_low_temperature_3 entity_forecast_low_temp_5: sensor.dark_sky_overnight_low_temperature_4 entity_forecast_icon_1: sensor.dark_sky_icon_1 entity_forecast_icon_2: sensor.dark_sky_icon_2 entity_forecast_icon_3: sensor.dark_sky_icon_3 entity_forecast_icon_4: sensor.dark_sky_icon_4 entity_forecast_icon_5: sensor.dark_sky_icon_5

我绝不是JavaScript开发人员。我没有声称,我走近的方式是最好的甚至是一种好方法。它适合我,这就是我所开放的工作

黑暗天气卡.JS:

class DarkSkyWeatherCard extends HTMLElement {set hass(hass) {if (!this.content) {const card = document.createElement('ha-card');const link = document.createelement('link');link.type ='text / css';link.rel ='stylesheet';link.href ='/local/custom_ui/dark-sky-weather-card.css';card.appendchild(链接);这个.Content = document.createelement('div');this.content.className =“卡”;card.appendChild (this.content);this.appendChild(卡); } const getUnit = function (measure) { const lengthUnit = hass.config.core.unit_system.length; switch (measure) { case 'air_pressure': return lengthUnit === 'km' ? 'hPa' : 'inHg'; case 'length': return lengthUnit; case 'precipitation': return lengthUnit === 'km' ? 'mm' : 'in'; default: return hass.config.core.unit_system[measure] || ''; } }; const transformDayNight = { "below_horizon": "night", "above_horizon": "day", } const sunLocation = transformDayNight[hass.states[this.config.entity_sun].state]; const weatherIcons = { 'clear-day': 'day', 'clear-night': 'night', 'rain': 'rainy-5', 'snow': 'snowy-6', 'sleet': 'rainy-6', 'wind': 'cloudy', 'fog': 'cloudy', 'cloudy': 'cloudy', 'partly-cloudy-day': 'cloudy-day-3', 'partly-cloudy-night': 'cloudy-night-3', 'hail': 'rainy-7', 'lightning': 'thunder', 'thunderstorm': 'thunder', 'windy-variant': `cloudy-${sunLocation}-3`, 'exceptional': '!!', } const windDirections = [ 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N' ]; var forecastDate1 = new Date(); forecastDate1.setDate(forecastDate1.getDate()+1); var forecastDate2 = new Date(); forecastDate2.setDate(forecastDate2.getDate()+2); var forecastDate3 = new Date(); forecastDate3.setDate(forecastDate3.getDate()+3); var forecastDate4 = new Date(); forecastDate4.setDate(forecastDate4.getDate()+4); var forecastDate5 = new Date(); forecastDate5.setDate(forecastDate5.getDate()+5); const currentConditions = hass.states[this.config.entity_current_conditions].state; const humidity = hass.states[this.config.entity_humidity].state; const pressure = Math.round(hass.states[this.config.entity_pressure].state); const temperature = Math.round(hass.states[this.config.entity_temperature].state); const visibility = hass.states[this.config.entity_visibility].state; const windBearing = windDirections[(Math.round((hass.states[this.config.entity_wind_bearing].state / 360) * 16))]; const windSpeed = Math.round(hass.states[this.config.entity_wind_speed].state); const forecast1 = { date: forecastDate1, condition: this.config.entity_forecast_icon_1, temphigh: this.config.entity_forecast_high_temp_1, templow: this.config.entity_forecast_low_temp_1, }; const forecast2 = { date: forecastDate2, condition: this.config.entity_forecast_icon_2, temphigh: this.config.entity_forecast_high_temp_2, templow: this.config.entity_forecast_low_temp_2, }; const forecast3 = { date: forecastDate3, condition: this.config.entity_forecast_icon_3, temphigh: this.config.entity_forecast_high_temp_3, templow: this.config.entity_forecast_low_temp_3, }; const forecast4 = { date: forecastDate4, condition: this.config.entity_forecast_icon_4, temphigh: this.config.entity_forecast_high_temp_4, templow: this.config.entity_forecast_low_temp_4, }; const forecast5 = { date: forecastDate5, condition: this.config.entity_forecast_icon_5, temphigh: this.config.entity_forecast_high_temp_5, templow: this.config.entity_forecast_low_temp_5, }; const forecast = [forecast1,forecast2,forecast3,forecast4,forecast5]; this.content.innerHTML = ` ${currentConditions} ${temperature} ${getUnit('temperature')}  
  • ${humidity} %
  • ${pressure} ${getUnit('air_pressure')}
  • ${windBearing} ${windSpeed} ${getUnit('length')}/h
  • ${visibility} ${getUnit('length')}
${forecast.map(daily => `
${(daily.date).toString().split(' ')[0]}

${Math.round(hass.states[daily.temphigh].state)}${getUnit('temperature')}
${Math.round(hass.states[daily.templow].state)}${getUnit('temperature')}
`).join('')}

${hass.states[this.config.entity_daily_summary].state}
`; } setConfig(config) { if (!config.entity_current_conditions || !config.entity_humidity || !config.entity_pressure || !config.entity_temperature || !config.entity_visibility || !config.entity_wind_bearing || !config.entity_wind_speed) { throw new Error('Please define entities'); } this.config = config; } // @TODO: This requires more intelligent logic getCardSize() { return 3; } } customElements.define('dark-sky-weather-card', DarkSkyWeatherCard);

黑暗天气卡.CSS

只对CSS文件进行了一个小的变化,所以只会显示更改。更改它的名称以匹配卡并避免与原件的冲突。

.forecast {宽度:100%;边缘:0自动;身高:10em;}
38喜欢

惊人的!感谢分享!这有助于我了解如何进行自定义UI,加上黑暗的天空在这里更准确。

是的,这看起来非常好,但我只是开始尝试leavelace。你能告诉我哪里放在哪里. js. css文件?我跑步hassio。

也是一个链接@arsaboo.他的原稿对学习很有帮助。
谢谢。

1就像

@klogg,这里是Arsaboo的卡的链接:定制动画气象卡为lovelace。指令与他的原始文件有链接以及您需要的动画图标。我建议先工作,然后,如果您仍然兴趣使用Dark Sky作为天气源,请使用我的帖子中的代码作为示例修改它。

要回答您的其他问题,请访问.js和.css文件以/ config / www / custom_ui目录。如果这是您使用的第一个自定义卡,您可能需要创建WWW和Custom_UI目录。

请注意,我的原始帖子中的CSS片段仅显示该文件的一小部分(只是我制作的更改)。更改并非真正必要,因此使用原始的CSS文件工作正常。我在我的配置中重命名。您可以在Dark-Sky-Weather-Card.js代码(包括其目录)中查看对此的引用。

在我的UI-Lovelace文件的顶部,我有以下几个:

资源: -  URL:/local/custom_ui/dark-sky-weather-card.js?v=4类型:js

这告诉UI在哪里找到定制卡。请注意,URL列为/local/custom_ui/dark-sky-weather-card.js。/本地目录是指配置/ www目录。

2喜欢

@ m.p.frankland
奇妙的回复。
谢谢!

编辑:我有一切正常工作。再次感谢。(它是一个很好的学习资源)。
我唯一的投诉是,直到我完全搬到Lovelace,我现在在我的原始UI主屏幕上有大约100个额外的传感器徽章,以满足所有预测的天气条件!
所以我想我不会偶尔使用它。: frowning_face:

@klogg

很高兴听到你的工作。

你是对的,黑暗天空传感器平台确实为预测产生了很多实体。这对我来说从来都不是一个真正的问题,因为我使用的是默认视图的概述,不显示徽章。我想你可以进入自定义,为每个单独设置隐藏属性。这样他们就不会淹没你的主视野了。

1就像

我有了这一点. js. csswww / custom_ui图标也在里面www /图标/ weather_icons /动画,传感器也被加载,所以一切都应该是好的,但这是我在加入我的Lovelace配置后得到的:

它向我看作是css没有出于某种原因加载。忽视了什么?这是在0.74.0b2

使用Firefox时,我有完全相同的问题。Chrome尽量按预期工作。

我没有更新任何HA Beta图像,所以如果这是您问题的一部分,也不能说。它看起来像.css没有应用......

要检查的事情:

  • 使用来自Arsaboo的原始.css文件。(我原来的帖子中的片段只是那个文件的一小部分)
  • 将.css文件重命名为Dark-Sky-Deather-Card.CSS(或在.js文件中在此行中使用的任何内容)
link.href ='/local/custom_ui/dark-sky-weather-card.css';
  • 使用Chrome。我没有在其他浏览器中测试但是如此@docbobo.提到,Firefox和其他浏览器中有知名定制卡的已知问题。我相信在其他线程中有过Firefox的解决方案。

实际上我正在使用Arsaboo的CSS文件,但它不会有所作为。我会去检查Firefox的最可能的解决方法。谢谢你的提示。

这是它看起来的看法:

我已经按照建议启用了定制元素和阴影DOM这里,它根据Firefox修复了一些其他UI问题。禁用这两件事再次修复了天气卡,但随后其他事情不正常工作。

谢谢你的检查。我也启用了那些。我会检查我是否需要它。

好的,似乎Firefox在阴影DOM发生时忽略链接的CSS。直接将样式定义嵌入到JS修复问题中。

1就像

环境javascript_version:最新并且可能将CSS嵌入到JS中至少在Mac上的Safari中固定它。Firefox仍然没有为我工作,我不明白为什么。

至少在Safari上看起来不错。
36.

Firefox肯定在这里工作。你是如何嵌入CSS的?

class DarkSkyWeatherCard extends HTMLElement {set hass(hass) {if (!this.content) {const card = document.createElement('ha-card');/ / card.appendChild(链接);这个.Content = document.createelement('div');this.content.className =“卡”;const style = document.createElement('样式');风格。textContent = ' .clear {clear: both;}(剪)';card.appendChild (this.content);this.appendChild(卡); }
1就像

我刚刚将我的innerhtml分配添加到文件的末尾......

1就像

伟大的,这对Firefox的伎俩做了。现在我很好奇,如果它仍然适用于野生动物园,但我要等到“我以后回家。

不幸的是,整个定制卡片的东西在iOS上不起作用ES5.:皱眉:

应该在javascript_version上完全解决iOS:最新...

1就像

有人能看到我的问题吗?

图像

文件:

谢谢你的帮助