Categoria: Tutorial Sonoff

Encontre aqui os melhores tutoriais sobre sonoff para o apple homekit.

Sonoff T1 – Homekit

Neste tutorial irei falar como deixar o sonoff T1 100% compatível com apple homekit e de forma nativa.

OBS: usei um mac para fazer a mudança do firmware, por isso não posso afirmar que funcionará com outros sistemas operacionais.

Para isso precisaremos alterar seu firmware original para um novo firmware.

1 passo é efetivamente alterar o firwmare para isso precisaremos de um conversor ftdi, abaixo um vídeo de como conectá-lo ao sonoff.

Iremos utilizar o firmware RavenCore, que tem suporte nativo para o T1. abaixo exemplo de comandos para trocar o firmware, eu utilizei mac, mais você pode usar windows ou linux sem problemas, basta mudar a chamada do esptool de acordo com o sistema operacional (instruções de comandos)

  1. backup fo firwmare original.
    esptool.py –port /dev/tty.usbserial-A50285BI read_flash 0x00000 0x100000 image1M.bin
  2. Zerar a memória do firwmare atual.
    esptool.py –port /dev/tty.usbserial-A50285BI erase_flash
  3. Enviar o novo firmware.
    esptool.py -p /dev/tty.usbserial-A50285BI –baud 115200 write_flash -fs 1MB -fm dout -ff 40m 0x0 rboot.bin 0x1000 blank_config.bin 0x2000 main.bin

Após a conclusão do processo, basta desligar e ligar o T1, ele irá gerar um novo ponto de acesso wi-fi, basta conectar neste ponto que irá abrir uma tela para inserir os dados da sua rede wifi. Como no exemplo do vídeo abaixo,

Pronto agora basta adiciona-lo ao apple homekit como qualquer outro dispositivo, abaixo o código de pareamento.

Pairing code image

Agora precisamos configura-lo para que os botões físicos do interruptor funcionem como antigamente. para isso iremos precisar do aplicativo EVE

Ao abrir o EVE iremos procurar o dispositivo que foi adicionado ao homekit.

Teremos algumas opções como abaixo, não se preocupe, vamos alterar apenas alguns itens.

  1. Item que devemos alterar é o Device Type iremos deixar a opção 2, isso quer dizer que estamos selecionado um sonoff com duas saídas.
  2. O proximo item que vamos alterar é o External Toggle 1 e 2 , vamos setar o valor para 1 , ao fazer isso estamos habilitando a função dos botões externos do interruptor. Basta agora aguardar uns 10 segundos enquanto a função é ativada.

Pronto você acabou de configurar o T1 para ser 100% compatível com homekit de forma nativa.

Dúvidas? acesse nosso fórum!! https://www.homekit.com.br/forums/

Sonoff Basic – Trocando o firmware original

Neste tutorial irei ensinar como trocar o firmware original do sonoff para um firmware com suporte a Apple Homekit.

Para integrar nativamente sonoff ao homekit sem precisar do homebridge, precisaremos alterar o firmware padrão, temos algumas alternativas de firmware na internet, neste artigo irei falar de algumas delas.

