Turn on iPad screen with a sensor for Dashboard

@remsta As long as you have a sensor in HA you can put it into HK (step 3 as per the OP) and then turn on notifications based on that sensor. When in guided access the iPad doesn’t show the notification- it just wakes up.

@mkormendy set your preference in the guided access settings

So the sensors show up only in HA as a Binary sensor - does it have to be HK?

Yeah it’s easy. As above, put this in your configuration.yaml, restart, wait a few minutes and it will show up in the Home app on the ipad:

homekit:
  filter:
    include_entities:
      - binary_sensor.name_of_sensor

@fmon So I don’t really want to use the home app - I wanted to use the HA app…

Are you saying, I just add that in, get it to show as a device in home but then I never actually need to use home- is that right?

You set up the notifications on the ipad in the home app- you only have to do it once. Step #3 in the original post… then every time the sensor is tripped the ipad will get a notification (which if it’s in guided access will just wake it up).

When I am adding Homekit - do I add homekit controller or homekit?

I selected Homekit and I selected Binary Sensor, Alarm and Cameras - it has now created a QR code for each camera as well as one for “HASS Bridge:xxxx” I am assuming this is the one I need to add to homekit?

homekit, not the homekit controller. It sounds like you haven’t paired yet- follow the dirxns in the docs!

I’ve set this up and it’s working as expected apart from one important aspect; the screen does not turn off again. No matter what settings I use it does not automatically turn off in guided access. In normal mode it works as it should. Anyone with the same issues or suggestions?

I have the same problem. I had previously updated the ipad to version 15.1, is it perhaps because of this?

I have, yes. But I didn’t try before so can’t say if that is the reason.

I had the same issue. This is a bug introduced in iPadOS 15.1. I downgraded to iPadOS 15.0.2 and everything works again.

1 Like

Hi!

I just wanted to present my iPad wakeup solution.
The basic idea is that an ESP32 emulates a virtual Bluetooth Low Energy (BLE) keyboard to send the “ESC” key whenever motion is detected, i.e. a GPIO pin toggles.
The solution uses ESPHome for the ESP32 firmware.
Very nice: with ESPHome you also have the possibility to do OTA FW upgrades.

ESPHome YAML file:

esphome:
  name: blekeyboard-eg
  platform: ESP32
  board: esp32dev
  platformio_options:
    build_flags: 
      - -DUSE_NIMBLE  
  includes:
    - esp32_ble_keyboard.h
  libraries:
    - "NimBLE-Arduino"
    - "t-vk/ESP32 BLE Keyboard"  

# Enable logging
logger:

# Enable Home Assistant API
api:

 
ota:
  password: "xxxxxxxxxxxxxxxxxxxxxxxxxx"

wifi:
  ssid: "SSID"
  password: "PASSPHRASE"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Blekeyboard-Eg Fallback Hotspot"
    password: "XYZXYZXYZ"

captive_portal:

switch:
  - platform: gpio
    name: "Status LED"
    id: status_led
    pin:
      # Built in LED
      number: GPIO5
      inverted: false
    on_turn_on:
      - delay: 50ms
      - switch.turn_off: status_led

custom_component:
  - lambda: |-
      return {new Esp32BLEKeyboard(App.get_name(), "ESPHome")};
    components:
      - id: ble_keyboard
        # The variable type is just Component, so a static_cast<Esp32BLEKeyboard *> is needed everywhere

# Example configuration entry
binary_sensor:
  - platform: gpio
    name: "Pin GPIO23"
    pin: GPIO23
    on_press:
      - switch.turn_on: status_led
      #- lambda: ble_keyboard_text->publish_state({KEY_ESC, 0});
      - lambda: (static_cast<Esp32BLEKeyboard *>(ble_keyboard))->bleKeyboard.write(KEY_ESC);
  - platform: custom
    lambda: |-
      auto kbd = static_cast<Esp32BLEKeyboard *>(ble_keyboard);
      return {kbd->connected_binarysensor};
    binary_sensors:
      - name: "Connected"
      
text_sensor:
  - platform: custom
    lambda: |-
      auto kbd = static_cast<Esp32BLEKeyboard *>(ble_keyboard);
      return {kbd->textsensor};
    text_sensors:
      - id: ble_keyboard_text
    # Use with lambda: ble_keyboard_text->publish_state("Hello, World!")
    # Note: media keys are special, they are are of type MediaKeyReport and can't be converted to strings

After creating the ESPHome project with the above YAML file, try to install it using the ESPHome Addon UI. It will complain that the header file is missing.

Just create a file and save this content:

#include <BleKeyboard.h>

#include "esphome.h"

class Esp32BLEKeyboard : public PollingComponent {
   public:
    BleKeyboard bleKeyboard;
    BinarySensor *connected_binarysensor = new BinarySensor();
    TextSensor *textsensor = new TextSensor();

    Esp32BLEKeyboard(std::string name, std::string manufacturer) : PollingComponent(1000), bleKeyboard(name, manufacturer, 100) {}

    void setup() override {
        ESP_LOGD("Esp32BLEKeyboard", "Setting up BLE Keyboard...");
        bleKeyboard.begin();
        bleKeyboard.releaseAll();
        this->textsensor->add_on_state_callback(
            [this](std::string value) {
                ESP_LOGD("Esp32BLEKeyboard", "Sending text %s", value.c_str());
                this->bleKeyboard.print(value.c_str());
            });
    }

    void update() override {
        connected_binarysensor->publish_state(bleKeyboard.isConnected());
    }
};

Copy this file to your config/esphome folder next to your YAML file.

This config uses GPIO pin 23 with an internal pull-down resistor. Just connect your relais (from your PIR sensor) to 3.3V and GPIO pin 23.
GPIO pin 5 is used to flash an LED whenever GPIO23 goes high.

BTW: I am not using a PIR sensor, but a radar sensor (HUBER Motion 50HFLV). The advantage is that it can be hidden behind a wall or in a wardrobe, but it still detects motion in front of it.
For the ESP32 board I am just using a cheap ESP32 Dev Kit C board.

UPDATE:
Forgot to mention to whom the credits belong to for all this:

3 Likes

Thanks. Pretty nifty project. I don’t currently have an ESP32 but I do have an old Arduino UNO somewhere. Do you know if it is possible to use that instead? If so I might try it just for the sake of it.

I’ll try the downgrade option first anyhow.

Downgrading to 15.02 worked for me. Thanks guys!

Stumbled accross this thread and just wanted to say thanks. Easy guide and works like a charm.

I also have this problem. Can you explain how to downgrade from 15.1 to 15.0.2?

That is not possible anymore I’m afraid :frowning:

Thank you for your reply, I was afraid of that. Now we can only wait for an update that fixes the bug.

OMG how did I latch onto the BLE keyboard part of this conversation and not see the first post!?
This completely solves my problem, thank you!

It seems that version 15.2 fixed that problem:

https://discussions.apple.com/thread/253297750

Could you try this and tell us if that is true?