This is a Home Assistant frontend created on Next.js build with TypeScript and Tailwind. Thanks to dangreco for his starter repo which this frontend is build up on. See: https://github.com/dangreco/home-assistant-nextjs-starter
-
Let DatoCMS set everything up for you clicking this button:
- Clone this repository
$ git clone https://github.com/MarkNygaard/HA-Next-Frontend.git
- Install dependencies
$ yarn
- Edit
utils/config.ts
with the name of your app:
const APP_NAME = 'app-name'; // <- Edit this!
export { APP_NAME };
In your DatoCMS' project, go to the Settings menu at the top and click API tokens.
Then click Read-only API token and copy the token.
Next, copy the .env.example
file in this directory to .env.local
(which will be ignored by Git):
cp .env.example .env.local
Then set each variable on .env.local
:
DATOCMS_API_KEY
should be the API token you just copied.
Your .env.local
file should look like this:
DATOCMS_API_KEY=...
Start the dev server
$ yarn dev
Open up localhost:3000
in your browser. The site might run slow in dev mode.
For production build
$ yarn build
Run you build
$ yarn start
Open up localhost:3000
in your browser, you're done!
-
pages/index.tsx
This is where your "dashboard" should go. The user will be redirected to this route after succesful authentication. -
components/
This is where your components like navigation, buttons, properties etc. are placed. -
components/icons/index.tsx
This is where you will add new icons to be used. Search icons at https://react-icons.github.io/react-icons/
Entities (Instructions from dangreco see: https://github.com/dangreco/home-assistant-nextjs-starter)
-
useEntity( entityId: string )
Retrieves an entity for the givenentityId
,undefined
if the entity is not found. -
useEntities( entityIds?: string[] )
Retrives an object of entities matching the givenentityIds
. If a given entity with IDentityId
was not found, the corresponding entrymyEntities[entityId]
will beundefined
. IfentityIds
is undefined, this hook returns all entities. -
useDomain( domain: string )
Retrieves an object of entities matching the givendomain
. E.g.,useDomain('light')
will return all entities with IDs matchinglight.xxxxxxxx
. -
useQuery( query: string )
Searches all available entites byquery
. Matches are based on both theentity_id
andfriendly_name
of the entity. -
TODO
useHistory( entityId: string )
Retrieves the history for an entity given itsentityId
.
Other (Instructions from dangreco see: https://github.com/dangreco/home-assistant-nextjs-starter)
-
useDiscovery( max?: number )
Finds Home Assistant servers on the local network. Stops the search oncemax
instances are found. Ifmax
is undefined, this will search forever. -
useAuth()
Retrieves current authentication information. The fieldlogout
is a function to log out of the current auth. -
useHass()
Retrieves the current Home Assistant state, incuding fieldsconnection
,entities
,services
,config
.