Skip to content

Commit

Permalink
Restructuring complete. Timeouts on popups. Fully Kiosk compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Sep 20, 2019
1 parent fdc509f commit 409a2fb
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 264 deletions.
71 changes: 55 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ A Home Assistant integration to turn your browser into a controllable entity - a

## Example uses

- Make the camera feed from your front door pop up on the tablett in your kitchen when someone rings the doorbell.
- Make the camera feed from your front door pop up on the tablet in your kitchen when someone rings the doorbell.
- Have a message pop up on every screen in the house when it's bedtime.
- Make the browser on your workstation switch to a specific tab when the kitchen light is on after midnight
- Play a TTS message on your work computer when the traffic sensor tells you it's time to go home.
- Display a full screen clock on your screen if no one's touched it for five minutes

# Installation instructions

Expand Down Expand Up @@ -49,38 +50,73 @@ Since the deviceID can be a bit hard to remember for devices you use often, you
browser_mod:
devices:
99980b13-dabc9563:
name: Arrakis
name: arrakis
d2fc860c-16379d23:
name: dashboard
```
This binds the *aliases* `Arrakis` to `99980b13-dabc9563` and `dashboard` to `d2fc860c-16379d23`.
This binds the *aliases* `arrakis` to `99980b13-dabc9563` and `dashboard` to `d2fc860c-16379d23`.

Note: Aliases must be unique.

## media\_player
Once `browser_mod` is installed, loading up your Home Assistant frontend on a new *device* will create a new `media_player` device.
## Entities
Once `browser_mod` is installed, loading up your Home Assistant frontend on a new *device* will create three or four new devices.

Any sound played on this media player will be played by the *device*.
- `sensor.<device>`
- `media_player.<device>`
- `light.<device>`
- If you're using Fully Kiosk Browser `binary_sensor.<device>`

The `media_player` entity also has some extra attributes presenting the current state of the *device*.
`<device>` here will be the `deviceID` of the *device* but with the dash (`-`) replaced by an underscore (`_`). If you've defined an alias, it will be that instead.

E.g:
Connecting your phone with `deviceID: ded3b4dc-abedd098` will create the entities `sensor.ded3b4dc_abedd098`, `media_player.ded3b4dc_abedd098` and `light.ded3b4dc_abedd098`.
Connecting with the computer named `Arrakis` above with `deviceID: 99980b13-dabc9563` will create the entities `sensor.arrakis`, `media_player.arrakis` and `light.arrakis`.

### sensor

The `sensor` will display the number of connected views (tabs/windows) of the device. Note that using multiple view isn't really recommended, and any action targeting a device will happen in the last loaded view.

The sensor also has the following attributes:

| attribute | content |
| --- | --- |
| `type` | `browser_mod` |
| `last_seen` | The time when the *device* was last seen |
| `deviceID` | The deviceID of the *device*. |
| `path` | The currently displayed path on the *device*. |
| `visibility` | Whether the frontend is currently visible on the *device*. |
| `userAgent` | The User Agent of the associated browser. |
| `currentUser` | The user currently logged in on the *device*. |
| `blackout` | Whether the view on the *device* is currently blacked out (see below). |
| `fullyKiosk` | True if the *device* is a Fully Kiosk browser. Undefined otherwise. |
| `width` | The current width of the browser window in pixels. |
| `height` | The current height of the browser window in pixels. |

### media\_player

The `media_player` can be used to play sounds on the *device*.

**NOTE: Because apple is apple; on iOS you need to touch the screen once after loading the frontend before any playback will work.**
**NOTE: Because Apple is Apple; on iOS you need to touch the screen once after loading the frontend before any playback will work.**

### light

The `light` can be used to blackout the screen.
For Fully Kiosk Browser, the screen will actually turn off.
For other browsers, the interface will just be covered with black (the screen is still on, will have a visible glow in the dark, and you won't save any battery).

### binary\_sensor

The `binary_sensor` will only be available for Fully Kiosk Browser PRO *devices*.
It's state will be the state of the camera motion detector of the *device* (5 second cooldown).

## `browser_mod.command` service

Call the `browser_mod.command` service to control your *device* in various ways.

All service calls have two parameters in common, `command` which is the command to execute, and `deviceID` which is a list of *devices* to execute the command on. If `deviceID` is omitted, the command will be executed on **all** currently connected *devices*.
All service calls have two parameters in common, `command` which is the command to execute, and `deviceID` which is a list of *devices* to execute the command on. If `deviceID` is omitted, the command will be executed on **all** currently connected *devices*. `deviceID` may also contain aliases.

There is a special function that will replace the special alias `this` with the current deviceID in the list `deviceID` for any service call from the frontend. In the examples below it will be shown used for the `browser_mod.command` service, but it also works e.g for calling scripts from the frontend.

`deviceID` may also contain aliases, and there's a special alias named `this` which will evaluate to the *device* from which a command was initiated (if from the frontend).
All examples below are given in the syntax used for calling them from lovelace via e.g. an entity-button card with `tap_action:` set to `call-service`. If you call the service from a script or an automation, the syntax will be slightly different.

### debug

Expand All @@ -90,7 +126,7 @@ service_data:
command: debug
```
Display a popup with the deviceID *and* a javascript allert with the deviceID on all connected *devices*.
Display a popup with the deviceID *and* a javascript alert with the deviceID on all connected *devices*.
### set-theme
Expand Down Expand Up @@ -153,8 +189,9 @@ will display the specified `entities` card as a popup on the current device.
![popup-example](https://user-images.githubusercontent.com/1299821/60288984-a7cb6b00-9915-11e9-9322-324323a9ec6e.png)
The optional parameter `large: true` will make the popup wider.
The optional parameter `style:` will apply css style options to the popup.
The optional parameter `style:` will apply CSS style options to the popup.
The optional parameter `auto_close: true` will make the popup close automatically when the mouse is moved or a key is pressed on the keyboard. This also removes the header bar.
The optional parameter `time:` (only useable if `auto_close: true` is also set) will turn the popup into a "screensaver". See the `blackout` command below.
Ex:
```yaml
Expand Down Expand Up @@ -185,6 +222,8 @@ service_data:
Will cover the entire window (or screen if in full screen mode) with black.
Moving the mouse, touching the screen or pressing any key will restore the view.

The optional parameter `time:` will make the blackout turn on automatically after the specified number of seconds. It works kind of like a screensaver and will keep turning on until `blackout` is called again with `time: -1`.

Note: This will *not* turn off your screen backlight. Most screens will still emit light in a dark room.

### no-blackout
Expand Down Expand Up @@ -224,7 +263,7 @@ The player card also displays the `entityID`. Click it to select, so you can cop
# Fully Kiosk Browser
If you are using a device running [Fully Kiosk Browser](https://www.ozerov.de/fully-kiosk-browser/) (PLUS version only) you will have access to a few more functions.

First of all the commands `blackout` and `no-blackout` will controll the devices screen directly.
First of all the commands `blackout` and `no-blackout` will control the devices screen directly.
`no-blackout` also has an optional parameter `brightness` that can set the screen brightness between 0 and 255.

Second, there are a few more attributes available
Expand Down Expand Up @@ -257,7 +296,7 @@ This actually means it pretty much replaces `popup-card` as well.
- This works even if the currently logged in user is not in the admin group.

### Does this replace lovelace-fullykiosk
It will, eventually.
Yes. You need the paid version, btw.

### Can the deviceID be used to track me across the internet

Expand All @@ -269,7 +308,7 @@ Some of [my lovelace plugins](https://github.com/thomasloven/hass-config/wiki/My

### How do I run commands from /dev-service?

`/dev-service` requires json-formated service data. There's an explanation on the differences between yaml and json [here](http://thomasloven.com/blog/2018/08/YAML-For-Nonprogrammers/).
`/dev-service` requires json-formatted service data. There's an explanation on the differences between yaml and json [here](http://thomasloven.com/blog/2018/08/YAML-For-Nonprogrammers/).

---
<a href="https://www.buymeacoffee.com/uqD6KHCdJ" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/white_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
1 change: 1 addition & 0 deletions custom_components/browser_mod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async def async_setup(hass, config):

await hass.helpers.discovery.async_load_platform("media_player", DOMAIN, {}, config)
await hass.helpers.discovery.async_load_platform("sensor", DOMAIN, {}, config)
await hass.helpers.discovery.async_load_platform("binary_sensor", DOMAIN, {}, config)
await hass.helpers.discovery.async_load_platform("light", DOMAIN, {}, config)

await setup_connection(hass, config)
Expand Down
50 changes: 50 additions & 0 deletions custom_components/browser_mod/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import logging
from datetime import datetime

from homeassistant.const import STATE_UNAVAILABLE, ATTR_BATTERY_CHARGING, ATTR_BATTERY_LEVEL, STATE_ON, STATE_OFF
from homeassistant.components.binary_sensor import DEVICE_CLASS_MOTION

from .helpers import setup_platform, BrowserModEntity

PLATFORM = 'binary_sensor'

async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
return setup_platform(hass, config, async_add_devices, PLATFORM, BrowserModSensor)

class BrowserModSensor(BrowserModEntity):
domain = PLATFORM

def __init__(self, hass, connection, deviceID, alias=None):
super().__init__(hass, connection, deviceID, alias)
self.last_seen = None

def updated(self):
self.last_seen = datetime.now()
self.schedule_update_ha_state()

@property
def state(self):
if not self.connection.connection:
return STATE_UNAVAILABLE
if self.data.get('motion', False):
return STATE_ON
return STATE_OFF

@property
def is_on(self):
return not self.data.get('motion', False)


@property
def device_class(self):
return DEVICE_CLASS_MOTION

@property
def device_state_attributes(self):
return {
"type": "browser_mod",
"last_seen": self.last_seen,
ATTR_BATTERY_LEVEL: self.data.get('battery', None),
ATTR_BATTERY_CHARGING: self.data.get('charging', None),
**self.data
}
Loading

0 comments on commit 409a2fb

Please sign in to comment.