Sonoff Homekit (https://github.com/Gruppio/Sonoff-Homekit)
Dispositivos compatíveis.
Sonoff BasicSonoff SlampherSonoff S26

Existe um outro firmware chamado – RavenCore, o bom deste firmware é que ele permite uma gama muito maior de dispositivos sonoff assim como algumas configurações avançadas utilizando o aplicativo Eve

O processo para trocar o firmware não é uma tarefa fácil para muitos pois envolve solda, pinos, comandos, porém com um pouco de paciência e leitura é possível ser feito.

Para isso precisaremos de alguns componentes eletrônicos e alguns softwares, Vou deixar abaixo o que precisei não estou ganhando comissão da loja, mais pelo menos fica mais fácil para comprar tudo no mesmo lugar!

Normalmente o pessoal solda alguns pinos no sonoff para fazer o flash, como eu não tenho a mínima prática para solda, resolvi usar apenas os jumpers sem solda mesmo.

  1. Módulo Conversor FTDI FT232RL USB/Serial (esse é o cara responsável por fazer seu computador falar com o modulo do sonoff)
  2. Cabo Mini USB 2.0 V8 – 1,80m
  3. Kit Jumper Premium 20cm – Macho / Fêmea (cabos utilizados para conectar o modulo conversor na placa sonoff)

Bom o primeiro passo é desmontar o sonoff ele vai ficar com essa aparência.
depois precisamos identificar os pinos que iremos ligar o nosso modulo conversor, que são eles.

alt text

Próximo passo é conectar os jumpers (cabos) entre o sonoff e o conversor mantendo a seguinte ordem. Lembre-se como não estamos utilizando solda, evite de mover a placa na hora do flash para não gerar nenhum problema.

Importante o modulo conversor tem duas tensões 5v e 3.3v , não conecte na 5v , pois você irá queimar seu sonoff.

sonoff 3.3v ————–> conversor 3.3v
sonoff gnd —————> conversor gnd
sonoff tx ——————> conversor rx
sonoff rx ——————> conversor tx

Pressionando o botão do sonoff conecte o conversor na porta USB do seu computador, aguarde 5s antes de soltar o botão, assim o sonoff irá inicializar em modo flash.

Para enviar o firmware ao sonoff existem alguns softwares como esptool que roda tanto em linux quanto windows e mac, porém o site HomekitItalia fez um software para windows que facilita muito a vida. Chamado Homekititalia flasher v1.0

Com ele você pode fazer o backup fo firmware original, instalar o tasmota, instalar o ravencore, tudo de forma bem mais simples, abaixo um video de como utilizar o software


Após o upload do novo firmware basta configurar o sonoff que estará pronto para ser utilizado com o apple homekit de forma nativa.

Em breve irei escrever tutoriais de como trocar o firmware de outros sonoff como por exemplo o POW R2, o Sonoff 4CH pro, e claro dos interruptores T1.

Sonoff – HomeBridge

Para integrar interruptores sonoff com firmware original, você irá precisar do homebrige como ponte , veja neste artigo como instalar o homebridge.

Após instalar o homebridge, você irá precisar configura-lo para conectar-se a api da ewlink através do plugin homebridge-ewlink-max.

Como instalar o homebridge-ewelink-max

Homebridge plugin to control Sonoff relays with OEM firmware. It uses the same API as the iOS app to communicate with your devices.

The platform will dynamically add/remove devices based on what is configured in your eWeLink account.

It has been tested with the Sonoff basic relays. I have performed testing with up to two relays associated to my account.

The plugin will only support one eWeLink account.

It is possible to continue to use the OEM functionality (eWeLink app, Google Home integration); this plugin requires no modification to the relay’s firmware.

Why max?

This is a fork of homebridge-ewelink, which is not being actively updated. There is another package named homebridge-ewelin-plus which is not updated for 6 months at the time of writing. The name is inspired by Apple’s naming convention.

This fork have the following notable changes / improvements:

  • Support login with phone number / email and password, which save your time from obtaining the authentication token with Charles once in a while.
  • Support sending heartbeat on the WebSocket connection, which greatly reduce the interval of reconnects, hence better stability.
  • Support obtaining the correct API / WebSocket API host automatically, so you don’t need to obtain these information with Charles.

Shortcomings

The code is of suboptimal quality. It was a quick-and-dirty plugin; feel free to contribute & improve.

Steps to install / configure

Assuming that you’ve already downloaded the eWeLink app on your iOS device & have configured it:

  1. Install the plugin
sudo npm -g install homebridge-ewelink-max
  1. Add to the platforms[] section of config.json.
  • phoneNumber – The login phone number of your ewelink account, do not include this if you login with email
  • email – The login email of your ewelink account, do not include this if you login with phone number
  • password – Your ewelink account login password
  • imei – This can be any valid UUID, get one with an online generator
  1. Restart Homebridge

Sample config.json

{
    "bridge": {
        "name": "Homebridge",
        "username": "XX:XX:XX:XX:XX:XX",
        "port": 51826,
        "pin": "123-45-678"
    },
    
    "description": "Your description here",

    "accessories": [
    ],

    "platforms": [
        {
            "platform" : "eWeLink",
            "name" : "eWeLink",
            "phoneNumber" : "+12345678901",
            "password" : "your-login-password",
            "imei" : "01234567-89AB-CDEF-0123-456789ABCDEF"
        }
    ]
}

If you use email login, the platform section should look like this:

        {
            "platform" : "eWeLink",
            "name" : "eWeLink",
            "email" : "your-email@example.com",
            "password" : "your-login-password",
            "imei" : "01234567-89AB-CDEF-0123-456789ABCDEF"
        }

A note on login session

An authentication token is generated every time your device’s app logs in to the eWeLink service.

You can only have one authentication token per user account.

Therefore if you use the HomeKit app and eWeLink app at the same time, they will fight each other for the login session. They should both work individually. You can leave homebridge running when using the eWeLink app.

To avoid being logged off from the eWeLink app

  1. Create another account
  2. Then log in with the new account on another mobile device (you have to keep both accounts connected and with eWeLink on the screen).
  3. Go to your eWeLink, select your Sonoff device and share it with the other account.
  4. A popup should appear on the other mobile device, accept it.
  5. Use the second account as your plugin login (and never use this account on eWeLink anymore to avoid being logged off)
  6. Be happy and never get a “session expired” message again.

Troubleshooting

I’ve attempted to make the logging as useful as possible. If you have any suggestions, please open an issue on GitHub.

Sample logging

[12/13/2017, 9:39:05 PM] [eWeLink] A total of [1] accessories were loaded from the local cache
[12/13/2017, 9:39:05 PM] [eWeLink] Requesting a list of devices from eWeLink HTTPS API at [https://us-api.coolkit.cc:8080]
[12/13/2017, 9:39:06 PM] [eWeLink] eWeLink HTTPS API reports that there are a total of [1] devices registered
[12/13/2017, 9:39:06 PM] [eWeLink] Evaluating if devices need to be removed...
[12/13/2017, 9:39:06 PM] [eWeLink] Verifying that all cached devices are still registered with the API. Devices that are no longer registered with the API will be removed.
[12/13/2017, 9:39:06 PM] [eWeLink] Device [Fan] is regeistered with API. Nothing to do.
[12/13/2017, 9:39:06 PM] [eWeLink] Evaluating if new devices need to be added...
[12/13/2017, 9:39:06 PM] [eWeLink] Device with ID [XXXXXXX] is already configured. Ensuring that the configuration is current.
[12/13/2017, 9:39:06 PM] [eWeLink] Updating recorded Characteristic.On for [Fan] to [false]. No request will be sent to the device.
[12/13/2017, 9:39:06 PM] [eWeLink] Setting power state to [off] for device [Fan]
[12/13/2017, 9:39:06 PM] [eWeLink] API key retrieved from web service is [XXXXXXX]
[12/13/2017, 9:39:06 PM] [eWeLink] Connecting to the WebSocket API at [wss://us-long.coolkit.cc:8080/api/ws]
[12/13/2017, 9:39:06 PM] [eWeLink] Sending login request [{"action":"userOnline","userAgent":"app","version":6,"nonce":"151321914688000","apkVesrion":"1.8","os":"ios","at":"XXXXXXX","apikey":"xxxxxxx","ts":"1513219146","model":"iPhone10,6","romVersion":"11.1.2","sequence":1513219146880}]
[12/13/2017, 9:39:06 PM] [eWeLink] WebSocket messge received:  {"error":0,"apikey":"xxxxxxx","config":{"hb":1,"hbInterval":145},"sequence":"1513219146880"}

Hey Siri, turn on the fan

[12/13/2017, 9:39:09 PM] [eWeLink] Setting power state to [on] for device [Fan]
[12/13/2017, 9:39:09 PM] [eWeLink] WebSocket messge received:  {"error":0,"deviceid":"XXXXXXX","apikey":"XXXXXXX","sequence":"1513219149620"}
[12/13/2017, 9:39:11 PM] [eWeLink] Setting power state to [off] for device [Fan]
[12/13/2017, 9:39:12 PM] [eWeLink] WebSocket messge received:  {"error":0,"deviceid":"XXXXXXX","apikey":"XXXXXXX","sequence":"1513219151735"}

The plugin will also listen for announcements via a persistent web socket. This allows you to control the device from the likes of Google Home & have Homebridge be kept up-to-date

Hey Google, turn on the fan

[12/13/2017, 9:41:50 PM] [eWeLink] Update message received for device [XXXXXXX]
[12/13/2017, 9:41:50 PM] [eWeLink] Updating recorded Characteristic.On for [Fan] to [true]. No request will be sent to the device.
[12/13/2017, 9:41:50 PM] [eWeLink] Setting power state to [on] for device [Fan]
[12/13/2017, 9:41:50 PM] [eWeLink] WebSocket messge received:  {"error":0,"deviceid":"XXXXXXX","apikey":"XXXXXXX","sequence":"1513219310003"}

Feito isso, basta adicionar o homebridge ao seu aplicativo apple casa.

  1. Dirija-se ao seu dispositivo iOS e inicie o aplicativo CASA
  2. Toque no botão Adicionar no canto superior direito da tela (parece um sinal de mais).
  3. Toque em Adicionar acessório .
  4. Toque no acessório Homebridge (o meu acabou de se chamar Homebridge).
  5. Você verá um alerta que diz: “Este acessório não é certificado e pode não funcionar de maneira confiável com o HomeKit”. toque em Adicionar mesmo assim .
  6. Toque em Inserir código manualmente na parte inferior da tela.
  7. Digite o código do HomeKit para o seu acessório Homebridge. Você pode encontrá-lo na janela do Terminal abaixo do texto que diz “Digitalize este código com seu aplicativo HomeKit no seu dispositivo iOS para parear com o Homebridge”.
  8. Adicione seu acessório Homebridge e toque em Avançar .