Ligar sonoff s20 com estado da bateria

Boas malta, estive a flashar um sonoff s20 para poder ligar o carregador do telemóvel Mediante a carga do mesmo.
Já uso o zanzito para obter a informação da matéria. Mas agora esta-me a falhar algo no código que sinceramente não faço ideia. Alguém me poderia dar uma dica do que está mal?

  - alias: Ligar sonoff Bateria abaixo dos 10 por cento
    initial_state: true
    trigger:
      platform: numeric_state
      entity_id:
        - sensor.bateria_estacao_de_radio
      below: 10
    condition:
      - condition: template
        value_template: '{{ states.input_boolean.battery_notifications.state == "on" }}'
    action:
      - service: switch.turn_on
        entity_id: switch.carregar_bateria_s3

O meu ficheiro yaml:

homeassistant:

###############################################################################
#                                                                             #
#                             C U S T O M I Z E                               #
#                                                                             #
###############################################################################
  customize:
    switch.carregar_bateria_s3:
      friendly_name: Carregar Telemovel
      icon: mdi:power

###############################################################################
#                                                                             #
#                                 S E N S O R S                               #
#                                                                             #
############################################################################### 
sensor:
  
  - platform: mqtt
    state_topic: "zanzito/s3/battery_level"
    name: "Bateria Estação de Rádio"
    unit_of_measurement: '%'
    retain: true

###############################################################################
#                                                                             #
#                           A U T O M A Ç Õ E S                               #
#                                                                             #
###############################################################################
automation:

       
  - alias: Ligar sonoff Bateria abaixo dos 10 por cento
    initial_state: true
    trigger:
      platform: numeric_state
      entity_id:
        - sensor.bateria_estacao_de_radio
      below: 10
    condition:
      - condition: template
        value_template: '{{ states.input_boolean.battery_notifications.state == "on" }}'
    action:
      - service: switch.turn_on
        entity_id: switch.carregar_bateria_s3
        

###############################################################################
#                                                                             #
#                           N O T I F I E R S                                 #
#                                                                             #
###############################################################################  

###############################################################################
#                                                                             #
#                                 G R O U P S                                 #
#                                                                             #
############################################################################### 
group:

  Switch Bateria S3:
    control: hidden
    entities:
      - switch.carregar_bateria_s3
  
  Bateria da Estação:
    control: hidden
    entities:
      - sensor.bateria_estacao_de_radio
      
  Automações S3:
    control: hidden
    entities:
      - automation.ligar_carregador_S3
      - automation.desligar_carregador_S3

  Estação:
    view: yes
    name: Bateria do Rádio
    entities:
      - group.switch_Bateria_S3
      - group.bateria_da_estacao
      - group.automacoes_s3

Estou a fazer os testes finais mas em princípio já tenho o código. Depois de testado eu partilho com o pessoal para também ver se está bem construído. Obrigado

Vou deixar o código que estou a usar para ligar desligar o sonoff s20 com o estado da bateria do meu smartphone

  - alias: Liga tomada para carregar bateria
    initial_state: true
    trigger:
      platform: numeric_state
      entity_id: sensor.bateria_estacao_de_radio
      below: 10
    action:
      - service: switch.turn_on
        entity_id: switch.carregar_bateria_s3
        
  - alias: Desliga tomada apos carregar bateria
    initial_state: true
    trigger:
      platform: numeric_state
      entity_id: sensor.bateria_estacao_de_radio
      above: 99
    action:
      - service: switch.turn_off
        entity_id: switch.carregar_bateria_s3

Espero que vos seja útil. Cumps

1 Like

Este tópico foi automaticamente fechado 90 dias após a última resposta. Novas respostas não são permitidas.