『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 172|回复: 2

[经验分享] 【已解决】请教在NR的函件中如何把这些用变量在MESSAG...

[复制链接]

11

主题

68

帖子

509

积分

高级会员

Rank: 4

积分
509
金钱
441
HASS币
0
发表于 2024-5-2 18:28:57 | 显示全部楼层 |阅读模式
本帖最后由 lambilly 于 2024-5-3 18:42 编辑
 {{ states("sensor.zzwtime") }}好,现在是北京时间:{{ states("sensor.time")
        }},客厅温度为{{states("sensor.keting_temperature")|round
        }}度、客厅湿度为{{states("sensor.zhi_neng_yao_kong_humidity")|round
        }}%,今天天气{{state_attr("weather.wo_de_jia","forecast_hourly")
        }},{{state_attr("weather.wo_de_jia","forecast_minutely")
        }},室外温度{{states("sensor.wo_de_jia_wen_du")|round }}度。
var weather = msg.payload;
var indoor_temperature = Math.round(msg.indoor_temperature);
var temperature = msg.data.attributes.temperature;
var rain = msg.data.attributes.rain;
var feelst = msg.data.attributes.feelst;
var wind_direct = msg.data.attributes.direct;
var speed = msg.data.attributes.speed;
var wind = msg.data.attributes.power;
var aqi = msg.aqi;
var aqi_word = "";
var week = msg.holiday_data.attributes.data.week;
var tomorrow_state = msg.holiday_data.attributes.data.tomorrow_state;
var lunar = msg.holiday_data.attributes.data.lunar
if (aqi > 300 ){
    aqi_word = "严重污染";
    }
if (aqi > 200 ){
    aqi_word = "重度污染";
    }    
if (aqi > 150 ){
    aqi_word = "中度污染";
    }   
if (aqi > 100 ){
    aqi_word = "轻度污染";
    }       
if (aqi > 50 ){
    aqi_word = "良";
    }  
if (aqi > 0 ){
    aqi_word = "优";
    }      
msg.payload = "主人," + msg.Hello_Word + "现在是" + msg.datetime + ","+week+",农历:"+lunar+"。明天是"+tomorrow_state+"。现在天气:" + weather + ",气温:" + temperature + "℃,"+wind+",体感温度:"+feelst+"℃,室内湿度:" + msg.indoor_humidity + "%,室内温度:" + indoor_temperature + "℃,空气质量:"+aqi_word+"!";
return msg;


回复

使用道具 举报

8

主题

157

帖子

893

积分

高级会员

Rank: 4

积分
893
金钱
736
HASS币
0
发表于 2024-5-3 16:41:33 | 显示全部楼层
前面通过《current state》获取变量数据,然后function调用变量?
类似本地窗帘状态的函数如下:
if(msg.data.attributes["curtain.current_position"]>88 ){
   msg.payload = "已开"
   return msg;
}else{
   msg.payload = "已关"
   return msg;
}
回复

使用道具 举报

11

主题

68

帖子

509

积分

高级会员

Rank: 4

积分
509
金钱
441
HASS币
0
 楼主| 发表于 2024-5-3 18:40:08 | 显示全部楼层
hejie127 发表于 2024-5-3 16:41
前面通过《current state》获取变量数据,然后function调用变量?
类似本地窗帘状态的函数如下:
...

明白了,问一下,有没有 elif ? 是不是和HA一样多种判断,从上至下。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-19 12:43 , Processed in 0.817559 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表