Git Product home page Git Product logo

herja's Introduction

Homeassistant-node

A library to create automation for Home Assistant in nodeJS using the WebSocket API.

How to use

Initialize the connexion

const connection = await configure({
  url: process.env.API_URL,
  access_token: process.env.API_TOKEN,
});

Where API_URL is ws://${host:port}/api/websocket and your access_token can be generated from your account.

Listen for changes on an entity

listenForEntity("sun.sun", (entity) => {
    if(entity.new_state.state === 'below_horizon')
        callService('light', 'turn_on', undefined, 'light.living_room')
})

Describe a set of state and give it a callback

onEntitiesState([{entity_id: 'binary_sensor.garden_door_contact', state: 'on'}, {entity_id: 'light.living_room_light', state: 'on'}],
    () => callService('light', 'turn_on', undefined, {entity_id: 'light.garden'})
)

Manually subscribe to an event

connection.subscribeEvents( (event) => {
  if(event.data.entity_id === "binary_sensor.garden_door_contact" && event.data.new_state === 'on'){
    callService('light', 'turn_on', undefined, {entity_id: 'light.garden'})
  }
})

Thanks

herja's People

Contributors

xorob0 avatar dependabot[bot] avatar anymaniax avatar

Stargazers

Roman avatar Mr Dev Dragon  avatar  avatar  avatar

Watchers

 avatar

Forkers

anymaniax

herja's Issues

Petite question

Bonjour, Je vous contact concernant un commit que vous avez réalisé sur une fonctionnalité dans home assistant permettant d'ajouter les poubelles dans le calendrier pour Hygea. Je n'ai pas trouvé de moyen de vous contacter autrement qu'ici. Pourriez-vous m'envoyer un message ? Vous pouvez directement me contacter sur Facebook : Jordan Quicken. Pour info j'ai également fait la HEH à Mons haha.

Incomplete or non working example with NodeJS.

Im going to assume this library will work fine with NodeJS but the example isn't sufficiently complete for that. Can you please at least clarify the fundamental usage for that?

when you say "Where API_URL is ws://${host:port}/api/websocketdoes" does that mean i can create a variable like let API_URL = "10.0.0.1:8123" ?

and same for access token? let access_token = "my_token"

And what about how to include the library into my project and commence the connection?

For the homeassistant NPM library for example, its pretty straight forward:

 const HomeAssistant = require('homeassistant'),
 const hass = new HomeAssistant({
        host: 'http://127.0.0.1',       // Home Assistant IP address
        port: 8123,                     // Home Assistant port number
        token: 'my-token',
        ignoreCert: true                // above is Home Assistant long lived token 
    });
hass.states.list()
    .then(data => console.log(data))

So what is the equivalent to "require" this library and activate the constructor? It would be really great if you could provide a complete functioning example that would work with NodeJS, that would be amazing and I'd appreciate that very much.

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.