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

 找回密码
 立即注册
查看: 3736|回复: 17

[教程系列] 每天将美好的句子推送至手机通知和TTS

[复制链接]

20

主题

218

帖子

928

积分

高级会员

Rank: 4

积分
928
金钱
710
HASS币
10
发表于 2023-1-29 17:23:03 | 显示全部楼层 |阅读模式
本帖最后由 damonwe 于 2023-1-31 23:24 编辑

最近折腾ios通知,忽然想找一个每日一句有意境的话推送到我的手机。翻了一阵找到了一个开源项目:一言。一言开发者中心 | 用代码表达言语的魅力,用代码书写山河的壮丽。 (hitokoto.cn)
这是他们的官网,github上也有。

有兄弟说写的不够详细,我就重新写一下吧,大家有问题再评论。
flow.png
这是我的流程,每天8:30或者在苹果手机快捷指令操作都可以激活。中间的都是一些时间和天气的参数,后面是获取“一言”的接口,最后家里的音箱播放,同时手机通知。如果是9-23点之间,两个都推送,如果不是,只在手机通知不播放音频。

flows.rar (2.96 KB, 下载次数: 83)

重点看一下获取一言的接口:http request节点
http.png
按照我的设置就可以。

如果用debug接收,会出现如下对象:
{"id":7690,
"uuid":"xxxx",
"hitokoto":"你在我规划的航程上,我在你投射的视线里。",
"type":"j","from":"歌曲《人生苦短》歌词",
"from_who":"周佳顺",
"creator":"xiongfie ng",
"creator_uid":xxxx,
"reviewer":xxxx,
"commit_from":"web",
"created_at":"xxxx",
"length":20}

那我们就需要用function来截取某些我们需要的句子。
var word = msg.payload;
var hitokoto = word.hitokoto;

msg.word = hitokoto;  //这里我用msg.word而不是msg.payload,是因为我前面的数据太多了,这里进行了区分,后面调取也是调取msg.word,而不是msg.payload。
return msg;



回复

使用道具 举报

20

主题

218

帖子

928

积分

高级会员

Rank: 4

积分
928
金钱
710
HASS币
10
 楼主| 发表于 2023-1-29 17:24:20 | 显示全部楼层
本帖最后由 damonwe 于 2023-2-3 16:24 编辑

目前实测好像有时候会出现undefind。给流程加一个纠错机制就行,就是用switch判断是否为undefind,如果是就连接到开始处重新获取一遍。
回复

使用道具 举报

146

主题

2266

帖子

6998

积分

元老级技术达人

积分
6998
金钱
4727
HASS币
30
发表于 2023-1-29 18:10:33 | 显示全部楼层
damonwe 发表于 2023-1-29 17:24
获取的节点是http request

能不能稍微详细点,我们是新手
回复

使用道具 举报

1

主题

29

帖子

181

积分

注册会员

Rank: 2

积分
181
金钱
152
HASS币
0
发表于 2023-1-29 22:44:15 | 显示全部楼层
兄弟,有详细教程吗?我想通过ipad播报,还有每日一句,具体怎样操作?我想用one 一个app里面的句子,有api接口。
回复

使用道具 举报

33

主题

2196

帖子

5838

积分

论坛元老

Rank: 8Rank: 8

积分
5838
金钱
3642
HASS币
60
QQ
发表于 2023-1-30 01:16:26 | 显示全部楼层
bugensui 发表于 2023-1-29 18:10
能不能稍微详细点,我们是新手
nr里直接导入流就好了
[{"id":"784792a75b4e5ec7","type":"tab","label":"测试","disabled":false,"info":"","env":[]},{"id":"935c1a21a3ec26bd","type":"http request","z":"784792a75b4e5ec7","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://v1.hitokoto.cn/","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":280,"y":100,"wires":[["1072c60867fe065e"]]},{"id":"e5bb37d521083863","type":"inject","z":"784792a75b4e5ec7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":100,"wires":[["935c1a21a3ec26bd"]]},{"id":"c825dd90dc9169f9","type":"debug","z":"784792a75b4e5ec7","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":100,"wires":[]},{"id":"1072c60867fe065e","type":"function","z":"784792a75b4e5ec7","name":"筛选","func":"var word = msg.payload.hitokoto;\n\nmsg.payload = word;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":100,"wires":[["c825dd90dc9169f9"]]},{"id":"aef85895ff6b9cec","type":"comment","z":"784792a75b4e5ec7","name":"1.1、一言推送","info":"","x":110,"y":40,"wires":[]}]
我不生产技术,我只是技术的搬运工。
回复

