Git Product home page Git Product logo

hass_openwrt's Introduction

Home Assistant integration with OpenWrt devices

hacs_badge

Features

  • Sensors:
    • Wireless clients counters
    • Number of connected mesh peers
    • Signal strength of mesh links
    • mwan3 interface online ratio
    • WAN interfaces Rx&Tx bytes counters (if configured)
  • Switches:
    • Control WPS status
  • Binary sensors:
    • mwan3 connectivity status
  • Services:
    • Reboot device: openwrt.reboot
    • Execute arbitrary command: openwrt.exec (see the configuration below)
    • Manage services using command-line: openwrt.init (see the configuration below)

Installing

  • OpeWrt device(s):

    • Make sure that uhttpd uhttpd-mod-ubus rpcd packages are installed (if you use custom images)
      • If you use mesh networks, install rpcd-mod-iwinfo package
    • Make sure that ubus is available via http using the manual: https://openwrt.org/docs/techref/ubus
      • To make it right, please refer to the Ubus configuration section below
  • Home Assistant:

    • Add this repo as a custom integration using HACS
    • Restart server
    • Go to Integrations and add a new OpenWrt integration

Ubus configuration

  • Create new file /usr/share/rpcd/acl.d/hass.json:
{
  "hass": {
    "description": "Home Assistant OpenWrt integraion permissions",
    "read": {
      "ubus": {
        "network.wireless": ["status"],
        "network.device": ["status"],
        "iwinfo": ["info", "assoclist"],
        "hostapd.*": ["get_clients", "wps_status"],
        "system": ["board"],
        "mwan3": ["status"]
      },
    },
    "write": {
      "ubus": {
        "system": ["reboot"],
        "hostapd.*": ["wps_start", "wps_cancel"]
      }
    }
  }
}
  • Add new system user hass (or do it in any other way that you prefer):
    • Add line to /etc/passwd: hass:x:10001:10001:hass:/var:/bin/false
    • Add line to /etc/shadow: hass:x:0:0:99999:7:::
    • Change password: passwd hass
  • Edit /etc/config/rpcd and add:
config login
        option username 'hass'
        option password '$p$hass'
        list read hass
        list read unauthenticated
        list write hass
  • Restart rpcd: /etc/init.d/rpcd restart

Executing command

In order to allow ubus/rpcd execute a command remotely, the command should be added to the permissions ACL file above. The extra configuration could look like below (gives permission to execute uptime command):

{
  "hass": {
    "write": {
      "ubus": {
        /* ... */
        "file": ["exec"]
      },
      "file": {
        /* ... */
        "/usr/bin/uptime": ["exec"]
      }
    },
  }
}

Manage services using command-line

In order to allow ubus/rpcd execute a command remotely, the command should be added to the permissions ACL file above. The extra configuration could look like below (gives permission to manage presence-detector service. Start, stop, restart, enable and disable system services.):

{
  "hass": {
    "write": {
      "ubus": {
        /* ... */
        "rc": ["init"]
      },
      "rc": {
        /* ... */
        "/etc/init.d/presence-detector": ["init"]
      }
    },
  }
}

Screenshots

Screenshot 2021-10-11 at 14 07 34

Screenshot 2021-10-11 at 14 08 15

hass_openwrt's People

Contributors

kvj avatar dckiller51 avatar cewbdex 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.