Coder Social home page Coder Social logo

arciiix / handy Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 11.65 MB

Easily control your home automations using hand gestures, at any time. This app recognizes the gestures using your security camera footage and controls every IoT action you can dream of. Nothing is impossible - make your life feel like you were the main character of a sci-fi movie.

Python 12.25% Jupyter Notebook 69.75% Kotlin 0.22% Swift 0.11% Objective-C 0.01% Dart 17.66%

handy's Introduction

Handy

Handy

Easily control your home automations using hand gestures, at any time. This app recognizes the gestures using your security camera footage and controls every IoT action you can dream of. Nothing is impossible - make your life feel like you were the main character of a sci-fi movie.

Imagine living in a world where you can effortlessly control every aspect of your smart home with a simple wave of your hand. Welcome to Handy, a groundbreaking project designed to transform your daily life into a science fiction dream come true. With Handy, you can seamlessly interact with your home automation systems using hand gestures, making the future of smart living a reality today.

Features

๐Ÿ–๏ธ Gesture Recognition

Control your smart home devices effortlessly with various hand gestures - I built and trained a classifier (Random Forest) model by myself. It gets the angles between different body joints (thanks to MediaPipe and some magic (math to be specific)) as input data and outputs the corresponding gesture ID. This sophisticated model accurately interprets your hand movements, enabling seamless interaction with your IoT devices.

๐Ÿก Home Assistant Integration

Handy was built to seamlessly integrate with Home Assistant, the most popular central hub for your smart home ecosystem. This means you can effortlessly control all your IoT devices that are compatible with it. Every single one of them. There is no catch.

๐ŸŽต Built-In actions

The core element of Handy is music control - play, pause, adjust volume, switch tracks, play music from YouTube or online radio, and much more. Want to get an update on weather or want the music player to say the current date and time? No problem at all.

๐Ÿ“ฑ Mobile App

If you need to manually control Handy without using hand gestures, you can use the mobile app I also created. What's more, it keeps the action history so that you can see who did what and when. You can also manage music items (radios/YouTube videos) of the playlist used in Handy.

โš™๏ธ Resource Efficiency

