Coder Social home page Coder Social logo

hass-s3's Introduction

HASS-S3

This custom integration provides a service for interacting with S3 including uploading files to a bucket or copying them within and between buckets.

Create your S3 bucket via the AWS console, remember bucket names must be unique. I created a bucket with the default access settings (allpublic OFF) and created a bucket name with format my-bucket-ransom_number with random_number generated on this website.

Note for a local and self-hosted alternative checkout the official Minio integration.

Installation and configuration

Place the custom_components folder in your configuration directory (or add its contents to an existing custom_components folder). Add to your Home Assistant configuration UI or add to your configuration.yaml:

s3:
  aws_access_key_id: AWS_ACCESS_KEY
  aws_secret_access_key: AWS_SECRET_KEY
  region_name: eu-west-1 # optional region, default is us-east-1

Services

Put Service

The s3 entity exposes a put service for uploading files to S3.

Example data for service call:

{
  "bucket": "my_bucket",
  "key": "my_key/file.jpg",
  "file_path": "/some/path/file.jpg",
  "storage_class": "STANDARD_IA" # optional
}

Copy Service

The s3 entity exposes a copy service for moving files around in S3.

Example data for service call:

{
  "bucket": "my_bucket",
  "key_source": "my_key/file_source.jpg",  
  "key_destination": "my_key/file_destination.jpg"
}

If you need to move items between buckets use this syntax:

{
  "bucket_source": "my_source_bucket",
  "key_source": "my_key/file_source.jpg",
  "bucket_destintation": "my_destination_bucket",
  "key_destination": "my_key/file_destination.jpg"
}

Delete Service

The s3 entity exposes a delete service for deleting files (objects) from S3.

Example data for service call:

{
  "bucket": "my_bucket",
  "key": "my_key/file_source.jpg",  
}

Sign URL Service

The S3 entity exposes a signurl service for generating pre-signed URLs with a defined validity period for accessing content already stored in S3 with a URL. Run this action after you call the S3 copy service. This service generates an event of type s3_signed_url which you can use as a trigger in a subsequent automation. The event data returns a key-value pair of URL and the pre-signed URL.

Example data for service call:

{
  "bucket": "my_bucket",
  "key": "my_key/file_source.jpg",
  "duration": 300
}

Example automation

The following automation uses the folder_watcher to automatically upload files created in the local filesystem to S3:

- id: '1587784389530'
  alias: upload-file-to-S3
  description: 'When a new file is created, upload to S3'
  trigger:
    event_type: folder_watcher
    platform: event
    event_data:
      event_type: created
  action:
    service: s3.put
    data_template:
      bucket: "my_bucket"
      key: "input/{{ now().year }}/{{ (now().month | string).zfill(2) }}/{{ (now().day | string).zfill(2) }}/{{ trigger.event.data.file }}"
      file_path: "{{ trigger.event.data.path }}"
      storage_class: "STANDARD_IA"

Note you must configure folder_watcher.

Accessing S3

I recommend Filezilla for connecting to your S3 bucket, free version is available.

hass-s3's People

Contributors

alenichel avatar cumpsd avatar gdrapp avatar karlchaffey avatar ktibow avatar pvizeli avatar ramias1 avatar robmarkcole 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.