Vou então apresentar o meu projecto, embora muito básico (ainda muito verde nestas andanças) e ainda sem testar pois não tenho ainda o material. Mas como gostava de ganhar o raspberry pi quem não arrisca não petisca.
Então começamos por flashar um sonoff s20 conforme toturial do forum (📑 Como flashar de forma simples qualquer ESP)
Depois disso vamos configurar o switch no configuration.yaml com o seguinte código:
switch:
- platform: mqtt
name: "Árvore de Natal"
state_topic: "stat/arvorenatal/POWER"
command_topic: "cmnd/arvorenatal/power"
availability_topic: "tele/arvorenatal/LWT"
payload_available: "Online"
payload_not_available: "Offline"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
Como uso o packages vamos criar um ficheiro arvore_natal.yaml com o seguinte código
homeassistant:
###############################################################################
# #
# C U S T O M I Z E #
# #
###############################################################################
customize:
script.arvore_natal:
friendly_name: Ligar e desligar árvore de natal automático
icon: mdi:pine-tree
switch.arvore_de_natal:
friendly_name: Ligar Pinheirinho
icon: mdi:power
automation.ligar_pinheiro:
icon: mdi:home-automation
automation.Pinheirinho_ligado:
icon: mdi:bell-ring
automation.Pinheirinho_desligado:
icon: mdi:bell-ring
binary_sensor.switch_158d05aa37d:
icon: mdi:light-switch
automation.interruptor_para_ligar_arvore_single:
icon: mdi:light-switch
automation.interruptor_para_desligar_arvore_double:
icon: mdi:light-switch
###############################################################################
# #
# S C R I P T S #
# #
###############################################################################
script:
arvore_natal:
sequence:
- service: switch.turn_on
entity_id: switch.arvore_de_natal
- delay: '06:00:00'
- service: switch.turn_off
entity_id: switch.arvore_de_natal
###############################################################################
# #
# A U T O M A Ç Õ E S #
# #
###############################################################################
automation:
#automation zigbee switch
- alias: Interruptor para ligar árvore single
initial_state: true
trigger:
- platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d05aa37d
click_type: single
action:
- service: switch.turn_on
data:
entity_id: switch.arvore_de_natal
- alias: Interruptor para desligar árvore double
initial_state: true
trigger:
- platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d05aa37d
click_type: double
action:
- service: switch.turn_off
data:
entity_id: switch.arvore_de_natal
#automação ligar pinheirinho
- alias: Ligar Pinheiro
initial_state: true
trigger:
- platform: time
at: '18:00:00'
action:
- service: script.turn_on
data:
entity_id: script.arvore_natal
#notificações
- alias: Pinheirinho ligado
initial_state: true
trigger:
- platform: state
entity_id: switch.arvore_de_natal
from: 'off'
to: 'on'
action:
service: notify.Telegram
data:
title: “Pinheiro Ligado”
message: “O pinheirinho está ligado”
data:
photo:
url: https://dl.dropboxusercontent.com/s/2v4dkslcpohfey2/IMG_20181203_133505.jpg?dl=0
caption: "O pinheirinho está ligado"
- alias: Pinheirinho desligado
initial_state: true
trigger:
- platform: state
entity_id: switch.arvore_de_natal
from: 'on'
to: 'off'
action:
service: notify.Telegram
data:
title: “Pinheiro Desligado”
message: “O pinheirinho foi desligado”
data:
photo:
url: https://dl.dropboxusercontent.com/s/gcezyt8zg8pmquy/IMG_20181203_133412.jpg?dl=0
caption: "O pinheirinho foi desligado"
###############################################################################
# #
# N O T I F Y #
# #
###############################################################################
notify:
- name: telegram
platform: telegram
chat_id: !secret chat_ids_bruno
telegram_bot:
- platform: polling
api_key: !secret api_key_bruno
allowed_chat_ids:
- !secret chat_ids_bruno
###############################################################################
# #
# G R O U P S #
#
###############################################################################
group:
Ligar iluminação manual:
control: hidden
entities:
- switch.arvore_de_natal
Ligar iluminação automático:
control: hidden
entities:
- script.arvore_natal
Interruptor ligar desligar Árvore:
control: hidden
entities:
- automation.interruptor_para_ligar_arvore_single
- automation.interruptor_para_desligar_arvore_double
Automação ligar Árvore:
control: hidden
entities:
- automation.ligar_pinheiro
Notificar acender da Árvore:
control: hidden
entities:
- automation.Pinheirinho_ligado
- automation.Pinheirinho_desligado
Interruptor da Árvore:
control: hidden
entities:
- binary_sensor.switch_158d05aa37d
Iluminação de Natal:
view: yes
icon: mdi:pine-tree
name: Iluminação de Natal
entities:
- group.ligar_iluminacao_manual
- group.ligar_iluminacao_automatico
- group.interruptor_ligar_desligar_arvore
- group.automacao_ligar_arvore
- group.notificar_acender_da_arvore
- group.interruptor_da_arvore
vamos ficar com a seguinte configuração:
As notificações vão ficar assim:
Material usado: https://mauser.pt/catalog/advanced_search_result.php?keywords=sonoff+s20
Espero que seja do agrado pessoal. Muito obrigado por tudo.