Efficiently operates on standard surveillance cameras 24/7, without any problems. Optimized for fully automated workflow - you forget that this app "works somewhere" - these hand gestures become a crucial part of your life (trust me, I know what I'm talking about ๐Ÿ˜…)

๐Ÿค– Customization

The app can be customized in every way. You can even build, train, and test your own gesture recognition model - I wanted this project to be incredibly friendly for new users - see below for Jupyter notebooks on how to get started. Easily customize and extend actions for any IoT device - with the intuitive code and docs.

๐Ÿ“ˆ Constant Innovation

Since this is a crucial part of my (and my family members') lives right now, every problem that I discover will be patched. And of course, this doesn't stop just there. This app will be improved so that it becomes a real science fiction dream come true.

Prerequirements

IMPORTANT: Before using the app, please upload the audio from the /handy/audio/ directory to Home Assistant as local media.

Train

Handy comes with pretrained model that recognizes various of hand gestures, but if you want to build your own, please follow the notebooks below.

  1. Gather data

  2. Process data

  3. Train model

After completing all above, you can optionally:

  1. Select ROI (region of interest), T-ROI (trigger region of interest), and G-ROI (gesture region of interest)

  2. Test model

Const values

You can modify some of the preferences a by creating a config.json file (handy/config.json)

Required changes:

Optional changes:

  • FPS_IDLE - frames per second before detection
  • FPS - frames per second after detection for gesture recognition
  • RESIZE_WIDTH - resize your input image to that width
  • RESIZE_HEIGHT - resize your input image to that height
  • ENV - change the current running environment - "DEV" or "PROD"
  • HOME_ASSISTANT_IP - the URL of your Home Assistant instance. Important: don't put the slash at the end
  • MEDIA_PLAYER_HASS_ENTITY_ID - the entity id of the media player inside Home Assistant - used for audio playing (e.g. confirmation of gesture)
  • DETECTIONS_TO_KEEP - To prevent false detections caused by accidental gestures or model inaccuracy, Handy caches the last detections. This variable sets the number of detections to store.
  • MINIMAL_DETECTIONS - that number of DETECTIONS_TO_KEEP has to be the same to consider a detection as true (and perform the given action)
  • ACTION_BLOCK_DELAY_SECONDS - to prevent user from accidently performing the same action after they show the gesture and didn't manage to stop showing it, add some blocking delay between next action
  • FAST_MODE_DURATION_SECONDS - normally the app works in an idle mode on low FPS. When user enters the T-ROI or a gesture within G-ROI is detected, the app turns into fast mode with high FPS. This variable determines how long it should remain in the fast mode after the last movement.
  • REQUIRED_TROI_PERCENT_CHANGE - this amount of the T-ROI frame has to be different for Handy to consider a movement inside it. Unit is percent [%].
  • NUMERIC_VALUE_MAX_WAITING_TIME_SECONDS - there are some actions, like changing volume, that have to know the numeric value of change (see numeric_value_track in numeric_value_track.py). This value determines how many seconds user can stand without raising neither of their arms to be considered as idle (so cancel the action)
  • GET_NUMERIC_VALUE_INTERVAL_SECONDS - see above - the handler will be called every n seconds, where n is this value.
  • LANGUAGE - can be either "pl" or "en" - the announcements will be said in that language, e.g. the current time.
  • MIN_ARM_ANGLE_FOR_NUMERIC_VALUE_CHANGE - Minimum angle for arm to be considered as raised (which, in numeric vaule mode, causes the value to be either increased or decreased).
  • TIME_START_MINUTES_AFTER_MIDNIGHT - The time of the day that Handy starts processing the images at (to prevent it from unnecessary image processing, e.g. why would it process images at 2 am?). It's minutes after midnight, i.e. hour * 60 + minutes, e.g. 08:15 = 8 * 60 + 15. Defaults to 8:00.
  • TIME_END_MINUTES_AFTER_MIDNIGHT - The same thing as above, but it's ending time. Defaults to 21:00.
  • SOCKET_IO_PORT - A port that the socket.io instance will run on.
  • ACTION_PERFORMED_HISTORY_LENGTH - in the mobile app, you can view the recent performed actions. This variable determines how many of the recent actions should be kept.

Action-related changes

  • PLAYER_PLAYPAUSE_HASS_ENTITY_ID - this media_player entity will be used for play/pause action
  • PLAYER_VOLUME_HASS_ENTITY_ID - this media_player entity will be used for volume change action
  • PLAYER_NEXTPLAYLISTITEM_HASS_ENTITY_ID - this media_player entity will be used for playing next playlist item (see below for playlist)
  • WEATHER_HASS_ENTITY_ID - this weather entity will be used for weather info
{
  "STREAM_URL": "udp://127.0.0.1:12345",
  "HOME_ASSISTANT_TOKEN": null,

  "FPS_IDLE": 0.5,
  "FPS": 5,
  "RESIZE_WIDTH": 960,
  "RESIZE_HEIGHT": 540,
  "ENV": "DEV",
  "HOME_ASSISTANT_IP": "http://homeassistant.local:8123",
  "MEDIA_PLAYER_HASS_ENTITY_ID": "media_player.mpd",
  "DETECTIONS_TO_KEEP": 20,
  "MINIMAL_DETECTIONS": 10,
  "ACTION_BLOCK_DELAY_SECONDS": 5,
  "FAST_MODE_DURATION_SECONDS": 3,
  "REQUIRED_TROI_PERCENT_CHANGE": 0.5,
  "NUMERIC_VALUE_MAX_WAITING_TIME_SECONDS": 8,
  "GET_NUMERIC_VALUE_INTERVAL_SECONDS": 1,
  "LANGUAGE": "en",
  "MIN_ARM_ANGLE_FOR_NUMERIC_VALUE_CHANGE": 70,
  "TIME_START_MINUTES_AFTER_MIDNIGHT": 480,
  "TIME_END_MINUTES_AFTER_MIDNIGHT": 1260,
  "SOCKET_IO_PORT": 4001,
  "ACTION_PERFORMED_HISTORY_LENGTH": 5,

  "PLAYER_PLAYPAUSE_HASS_ENTITY_ID": "media_player.volumio",
  "PLAYER_NEXTPLAYLISTITEM_HASS_ENTITY_ID": "media_player.mpd",
  "PLAYER_VOLUME_HASS_ENTITY_ID": "media_player.volumio",
  "WEATHER_HASS_ENTITY_ID": "weather.openweathermap"
}

Using with Volumio

If you want to use Handy with Volumio (like I do), you have to note that there's a huge difference between the Volumio integration in Home Assistant and MPD (it's not the same as DLNA Digital Media Renderer - this one is useless and buggy for Volumio).

You should use both Volumio and MPD integration. The first one is good for just controlling Volumio, whereas the second one is required to get current played media or play something on Volumio. See the default config - media_player.volumio is the Volumio integration and media_player.mpd is the Music Player Daemon (which is still Volumio). The MPD is a perfect thing - it comes back to the previously played media when using TTS (announce mode) - which is just ideal for Handy and solves tones of unnecessary problems DLNA_DMR or Volumio has.

To set up MPD in Home Assistant, please add:

- platform: mpd
  name: volumio_mpd
  host: your.volumio.ip.address

Command to stream webcam on Linux

ffmpeg -f v4l2 -i /dev/video0 -preset ultrafast -vcodec libx264 -tune zerolatency -b 900k -f h264 udp://<YOUR_IP>:<YOUR_PORT>

Default poses

Play next item

Play next item

Play/pause

Play/pause

(Re)play current item

Play current item

Volume

First, make this pose:

Volume

The system will indicate that it's ready to change the volume by muting the audio for a moment.

Then, to increase the volume, make this pose:

Volume up

And to decrease the volume, make this pose:

Volume down

When you're ready, you can leave the ROI or raise both your hands.

Toggle playlist - between local and remote (YouTube)

Toggle playlist

Get the current time

Get the current time

Get the current weather

Get the current weather

Made with lots of โค๏ธ by Artur Nowak

handy's People

Contributors

arciiix avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.