使用道具 举报

146

主题

2266

帖子

6998

积分

元老级技术达人

积分
6998
金钱
4727
HASS币
30
发表于 2023-1-30 11:40:03 | 显示全部楼层
zxyny1989 发表于 2023-1-30 01:16
nr里直接导入流就好了

好的,这个是每天更新一次对吧
回复

使用道具 举报

33

主题

2196

帖子

5838

积分

论坛元老

Rank: 8Rank: 8

积分
5838
金钱
3642
HASS币
60
QQ
发表于 2023-1-30 22:44:49 | 显示全部楼层
bugensui 发表于 2023-1-30 11:40
好的,这个是每天更新一次对吧

更新看平台,我测试了下,好像几秒更新一次
我不生产技术,我只是技术的搬运工。
回复

使用道具 举报

146

主题

2266

帖子

6998

积分

元老级技术达人

积分
6998
金钱
4727
HASS币
30
发表于 2023-1-30 23:02:43 | 显示全部楼层
zxyny1989 发表于 2023-1-30 22:44
更新看平台,我测试了下,好像几秒更新一次

我导入了。但是没有反应,不知道是不是姿势不对
回复

使用道具 举报

33

主题

2196

帖子

5838

积分

论坛元老

Rank: 8Rank: 8

积分
5838
金钱
3642
HASS币
60
QQ
发表于 2023-1-30 23:33:03 | 显示全部楼层
bugensui 发表于 2023-1-30 23:02
我导入了。但是没有反应,不知道是不是姿势不对

看nr右侧的输出啊。那你用这个流吧,直接在ha生成实体。1秒一更新的,我用的1分钟
[{"id":"784792a75b4e5ec7","type":"tab","label":"测试","disabled":false,"info":"","env":[]},{"id":"935c1a21a3ec26bd","type":"http request","z":"784792a75b4e5ec7","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://v1.hitokoto.cn/","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":280,"y":100,"wires":[["1072c60867fe065e"]]},{"id":"e5bb37d521083863","type":"inject","z":"784792a75b4e5ec7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":100,"wires":[["935c1a21a3ec26bd"]]},{"id":"c825dd90dc9169f9","type":"debug","z":"784792a75b4e5ec7","name":"debug 4","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":60,"wires":[]},{"id":"1072c60867fe065e","type":"function","z":"784792a75b4e5ec7","name":"筛选","func":"var word = msg.payload.hitokoto;\n\nmsg.payload = word;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":100,"wires":[["c825dd90dc9169f9","4c26af6b20879f42"]]},{"id":"aef85895ff6b9cec","type":"comment","z":"784792a75b4e5ec7","name":"1.1、一言推送","info":"","x":110,"y":40,"wires":[]},{"id":"4c26af6b20879f42","type":"ha-entity","z":"784792a75b4e5ec7","name":"一言","server":"5d5b63f8.ca1c8c","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"yiyan"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload","stateType":"msg","attributes":[{"property":"","value":"string","valueType":"global"}],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":590,"y":100,"wires":[[]]},{"id":"5d5b63f8.ca1c8c","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]



我不生产技术,我只是技术的搬运工。
回复

使用道具 举报

146

主题

2266

帖子

6998

积分

元老级技术达人

积分
6998
金钱
4727
HASS币
30
发表于 2023-1-31 11:32:56 | 显示全部楼层
zxyny1989 发表于 2023-1-30 23:33
看nr右侧的输出啊。那你用这个流吧,直接在ha生成实体。1秒一更新的,我用的1分钟

好的,谢谢大佬
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-22 13:32 , Processed in 0.738046 second(s), 35 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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