我啃了下pyscript,看不懂,也没找到个简单的教程,不会用啊,我有一点点基础,能写个简单的爬虫但是类似这种@xxxxx这种就不太明白了。大佬有教程么,推荐下,谢谢,我用gpt3.5写出来的,调用的时候提示调用服务 python_script.提醒 失败。 Service python_script.提醒 does not match format <domain>.<name> for dictionary value @ data['sequence'][0]['service']. Got 'python_script.提醒'
也不知道如何调用,我保存到文件夹下,提醒.py
倒是直接生成个服务调用,但是调用的不对。
# Import the necessary modules
import time
def remind_before_light_off(hass, entity_id, original_volume):
# Set initial countdown
current_countdown = 30
# Loop through the countdown
while current_countdown > 0:
# Remind every 5 minutes
if current_countdown % 5 == 0:
hass.services.call("media_player", "volume_set", {"entity_id": entity_id, "volume_level": 0.29})
hass.services.call("tts", "google_translate_say", {"entity_id": entity_id, "message": f"还有{current_countdown}分钟关灯啦,宝贝们抓紧呀!"})
time.sleep(5)
hass.services.call("media_player", "volume_set", {"entity_id": entity_id, "volume_level": 0.29})
# Decrement the countdown
current_countdown -= 1
# Wait for 1 minute
time.sleep(60)
# When countdown is finished, reset the volume
hass.services.call("media_player", "volume_set", {"entity_id": entity_id, "volume_level": original_volume})
# Call the function to set up the reminder
remind_before_light_off(hass, "media_player.ke_ting", 0.29)