mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-23 17:27:19 +00:00
Merge branch 'current' into next
This commit is contained in:
commit
86ae27b9ff
@ -101,8 +101,8 @@ social:
|
||||
# Home Assistant release details
|
||||
current_major_version: 0
|
||||
current_minor_version: 103
|
||||
current_patch_version: 5
|
||||
date_released: 2019-12-28
|
||||
current_patch_version: 6
|
||||
date_released: 2020-01-06
|
||||
|
||||
# Either # or the anchor link to latest release notes in the blog post.
|
||||
# Must be prefixed with a # and have double quotes around it.
|
||||
|
@ -42,15 +42,15 @@ That's it. You should no be able to use the Google Voice assistant.
|
||||
|
||||
{% configuration %}
|
||||
client_secrets:
|
||||
description: The file downloaded from the [Google Actions Console][GActionsConsole], you can redownload them under the "Develop - Device registration" tab. By default the add-on look in the "hassio/share" folder.
|
||||
description: The file downloaded from the [Google Actions Console](https://console.actions.google.com/), you can redownload them under the "Develop - Device registration" tab. By default the add-on look in the "hassio/share" folder.
|
||||
required: true
|
||||
type: string
|
||||
project_id:
|
||||
description: The project id can be found in your "google_assistant.json" file or under project settings in the [Google Actions Console][GActionsConsole].
|
||||
description: The project id can be found in your "google_assistant.json" file or under project settings in the [Google Actions Console](https://console.actions.google.com/).
|
||||
required: true
|
||||
type: string
|
||||
model_id:
|
||||
description: The model id can also be found under the "Develop - Device registration tab" in the [Google Actions Console][GActionsConsole].
|
||||
description: The model id can also be found under the "Develop - Device registration tab" in the [Google Actions Console](https://console.actions.google.com/).
|
||||
required: true
|
||||
type: string
|
||||
{% endconfiguration %}
|
||||
|
@ -41,12 +41,20 @@ import voluptuous as vol
|
||||
import homeassistant.components as core
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components import device_tracker, light
|
||||
from homeassistant.const import (ATTR_ENTITY_ID, SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON, STATE_HOME, STATE_NOT_HOME,
|
||||
STATE_OFF, STATE_ON)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_HOME,
|
||||
STATE_NOT_HOME,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import split_entity_id
|
||||
from homeassistant.helpers.event import (async_track_state_change,
|
||||
async_track_time_change)
|
||||
from homeassistant.helpers.event import (
|
||||
async_track_state_change,
|
||||
async_track_time_change,
|
||||
)
|
||||
|
||||
# The domain of your component. Should be equal to the name of your component.
|
||||
DOMAIN = "example"
|
||||
@ -54,26 +62,26 @@ DOMAIN = "example"
|
||||
# List of integration names (string) your integration depends upon.
|
||||
# We depend on group because group will be loaded after all the integrations that
|
||||
# initialize devices have been setup.
|
||||
DEPENDENCIES = ['group', 'device_tracker', 'light']
|
||||
DEPENDENCIES = ["group", "device_tracker", "light"]
|
||||
|
||||
# Configuration key for the entity id we are targeting.
|
||||
CONF_TARGET = 'target'
|
||||
CONF_TARGET = "target"
|
||||
|
||||
# Variable for storing configuration parameters.
|
||||
TARGET_ID = None
|
||||
|
||||
# Name of the service that we expose.
|
||||
SERVICE_FLASH = 'flash'
|
||||
SERVICE_FLASH = "flash"
|
||||
|
||||
# Shortcut for the logger
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Validate that all required config options are given.
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Optional(CONF_TARGET): cv.entity_id
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{DOMAIN: vol.Schema({vol.Optional(CONF_TARGET): cv.entity_id})},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Setup example component."""
|
||||
@ -84,8 +92,7 @@ async def async_setup(hass, config):
|
||||
|
||||
# Validate that the target entity id exists.
|
||||
if hass.states.get(TARGET_ID) is None:
|
||||
_LOGGER.error("Target entity id %s does not exist",
|
||||
TARGET_ID)
|
||||
_LOGGER.error("Target entity id %s does not exist", TARGET_ID)
|
||||
|
||||
# Tell the bootstrapper that we failed to initialize and clear the
|
||||
# stored target id so our functions don't run.
|
||||
@ -120,7 +127,7 @@ async def async_setup(hass, config):
|
||||
return
|
||||
|
||||
if device_tracker.is_on(hass) and not core.is_on(hass, TARGET_ID):
|
||||
_LOGGER.info('People home at 7AM, turning target on')
|
||||
_LOGGER.info("People home at 7AM, turning target on")
|
||||
await hass.services.async_call(domain, SERVICE_TURN_ON, data)
|
||||
|
||||
async def async_flash_service(service):
|
||||
@ -133,7 +140,9 @@ async def async_setup(hass, config):
|
||||
|
||||
if core.is_on(hass, TARGET_ID):
|
||||
# We need this call to run blocking, as we want to wait 10s after it finished
|
||||
await hass.services.async_call(domain, SERVICE_TURN_OFF, data, blocking=True)
|
||||
await hass.services.async_call(
|
||||
domain, SERVICE_TURN_OFF, data, blocking=True
|
||||
)
|
||||
time.sleep(10)
|
||||
await hass.services.async_call(domain, SERVICE_TURN_ON, data)
|
||||
else:
|
||||
@ -146,15 +155,26 @@ async def async_setup(hass, config):
|
||||
|
||||
# If all lights turn off, turn off.
|
||||
async_track_state_change(
|
||||
hass, light.ENTITY_ID_ALL_LIGHTS, async_switch_off, STATE_ON, STATE_OFF)
|
||||
hass, light.ENTITY_ID_ALL_LIGHTS, async_switch_off, STATE_ON, STATE_OFF
|
||||
)
|
||||
|
||||
# If all people leave the house and the entity is on, turn it off.
|
||||
async_track_state_change(
|
||||
hass, device_tracker.ENTITY_ID_ALL_DEVICES, async_switch_off, STATE_HOME, STATE_NOT_HOME)
|
||||
hass,
|
||||
device_tracker.ENTITY_ID_ALL_DEVICES,
|
||||
async_switch_off,
|
||||
STATE_HOME,
|
||||
STATE_NOT_HOME,
|
||||
)
|
||||
|
||||
# If anyone comes home and the entity is not on, turn it on.
|
||||
async_track_state_change(
|
||||
hass, device_tracker.ENTITY_ID_ALL_DEVICES, async_switch_on, STATE_NOT_HOME, STATE_HOME)
|
||||
hass,
|
||||
device_tracker.ENTITY_ID_ALL_DEVICES,
|
||||
async_switch_on,
|
||||
STATE_NOT_HOME,
|
||||
STATE_HOME,
|
||||
)
|
||||
|
||||
# Call wakeup callback at 7 AM
|
||||
async_track_time_change(hass, async_wake_up, hour=7, minute=00, second=00)
|
||||
|
@ -18,21 +18,21 @@ This example follows a topic on MQTT and updates the state of an entity to the l
|
||||
import homeassistant.loader as loader
|
||||
|
||||
# The domain of your component. Should be equal to the name of your component.
|
||||
DOMAIN = 'hello_mqtt'
|
||||
DOMAIN = "hello_mqtt"
|
||||
|
||||
# List of integration names (string) your integration depends upon.
|
||||
DEPENDENCIES = ['mqtt']
|
||||
DEPENDENCIES = ["mqtt"]
|
||||
|
||||
|
||||
CONF_TOPIC = 'topic'
|
||||
DEFAULT_TOPIC = 'home-assistant/hello_mqtt'
|
||||
CONF_TOPIC = "topic"
|
||||
DEFAULT_TOPIC = "home-assistant/hello_mqtt"
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Hello MQTT component."""
|
||||
mqtt = hass.components.mqtt
|
||||
topic = config[DOMAIN].get(CONF_TOPIC, DEFAULT_TOPIC)
|
||||
entity_id = 'hello_mqtt.last_message'
|
||||
entity_id = "hello_mqtt.last_message"
|
||||
|
||||
# Listener to be called when we receive a message.
|
||||
# The msg parameter is a Message object with the following members:
|
||||
@ -45,15 +45,15 @@ def setup(hass, config):
|
||||
mqtt.subscribe(topic, message_received)
|
||||
|
||||
# Set the initial state.
|
||||
hass.states.set(entity_id, 'No messages')
|
||||
hass.states.set(entity_id, "No messages")
|
||||
|
||||
# Service to publish a message on MQTT.
|
||||
def set_state_service(call):
|
||||
"""Service to send a message."""
|
||||
mqtt.publish(topic, call.data.get('new_state'))
|
||||
mqtt.publish(topic, call.data.get("new_state"))
|
||||
|
||||
# Register our service with Home Assistant.
|
||||
hass.services.register(DOMAIN, 'set_state', set_state_service)
|
||||
hass.services.register(DOMAIN, "set_state", set_state_service)
|
||||
|
||||
# Return boolean to indicate that initialization was successfully.
|
||||
return True
|
||||
|
@ -43,19 +43,19 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = 'simple_alarm"'
|
||||
|
||||
DEPENDENCIES = ['group', 'device_tracker', 'light']
|
||||
DEPENDENCIES = ["group", "device_tracker", "light"]
|
||||
|
||||
# Attribute to tell which light has to flash when a known person comes home
|
||||
# If omitted will flash all.
|
||||
CONF_KNOWN_LIGHT = 'known_light'
|
||||
CONF_KNOWN_LIGHT = "known_light"
|
||||
|
||||
# Attribute to tell which light has to flash when an unknown person comes home
|
||||
# If omitted will flash all.
|
||||
CONF_UNKNOWN_LIGHT = 'unknown_light'
|
||||
CONF_UNKNOWN_LIGHT = "unknown_light"
|
||||
|
||||
# Services to test the alarms
|
||||
SERVICE_TEST_KNOWN_ALARM = 'test_known'
|
||||
SERVICE_TEST_UNKNOWN_ALARM = 'test_unknown'
|
||||
SERVICE_TEST_KNOWN_ALARM = "test_known"
|
||||
SERVICE_TEST_UNKNOWN_ALARM = "test_unknown"
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
@ -66,8 +66,7 @@ def setup(hass, config):
|
||||
light_id = config[DOMAIN].get(conf_key, light.ENTITY_ID_ALL_LIGHTS)
|
||||
|
||||
if hass.states.get(light_id) is None:
|
||||
_LOGGER.error(
|
||||
"Light id %s could not be found in state machine", light_id)
|
||||
_LOGGER.error("Light id %s could not be found in state machine", light_id)
|
||||
|
||||
return False
|
||||
|
||||
@ -88,18 +87,19 @@ def setup(hass, config):
|
||||
def unknown_alarm():
|
||||
""" Fire an alarm if the light turns on while no one is home. """
|
||||
light.turn_on(
|
||||
hass, unknown_light_id,
|
||||
flash=light.FLASH_LONG, rgb_color=[255, 0, 0])
|
||||
hass, unknown_light_id, flash=light.FLASH_LONG, rgb_color=[255, 0, 0]
|
||||
)
|
||||
|
||||
# Send a message to the user
|
||||
notify.send_message(
|
||||
hass, "The lights just got turned on while no one was home.")
|
||||
hass, "The lights just got turned on while no one was home."
|
||||
)
|
||||
|
||||
# Setup services to test the effect
|
||||
hass.services.register(DOMAIN, SERVICE_TEST_KNOWN_ALARM, lambda call: known_alarm())
|
||||
hass.services.register(
|
||||
DOMAIN, SERVICE_TEST_KNOWN_ALARM, lambda call: known_alarm())
|
||||
hass.services.register(
|
||||
DOMAIN, SERVICE_TEST_UNKNOWN_ALARM, lambda call: unknown_alarm())
|
||||
DOMAIN, SERVICE_TEST_UNKNOWN_ALARM, lambda call: unknown_alarm()
|
||||
)
|
||||
|
||||
def unknown_alarm_if_lights_on(entity_id, old_state, new_state):
|
||||
"""Called when a light has been turned on."""
|
||||
@ -107,8 +107,12 @@ def setup(hass, config):
|
||||
unknown_alarm()
|
||||
|
||||
track_state_change(
|
||||
hass, light.ENTITY_ID_ALL_LIGHTS,
|
||||
unknown_alarm_if_lights_on, STATE_OFF, STATE_ON)
|
||||
hass,
|
||||
light.ENTITY_ID_ALL_LIGHTS,
|
||||
unknown_alarm_if_lights_on,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
|
||||
def ring_known_alarm(entity_id, old_state, new_state):
|
||||
"""Called when a known person comes home."""
|
||||
@ -117,8 +121,12 @@ def setup(hass, config):
|
||||
|
||||
# Track home coming of each device
|
||||
track_state_change(
|
||||
hass, hass.states.entity_ids(device_tracker.DOMAIN),
|
||||
ring_known_alarm, STATE_NOT_HOME, STATE_HOME)
|
||||
hass,
|
||||
hass.states.entity_ids(device_tracker.DOMAIN),
|
||||
ring_known_alarm,
|
||||
STATE_NOT_HOME,
|
||||
STATE_HOME,
|
||||
)
|
||||
|
||||
return True
|
||||
```
|
||||
|
@ -59,33 +59,39 @@ One of the most common uses cases are to show groups during certain times of day
|
||||
|
||||
from datetime import time, datetime
|
||||
|
||||
|
||||
def mk_occasion(name, start, end, days=None):
|
||||
s = start.split(':')
|
||||
e = end.split(':')
|
||||
return {'name' : name,
|
||||
'start': time(int(s[0]), int(s[1]), int(s[2])),
|
||||
'end' : time(int(e[0]), int(e[1]), int(e[2])),
|
||||
'days' : days}
|
||||
s = start.split(":")
|
||||
e = end.split(":")
|
||||
return {
|
||||
"name": name,
|
||||
"start": time(int(s[0]), int(s[1]), int(s[2])),
|
||||
"end": time(int(e[0]), int(e[1]), int(e[2])),
|
||||
"days": days,
|
||||
}
|
||||
|
||||
|
||||
# Matching is done from top to bottom
|
||||
OCCASIONS = [
|
||||
# More specific occasions
|
||||
mk_occasion('work_morning', '06:00:00', '07:10:00', range(5)),
|
||||
|
||||
mk_occasion("work_morning", "06:00:00", "07:10:00", range(5)),
|
||||
# General matching
|
||||
mk_occasion('weekday', '00:00:00', '23:59:59', range(5)),
|
||||
mk_occasion('weekend', '00:00:00', '23:59:59', [5, 6])
|
||||
mk_occasion("weekday", "00:00:00", "23:59:59", range(5)),
|
||||
mk_occasion("weekend", "00:00:00", "23:59:59", [5, 6]),
|
||||
]
|
||||
|
||||
def get_current_occasion(occasion_list, default_occasion='normal'):
|
||||
|
||||
def get_current_occasion(occasion_list, default_occasion="normal"):
|
||||
now = datetime.now()
|
||||
for occasion in OCCASIONS:
|
||||
if occasion['start'] <= now.time() <= occasion['end'] and \
|
||||
(occasion['days'] is None or now.weekday() in occasion['days']):
|
||||
return occasion['name']
|
||||
if occasion["start"] <= now.time() <= occasion["end"] and (
|
||||
occasion["days"] is None or now.weekday() in occasion["days"]
|
||||
):
|
||||
return occasion["name"]
|
||||
return default_occasion
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(get_current_occasion(OCCASIONS))
|
||||
```
|
||||
|
||||
|
@ -31,8 +31,8 @@ Let's start with a simple App to turn a light on every night at sunset and off e
|
||||
```python
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
|
||||
class OutsideLights(hass.Hass):
|
||||
|
||||
class OutsideLights(hass.Hass):
|
||||
def initialize(self):
|
||||
self.run_at_sunrise(self.sunrise_cb)
|
||||
self.run_at_sunset(self.sunset_cb)
|
||||
@ -42,7 +42,6 @@ class OutsideLights(hass.Hass):
|
||||
|
||||
def sunset_cb(self, kwargs):
|
||||
self.turn_on(self.args["on_scene"])
|
||||
|
||||
```
|
||||
|
||||
This is also fairly easy to achieve with Home Assistant automations, but we are just getting started.
|
||||
@ -54,8 +53,8 @@ Our next example is to turn on a light when motion is detected and it is dark, a
|
||||
```python
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
|
||||
class FlashyMotionLights(hass.Hass):
|
||||
|
||||
class FlashyMotionLights(hass.Hass):
|
||||
def initialize(self):
|
||||
self.listen_state(self.motion, "binary_sensor.drive", new="on")
|
||||
|
||||
@ -75,8 +74,8 @@ Now let's extend this with a somewhat artificial example to show something that
|
||||
```python
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
|
||||
class MotionLights(hass.Hass):
|
||||
|
||||
class MotionLights(hass.Hass):
|
||||
def initialize(self):
|
||||
self.listen_state(self.motion, "binary_sensor.drive", new="on")
|
||||
|
||||
|
@ -13,13 +13,16 @@ The first step is to create a unique file within the apps directory (as defined
|
||||
```python
|
||||
import homeassistant.appapi as appapi
|
||||
|
||||
|
||||
class MotionLights(appapi.AppDaemon):
|
||||
"""Motion lights implementation."""
|
||||
```
|
||||
|
||||
When configured as an app in the config file (more on that later) the lifecycle of the App begins. It will be instantiated as an object by AppDaemon, and immediately, it will have a call made to its `initialize()` function - this function must appear as part of every app:
|
||||
|
||||
```python
|
||||
def initialize(self):
|
||||
"""Perform initialization."""
|
||||
```
|
||||
|
||||
The initialize function allows the app to register any callbacks it might need for responding to state changes, and also any setup activities. When the `initialize()` function returns, the App will be dormant until any of its callbacks are activated.
|
||||
@ -410,7 +413,8 @@ When calling back into the App, the App must provide a class function with a kno
|
||||
|
||||
```python
|
||||
def my_callback(self, entity, attribute, old, new, **kwargs):
|
||||
<do some useful work here>
|
||||
"""Handle state callback."""
|
||||
# do some useful work here
|
||||
```
|
||||
|
||||
You can call the function whatever you like - you will reference it in the `listen_state()` call, and you can create as many callback functions as you need.
|
||||
@ -493,7 +497,8 @@ If duration is supplied as a parameter, the callback will not fire unless the st
|
||||
|
||||
```python
|
||||
def my_callback(self, **kwargs):
|
||||
<do some useful work here>
|
||||
"""Handle state change."""
|
||||
# do some useful work here
|
||||
```
|
||||
|
||||
(Scheduler callbacks are documented in detail later in this document)
|
||||
@ -518,17 +523,22 @@ self.handle = self.listen_state(self.my_callback, "light.office_1")
|
||||
self.handle = self.listen_state(self.my_callback, "light.office_1", attribute="all")
|
||||
|
||||
# Listen for a state change involving the brightness attribute of light.office1
|
||||
self.handle = self.listen_state(self.my_callback, "light.office_1", attribute = "brightness")
|
||||
self.handle = self.listen_state(
|
||||
self.my_callback, "light.office_1", attribute="brightness"
|
||||
)
|
||||
|
||||
# Listen for a state change involving light.office1 turning on and return the state attribute
|
||||
self.handle = self.listen_state(self.my_callback, "light.office_1", new="on")
|
||||
|
||||
# Listen for a state change involving light.office1 changing from brightness 100 to 200 and return the state attribute
|
||||
self.handle = self.listen_state(self.my_callback, "light.office_1", old = "100", new = "200")
|
||||
self.handle = self.listen_state(
|
||||
self.my_callback, "light.office_1", old="100", new="200"
|
||||
)
|
||||
|
||||
# Listen for a state change involving light.office1 changing to state on and remaining on for a minute
|
||||
self.handle = self.listen_state(self.my_callback, "light.office_1", new = "on", duration = 60)
|
||||
|
||||
self.handle = self.listen_state(
|
||||
self.my_callback, "light.office_1", new="on", duration=60
|
||||
)
|
||||
```
|
||||
|
||||
### cancel_listen_state()
|
||||
@ -593,7 +603,8 @@ As with State Change callbacks, Scheduler Callbacks expect to call into function
|
||||
|
||||
```python
|
||||
def my_callback(self, **kwargs):
|
||||
<do some useful work here>
|
||||
"""Handle scheduler callback."""
|
||||
# do some useful work here
|
||||
```
|
||||
|
||||
You can call the function whatever you like; you will reference it in the Scheduler call, and you can create as many callback functions as you need.
|
||||
@ -678,6 +689,7 @@ Arbitrary keyword parameters to be provided to the callback function when it is
|
||||
```python
|
||||
# Run at 4pm today, or 4pm tomorrow if it is already after 4pm
|
||||
import datetime
|
||||
|
||||
...
|
||||
runtime = datetime.time(16, 0, 0)
|
||||
handle = self.run_once(self.run_once_c, runtime)
|
||||
@ -716,6 +728,7 @@ Arbitrary keyword parameters to be provided to the callback function when it is
|
||||
```python
|
||||
# Run at 4pm today
|
||||
import datetime
|
||||
|
||||
...
|
||||
runtime = datetime.time(16, 0, 0)
|
||||
today = datetime.date.today()
|
||||
@ -755,6 +768,7 @@ Arbitrary keyword parameters to be provided to the callback function when it is
|
||||
```python
|
||||
# Run daily at 7pm
|
||||
import datetime
|
||||
|
||||
...
|
||||
time = datetime.time(19, 0, 0)
|
||||
self.run_daily(self.run_daily_c, runtime)
|
||||
@ -793,6 +807,7 @@ Arbitrary keyword parameters to be provided to the callback function when it is
|
||||
```python
|
||||
# Run every hour, on the hour
|
||||
import datetime
|
||||
|
||||
...
|
||||
time = datetime.time(0, 0, 0)
|
||||
self.run_daily(self.run_daily_c, runtime)
|
||||
@ -830,6 +845,7 @@ Arbitrary keyword parameters to be provided to the callback function when it is
|
||||
```python
|
||||
# Run Every Minute on the minute
|
||||
import datetime
|
||||
|
||||
...
|
||||
time = datetime.time(0, 0, 0)
|
||||
self.run_minutely(self.run_minutely_c, time)
|
||||
@ -872,6 +888,7 @@ Arbitrary keyword parameters to be provided to the callback function when it is
|
||||
```python
|
||||
# Run every 17 minutes starting in 2 hours time
|
||||
import datetime
|
||||
|
||||
...
|
||||
self.run_every(self.run_every_c, time, 17 * 60)
|
||||
```
|
||||
@ -987,15 +1004,17 @@ Arbitrary keyword parameters to be provided to the callback function when it is
|
||||
|
||||
```python
|
||||
import datetime
|
||||
...
|
||||
|
||||
# ...
|
||||
|
||||
# Run 45 minutes before sunset
|
||||
self.run_at_sunrise(self.sun, offset = datetime.timedelta(minutes = -45).total_seconds(), "Sunrise -45 mins")
|
||||
self.run_at_sunrise(self.sun, offset=datetime.timedelta(minutes=-45).total_seconds())
|
||||
# or you can just do the math yourself
|
||||
self.run_at_sunrise(self.sun, offset = 30 * 60, "Sunrise +30 mins")
|
||||
self.run_at_sunrise(self.sun, offset=30 * 60) # Sunrise +30 mins
|
||||
# Run at a random time +/- 60 minutes from sunrise
|
||||
self.run_at_sunrise(self.sun, random_start = -60*60, random_end = 60*60, "Sunrise, random +/- 60 mins")
|
||||
self.run_at_sunrise(self.sun, random_start=-60 * 60, random_end=60 * 60)
|
||||
# Run at a random time between 30 and 60 minutes before sunrise
|
||||
self.run_at_sunrise(self.sun, random_start = -60*60, random_end = 30*60, "Sunrise, random - 30 - 60 mins")
|
||||
self.run_at_sunrise(self.sun, random_start=-60 * 60, random_end=30 * 60)
|
||||
```
|
||||
|
||||
### run_at_sunset()
|
||||
@ -1031,14 +1050,18 @@ Arbitrary keyword parameters to be provided to the callback function when it is
|
||||
```python
|
||||
# Example using timedelta
|
||||
import datetime
|
||||
...
|
||||
self.run_at_sunset(self.sun, datetime.timedelta(minutes = -45).total_seconds(), "Sunset -45 mins")
|
||||
|
||||
# ...
|
||||
|
||||
self.run_at_sunset(
|
||||
self.sun, datetime.timedelta(minutes=-45).total_seconds()
|
||||
) # Sunset -45 mins
|
||||
# or you can just do the math yourself
|
||||
self.run_at_sunset(self.sun, 30 * 60, "Sunset +30 mins")
|
||||
self.run_at_sunset(self.sun, 30 * 60) # Sunset +30 mins
|
||||
# Run at a random time +/- 60 minutes from sunset
|
||||
self.run_at_sunset(self.sun, random_start = -60*60, random_end = 60*60, "Sunset, random +/- 60 mins")
|
||||
self.run_at_sunset(self.sun, random_start=-60 * 60, random_end=60 * 60)
|
||||
# Run at a random time between 30 and 60 minutes before sunset
|
||||
self.run_at_sunset(self.sun, random_start = -60*60, random_end = 30*60, "Sunset, random - 30 - 60 mins")
|
||||
self.run_at_sunset(self.sun, random_start=-60 * 60, random_end=30 * 60)
|
||||
```
|
||||
### sunrise()
|
||||
|
||||
@ -1096,7 +1119,7 @@ result = self.sun_up()
|
||||
|
||||
```python
|
||||
if self.sun_up():
|
||||
do something
|
||||
do_something()
|
||||
```
|
||||
|
||||
### sun_down()
|
||||
@ -1117,7 +1140,7 @@ result = self.sun_down()
|
||||
|
||||
```python
|
||||
if self.sun_down():
|
||||
do something
|
||||
do_something()
|
||||
```
|
||||
|
||||
## Calling Services
|
||||
@ -1366,7 +1389,8 @@ As with State Change and Scheduler callbacks, Event Callbacks expect to call int
|
||||
|
||||
```python
|
||||
def my_callback(self, event_name, data, kwargs):
|
||||
<do some useful work here>
|
||||
"""Handle event callback."""
|
||||
# do some useful work here
|
||||
```
|
||||
|
||||
You can call the function whatever you like - you will reference it in the Scheduler call, and you can create as many callback functions as you need.
|
||||
@ -1396,7 +1420,7 @@ Listen event sets up a callback for a specific event, or any event.
|
||||
#### Synopsis
|
||||
|
||||
```python
|
||||
handle = listen_event(function, event = None, **kwargs):
|
||||
handle = listen_event(function, event=None, **kwargs)
|
||||
```
|
||||
#### Returns
|
||||
|
||||
@ -1427,7 +1451,9 @@ self.listen_event(self.mode_event, "MODE_CHANGE")
|
||||
# Listen for a minimote event activating scene 3:
|
||||
self.listen_event(self.generic_event, "zwave.scene_activated", scene_id=3)
|
||||
# Listen for a minimote event activating scene 3 from a specific minimote:
|
||||
self.listen_event(self.generic_event, "zwave.scene_activated", entity_id = "minimote_31", scene_id = 3)
|
||||
self.listen_event(
|
||||
self.generic_event, "zwave.scene_activated", entity_id="minimote_31", scene_id=3
|
||||
)
|
||||
```
|
||||
|
||||
### cancel_listen_event()
|
||||
@ -1518,6 +1544,7 @@ Functions called as an event callback will be supplied with 2 arguments:
|
||||
|
||||
```python
|
||||
def service(self, event_name, data):
|
||||
"""Handle event."""
|
||||
```
|
||||
|
||||
#### event_name
|
||||
@ -1585,7 +1612,7 @@ An iterable list of all device trackers.
|
||||
```python
|
||||
trackers = self.get_trackers()
|
||||
for tracker in trackers:
|
||||
do something
|
||||
do_something(tracker)
|
||||
```
|
||||
|
||||
### get_tracker_state()
|
||||
@ -1638,7 +1665,7 @@ Returns `True` if everyone is at home, `False` otherwise.
|
||||
|
||||
```python
|
||||
if self.everyone_home():
|
||||
do something
|
||||
do_something()
|
||||
```
|
||||
### anyone_home()
|
||||
|
||||
@ -1658,7 +1685,7 @@ Returns `True` if anyone is at home, `False` otherwise.
|
||||
|
||||
```python
|
||||
if self.anyone_home():
|
||||
do something
|
||||
do_something()
|
||||
```
|
||||
### noone_home()
|
||||
|
||||
@ -1678,7 +1705,7 @@ Returns `True` if no one is home, `False` otherwise.
|
||||
|
||||
```python
|
||||
if self.noone_home():
|
||||
do something
|
||||
do_something()
|
||||
```
|
||||
|
||||
## Miscellaneous Helper Functions
|
||||
@ -1837,9 +1864,9 @@ A representation of the start and end time respectively in a string format with
|
||||
|
||||
```python
|
||||
if self.now_is_between("17:30:00", "08:00:00"):
|
||||
do something
|
||||
do_something()
|
||||
if self.now_is_between("sunset - 00:45:00", "sunrise + 00:45:00"):
|
||||
do something
|
||||
do_something_else()
|
||||
```
|
||||
|
||||
### friendly_name()
|
||||
@ -1860,7 +1887,11 @@ The friendly name of the entity if it exists or the entity id if not.
|
||||
|
||||
```python
|
||||
tracker = "device_tracker.andrew"
|
||||
self.log("{} ({}) is {}".format(tracker, self.friendly_name(tracker), self.get_tracker_state(tracker)))
|
||||
self.log(
|
||||
"{} ({}) is {}".format(
|
||||
tracker, self.friendly_name(tracker), self.get_tracker_state(tracker)
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
### split_entity()
|
||||
@ -1888,7 +1919,7 @@ A list with 2 entries, the device and entity respectively.
|
||||
```python
|
||||
device, entity = self.split_entity(entity_id)
|
||||
if device == "scene":
|
||||
do something specific to scenes
|
||||
do_something_specific_to_scenes()
|
||||
```
|
||||
|
||||
|
||||
@ -1935,7 +1966,7 @@ A list of split devices with 1 or more entries.
|
||||
|
||||
```python
|
||||
for sensor in self.split_device_list(self.args["sensors"]):
|
||||
do something for each sensor, e.g., make a state subscription
|
||||
do_something(sensor) # e.g. make a state subscription
|
||||
```
|
||||
|
||||
|
||||
@ -2007,7 +2038,7 @@ Sharing information between different Apps is very simple if required. Each app
|
||||
In addition, Apps have access to the entire configuration if required, meaning they can access AppDaemon configuration items as well as parameters from other Apps. To use this, there is a class attribute called `self.config`. It contains a `ConfigParser` object, which is similar in operation to a `Dictionary`. To access any apps parameters, simply reference the ConfigParser object using the Apps name (form the config file) as the first key, and the parameter required as the second, for instance:
|
||||
|
||||
```python
|
||||
other_apps_arg = self.config["some_app"]["some_parameter"].
|
||||
other_apps_arg = self.config["some_app"]["some_parameter"]
|
||||
```
|
||||
|
||||
To get AppDaemon's config parameters, use the key "AppDaemon", e.g.:
|
||||
|
@ -58,8 +58,8 @@ different scenes in a different version of the App.
|
||||
```python
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
|
||||
class OutsideLights(hass.Hass):
|
||||
|
||||
class OutsideLights(hass.Hass):
|
||||
def initialize(self):
|
||||
self.run_at_sunrise(self.sunrise_cb)
|
||||
self.run_at_sunset(self.before_sunset_cb, offset=-900)
|
||||
@ -69,7 +69,6 @@ different scenes in a different version of the App.
|
||||
|
||||
def before_sunset_cb(self, kwargs):
|
||||
self.turn_on(self.args["on_scene"])
|
||||
|
||||
```
|
||||
|
||||
This is also fairly easy to achieve with Home Assistant automations, but we are just getting started.
|
||||
@ -81,8 +80,8 @@ Our next example is to turn on a light when motion is detected and it is dark, a
|
||||
```python
|
||||
import appdaemon.appapi as appapi
|
||||
|
||||
class FlashyMotionLights(appapi.AppDaemon):
|
||||
|
||||
class FlashyMotionLights(appapi.AppDaemon):
|
||||
def initialize(self):
|
||||
self.listen_state(self.motion, "binary_sensor.drive", new="on")
|
||||
|
||||
@ -102,8 +101,8 @@ Now lets extend this with a somewhat artificial example to show something that i
|
||||
```python
|
||||
import homeassistant.appapi as appapi
|
||||
|
||||
class MotionLights(appapi.AppDaemon):
|
||||
|
||||
class MotionLights(appapi.AppDaemon):
|
||||
def initialize(self):
|
||||
self.listen_state(self.motion, "binary_sensor.drive", new="on")
|
||||
|
||||
|
@ -154,7 +154,7 @@ for x in range(0, 10):
|
||||
translations["%s" % x] = "\\x3%s" % x
|
||||
|
||||
for c in sys.argv[1]:
|
||||
print(translations[c], end='')
|
||||
print(translations[c], end="")
|
||||
```
|
||||
|
||||
## OZW Log
|
||||
|
@ -51,7 +51,7 @@ entity_id:
|
||||
title:
|
||||
description: >
|
||||
A title to be used for the notification if the notifier supports it
|
||||
with [template][template] support.
|
||||
with [template](/docs/configuration/templating/) support.
|
||||
required: false
|
||||
type: template
|
||||
state:
|
||||
@ -80,13 +80,13 @@ skip_first:
|
||||
message:
|
||||
description: >
|
||||
A message to be sent after an alert transitions from `off` to `on`
|
||||
with [template][template] support.
|
||||
with [template](/docs/configuration/templating/) support.
|
||||
required: false
|
||||
type: template
|
||||
done_message:
|
||||
description: >
|
||||
A message sent after an alert transitions from `on` to `off` with
|
||||
[template][template] support. Is only sent if an alert notification
|
||||
[template](/docs/configuration/templating/) support. Is only sent if an alert notification
|
||||
was sent for transitioning from `off` to `on`.
|
||||
required: false
|
||||
type: template
|
||||
@ -205,7 +205,7 @@ sent at 2:15, 2:45, 3:45, 4:45, etc., continuing every 60 minutes.
|
||||
### Message Templates
|
||||
|
||||
It may be desirable to have the alert notifications include information
|
||||
about the state of the entity. [Templates](/docs/configuration/templating/)
|
||||
about the state of the entity. [Templates][template]
|
||||
can be used in the message or name of the alert to make it more relevant.
|
||||
The following will show for a plant how to include the problem `attribute`
|
||||
of the entity.
|
||||
|
@ -223,6 +223,7 @@ import appdaemon.plugins.hass.hassapi as hass
|
||||
import datetime
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class DeconzHelper(hass.Hass):
|
||||
def initialize(self) -> None:
|
||||
self.listen_event(self.event_received, "deconz_event")
|
||||
@ -232,8 +233,15 @@ class DeconzHelper(hass.Hass):
|
||||
event_id = data["id"]
|
||||
event_received = datetime.now()
|
||||
|
||||
self.log("Deconz event received from {}. Event was: {}".format(event_id, event_data))
|
||||
self.set_state("sensor.deconz_event", state = event_id, attributes = {"event_data": event_data, "event_received": str(event_received)})
|
||||
self.log(f"Deconz event received from {event_id}. Event was: {event_data}")
|
||||
self.set_state(
|
||||
"sensor.deconz_event",
|
||||
state=event_id,
|
||||
attributes={
|
||||
"event_data": event_data,
|
||||
"event_received": str(event_received),
|
||||
},
|
||||
)
|
||||
```
|
||||
|
||||
{% endraw %}
|
||||
@ -255,23 +263,23 @@ remote_control:
|
||||
```python
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
|
||||
class RemoteControl(hass.Hass):
|
||||
|
||||
class RemoteControl(hass.Hass):
|
||||
def initialize(self):
|
||||
if 'event' in self.args:
|
||||
self.listen_event(self.handle_event, self.args['event'])
|
||||
if "event" in self.args:
|
||||
self.listen_event(self.handle_event, self.args["event"])
|
||||
|
||||
def handle_event(self, event_name, data, kwargs):
|
||||
if data['id'] == self.args['id']:
|
||||
self.log(data['event'])
|
||||
if data['event'] == 1002:
|
||||
self.log('Button on')
|
||||
elif data['event'] == 2002:
|
||||
self.log('Button dim up')
|
||||
elif data['event'] == 3002:
|
||||
self.log('Button dim down')
|
||||
elif data['event'] == 4002:
|
||||
self.log('Button off')
|
||||
if data["id"] == self.args["id"]:
|
||||
self.log(data["event"])
|
||||
if data["event"] == 1002:
|
||||
self.log("Button on")
|
||||
elif data["event"] == 2002:
|
||||
self.log("Button dim up")
|
||||
elif data["event"] == 3002:
|
||||
self.log("Button dim down")
|
||||
elif data["event"] == 4002:
|
||||
self.log("Button off")
|
||||
```
|
||||
|
||||
{% endraw %}
|
||||
@ -298,33 +306,35 @@ sonos_remote_control:
|
||||
```python
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
|
||||
class SonosRemote(hass.Hass):
|
||||
|
||||
class SonosRemote(hass.Hass):
|
||||
def initialize(self):
|
||||
self.sonos = self.args['sonos']
|
||||
if 'event' in self.args:
|
||||
self.listen_event(self.handle_event, self.args['event'])
|
||||
self.sonos = self.args["sonos"]
|
||||
if "event" in self.args:
|
||||
self.listen_event(self.handle_event, self.args["event"])
|
||||
|
||||
def handle_event(self, event_name, data, kwargs):
|
||||
if data['id'] == self.args['id']:
|
||||
if data['event'] == 1002:
|
||||
self.log('Button toggle')
|
||||
if data["id"] == self.args["id"]:
|
||||
if data["event"] == 1002:
|
||||
self.log("Button toggle")
|
||||
self.call_service("media_player/media_play_pause", entity_id=self.sonos)
|
||||
|
||||
elif data['event'] == 2002:
|
||||
self.log('Button volume up')
|
||||
elif data["event"] == 2002:
|
||||
self.log("Button volume up")
|
||||
self.call_service("media_player/volume_up", entity_id=self.sonos)
|
||||
|
||||
elif data['event'] == 3002:
|
||||
self.log('Button volume down')
|
||||
elif data["event"] == 3002:
|
||||
self.log("Button volume down")
|
||||
self.call_service("media_player/volume_down", entity_id=self.sonos)
|
||||
|
||||
elif data['event'] == 4002:
|
||||
self.log('Button previous')
|
||||
self.call_service("media_player/media_previous_track", entity_id = self.sonos)
|
||||
elif data["event"] == 4002:
|
||||
self.log("Button previous")
|
||||
self.call_service(
|
||||
"media_player/media_previous_track", entity_id=self.sonos
|
||||
)
|
||||
|
||||
elif data['event'] == 5002:
|
||||
self.log('Button next')
|
||||
elif data["event"] == 5002:
|
||||
self.log("Button next")
|
||||
self.call_service("media_player/media_next_track", entity_id=self.sonos)
|
||||
```
|
||||
|
||||
|
@ -30,7 +30,7 @@ As it suggests the region name is not the city or nearest city you want to get t
|
||||
|
||||
Be aware, to get the region name you need to use the following link by replacing `Hamburg` with your city:
|
||||
- Find your region here: `https://www.dwd.de/DE/wetter/warnungen_landkreise/warnWetter_node.html?ort=Hamburg`
|
||||
- On the page that is loaded in your browser you will find the correct region ("Kreis") below the map as a headding.
|
||||
- On the page that is loaded in your browser you will find the correct region ("Kreis") below the map as a heading.
|
||||
- Verify if you find any warning for your region here. Your region ("Kreis") will appear only if warnings exist: `https://www.dwd.de/DWD/warnungen/warnapp_landkreise/json/warnings.json?jsonp=loadWarnings`
|
||||
|
||||
</div>
|
||||
|
@ -161,6 +161,7 @@ in seconds since the UNIX epoch. Convert them manually using
|
||||
|
||||
```python
|
||||
from datetime import datetime
|
||||
|
||||
datetime.fromtimestamp(1422830502)
|
||||
```
|
||||
|
||||
|
@ -222,9 +222,13 @@ As already shown on the [API](/developers/rest_api/) page, it's very simple to u
|
||||
|
||||
```python
|
||||
response = requests.post(
|
||||
'http://localhost:8123/api/states/binary_sensor.radio',
|
||||
headers={'Authorization': 'Bearer LONG_LIVED_ACCESS_TOKEN', 'content-type': 'application/json'},
|
||||
data=json.dumps({'state': 'on', 'attributes': {'friendly_name': 'Radio'}}))
|
||||
"http://localhost:8123/api/states/binary_sensor.radio",
|
||||
headers={
|
||||
"Authorization": "Bearer LONG_LIVED_ACCESS_TOKEN",
|
||||
"content-type": "application/json",
|
||||
},
|
||||
data=json.dumps({"state": "on", "attributes": {"friendly_name": "Radio"}}),
|
||||
)
|
||||
print(response.text)
|
||||
```
|
||||
|
||||
|
@ -32,8 +32,8 @@ It is not possible to use Python imports with this integration. If you want to d
|
||||
- Create a file `hello_world.py` in the folder and give it this content:
|
||||
|
||||
```python
|
||||
name = data.get('name', 'world')
|
||||
logger.info("Hello {}".format(name))
|
||||
name = data.get("name", "world")
|
||||
logger.info("Hello %s", name)
|
||||
hass.bus.fire(name, {"wow": "from a Python script!"})
|
||||
```
|
||||
|
||||
@ -50,11 +50,11 @@ The following example shows how to call a service from `python_script`. This scr
|
||||
|
||||
```python
|
||||
# turn_on_light.py
|
||||
entity_id = data.get('entity_id')
|
||||
rgb_color = data.get('rgb_color', [255, 255, 255])
|
||||
entity_id = data.get("entity_id")
|
||||
rgb_color = data.get("rgb_color", [255, 255, 255])
|
||||
if entity_id is not None:
|
||||
service_data = {'entity_id': entity_id, 'rgb_color': rgb_color, 'brightness': 255 }
|
||||
hass.services.call('light', 'turn_on', service_data, False)
|
||||
service_data = {"entity_id": entity_id, "rgb_color": rgb_color, "brightness": 255}
|
||||
hass.services.call("light", "turn_on", service_data, False)
|
||||
```
|
||||
The above `python_script` can be called using the following JSON as an input.
|
||||
|
||||
|
@ -137,19 +137,19 @@ You can then use the following `python_script` to save the video file:
|
||||
```python
|
||||
# obtain ring doorbell camera object
|
||||
# replace the camera.front_door by your camera entity
|
||||
ring_cam = hass.states.get('camera.front_door')
|
||||
ring_cam = hass.states.get("camera.front_door")
|
||||
|
||||
subdir_name = 'ring_{}'.format(ring_cam.attributes.get('friendly_name'))
|
||||
subdir_name = f"ring_{ring_cam.attributes.get('friendly_name')}"
|
||||
|
||||
# get video URL
|
||||
data = {
|
||||
'url': ring_cam.attributes.get('video_url'),
|
||||
'subdir': subdir_name,
|
||||
'filename': ring_cam.attributes.get('friendly_name')
|
||||
"url": ring_cam.attributes.get("video_url"),
|
||||
"subdir": subdir_name,
|
||||
"filename": ring_cam.attributes.get("friendly_name"),
|
||||
}
|
||||
|
||||
# call downloader integration to save the video
|
||||
hass.services.call('downloader', 'download_file', data)
|
||||
hass.services.call("downloader", "download_file", data)
|
||||
```
|
||||
|
||||
## Sensor
|
||||
|
@ -155,8 +155,9 @@ The script (saved as `arest-value.py`) that is used looks like the example below
|
||||
```python
|
||||
#!/usr/bin/python3
|
||||
from requests import get
|
||||
response = get('http://10.0.0.48/analog/2')
|
||||
print(response.json()['return_value'])
|
||||
|
||||
response = get("http://10.0.0.48/analog/2")
|
||||
print(response.json()["return_value"])
|
||||
```
|
||||
|
||||
To use the script you need to add something like the following to your `configuration.yaml` file.
|
||||
|
@ -53,7 +53,7 @@ The result set will include your chat ID as `id` in the `chat` section:
|
||||
|
||||
**Method 3:** Another way to get your chat ID directly is described below. Start your Python interpreter from the command-line:
|
||||
|
||||
```python
|
||||
```shell
|
||||
$ python3
|
||||
>>> import telegram
|
||||
>>> bot = telegram.Bot(token='YOUR_API_TOKEN')
|
||||
|
@ -424,76 +424,90 @@ This is how the previous 4 automations would be through a simple AppDaemon app:
|
||||
```python
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
|
||||
|
||||
class TelegramBotEventListener(hass.Hass):
|
||||
"""Event listener for Telegram bot events."""
|
||||
|
||||
def initialize(self):
|
||||
"""Listen to Telegram Bot events of interest."""
|
||||
self.listen_event(self.receive_telegram_text, 'telegram_text')
|
||||
self.listen_event(self.receive_telegram_callback, 'telegram_callback')
|
||||
self.listen_event(self.receive_telegram_text, "telegram_text")
|
||||
self.listen_event(self.receive_telegram_callback, "telegram_callback")
|
||||
|
||||
def receive_telegram_text(self, event_id, payload_event, *args):
|
||||
"""Text repeater."""
|
||||
assert event_id == 'telegram_text'
|
||||
user_id = payload_event['user_id']
|
||||
msg = 'You said: ``` %s ```' % payload_event['text']
|
||||
keyboard = [[("Edit message", "/edit_msg"),
|
||||
("Don't", "/do_nothing")],
|
||||
[("Remove this button", "/remove button")]]
|
||||
self.call_service('telegram_bot/send_message',
|
||||
title='*Dumb automation*',
|
||||
assert event_id == "telegram_text"
|
||||
user_id = payload_event["user_id"]
|
||||
msg = "You said: ``` %s ```" % payload_event["text"]
|
||||
keyboard = [
|
||||
[("Edit message", "/edit_msg"), ("Don't", "/do_nothing")],
|
||||
[("Remove this button", "/remove button")],
|
||||
]
|
||||
self.call_service(
|
||||
"telegram_bot/send_message",
|
||||
title="*Dumb automation*",
|
||||
target=user_id,
|
||||
message=msg,
|
||||
disable_notification=True,
|
||||
inline_keyboard=keyboard)
|
||||
inline_keyboard=keyboard,
|
||||
)
|
||||
|
||||
def receive_telegram_callback(self, event_id, payload_event, *args):
|
||||
"""Event listener for Telegram callback queries."""
|
||||
assert event_id == 'telegram_callback'
|
||||
data_callback = payload_event['data']
|
||||
callback_id = payload_event['id']
|
||||
chat_id = payload_event['chat_id']
|
||||
assert event_id == "telegram_callback"
|
||||
data_callback = payload_event["data"]
|
||||
callback_id = payload_event["id"]
|
||||
chat_id = payload_event["chat_id"]
|
||||
# keyboard = ["Edit message:/edit_msg, Don't:/do_nothing",
|
||||
# "Remove this button:/remove button"]
|
||||
keyboard = [[("Edit message", "/edit_msg"),
|
||||
("Don't", "/do_nothing")],
|
||||
[("Remove this button", "/remove button")]]
|
||||
keyboard = [
|
||||
[("Edit message", "/edit_msg"), ("Don't", "/do_nothing")],
|
||||
[("Remove this button", "/remove button")],
|
||||
]
|
||||
|
||||
if data_callback == '/edit_msg': # Message editor:
|
||||
if data_callback == "/edit_msg": # Message editor:
|
||||
# Answer callback query
|
||||
self.call_service('telegram_bot/answer_callback_query',
|
||||
message='Editing the message!',
|
||||
self.call_service(
|
||||
"telegram_bot/answer_callback_query",
|
||||
message="Editing the message!",
|
||||
callback_query_id=callback_id,
|
||||
show_alert=True)
|
||||
show_alert=True,
|
||||
)
|
||||
|
||||
# Edit the message origin of the callback query
|
||||
msg_id = payload_event['message']['message_id']
|
||||
user = payload_event['from_first']
|
||||
title = '*Message edit*'
|
||||
msg = 'Callback received from %s. Message id: %s. Data: ``` %s ```'
|
||||
self.call_service('telegram_bot/edit_message',
|
||||
msg_id = payload_event["message"]["message_id"]
|
||||
user = payload_event["from_first"]
|
||||
title = "*Message edit*"
|
||||
msg = "Callback received from %s. Message id: %s. Data: ``` %s ```"
|
||||
self.call_service(
|
||||
"telegram_bot/edit_message",
|
||||
chat_id=chat_id,
|
||||
message_id=msg_id,
|
||||
title=title,
|
||||
message=msg % (user, msg_id, data_callback),
|
||||
inline_keyboard=keyboard)
|
||||
inline_keyboard=keyboard,
|
||||
)
|
||||
|
||||
elif data_callback == '/remove button': # Keyboard editor:
|
||||
elif data_callback == "/remove button": # Keyboard editor:
|
||||
# Answer callback query
|
||||
self.call_service('telegram_bot/answer_callback_query',
|
||||
message='Callback received for editing the '
|
||||
'inline keyboard!',
|
||||
callback_query_id=callback_id)
|
||||
self.call_service(
|
||||
"telegram_bot/answer_callback_query",
|
||||
message="Callback received for editing the " "inline keyboard!",
|
||||
callback_query_id=callback_id,
|
||||
)
|
||||
|
||||
# Edit the keyboard
|
||||
new_keyboard = keyboard[:1]
|
||||
self.call_service('telegram_bot/edit_replymarkup',
|
||||
self.call_service(
|
||||
"telegram_bot/edit_replymarkup",
|
||||
chat_id=chat_id,
|
||||
message_id='last',
|
||||
inline_keyboard=new_keyboard)
|
||||
message_id="last",
|
||||
inline_keyboard=new_keyboard,
|
||||
)
|
||||
|
||||
elif data_callback == '/do_nothing': # Only Answer to callback query
|
||||
self.call_service('telegram_bot/answer_callback_query',
|
||||
message='OK, you said no!',
|
||||
callback_query_id=callback_id)
|
||||
elif data_callback == "/do_nothing": # Only Answer to callback query
|
||||
self.call_service(
|
||||
"telegram_bot/answer_callback_query",
|
||||
message="OK, you said no!",
|
||||
callback_query_id=callback_id,
|
||||
)
|
||||
```
|
||||
|
@ -36,6 +36,6 @@ name:
|
||||
|
||||
For valid time zones check the **TZ** column in the [Wikipedia overview](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Or get the full list from the [pytz](https://pypi.python.org/pypi/pytz) module.
|
||||
|
||||
```python
|
||||
```shell
|
||||
python3 -c "import pytz;print(pytz.all_timezones)"
|
||||
```
|
||||
|
@ -315,7 +315,7 @@ All services for use in Home Assistant are moved to their integration naming spa
|
||||
## Release 0.103.4 - December 22
|
||||
|
||||
- Remove requirement from entity integration ([@balloob] - [#30113]) ([doods docs]) ([image_processing docs]) ([seven_segments docs]) ([tensorflow docs])
|
||||
- Move imports into setup function in homekit __init__.py ([@springstan] - [#30137]) ([homekit docs])
|
||||
- Move imports into setup function in homekit **init**.py ([@springstan] - [#30137]) ([homekit docs])
|
||||
- Fix deconz SSDP updating Hassio discovery ([@frenck] - [#30153]) ([deconz docs])
|
||||
- Allow battery value of 0 as well as make sure to not create a battery tracker if one already exist ([@Kane610] - [#30155]) ([deconz docs])
|
||||
|
||||
@ -323,7 +323,7 @@ All services for use in Home Assistant are moved to their integration naming spa
|
||||
[#30137]: https://github.com/home-assistant/home-assistant/pull/30137
|
||||
[#30153]: https://github.com/home-assistant/home-assistant/pull/30153
|
||||
[#30155]: https://github.com/home-assistant/home-assistant/pull/30155
|
||||
[@Kane610]: https://github.com/Kane610
|
||||
[@kane610]: https://github.com/Kane610
|
||||
[@balloob]: https://github.com/balloob
|
||||
[@frenck]: https://github.com/frenck
|
||||
[@springstan]: https://github.com/springstan
|
||||
@ -342,6 +342,27 @@ All services for use in Home Assistant are moved to their integration naming spa
|
||||
[@tchellomello]: https://github.com/tchellomello
|
||||
[ring docs]: /components/ring/
|
||||
|
||||
## Release 0.103.6 - January 6
|
||||
|
||||
- Handle wired bug on restart ([@Kane610] - [#30276]) ([unifi docs])
|
||||
- Bump pysmartthings 0.7.0 ([@andrewsayre] - [#30302]) ([smartthings docs])
|
||||
- Bump env_canada to 0.0.31 ([@michaeldavie] - [#30409]) ([environment_canada docs])
|
||||
- Fix google sync ([@balloob] - [#30524]) ([cloud docs]) ([google_assistant docs])
|
||||
|
||||
[#30276]: https://github.com/home-assistant/home-assistant/pull/30276
|
||||
[#30302]: https://github.com/home-assistant/home-assistant/pull/30302
|
||||
[#30409]: https://github.com/home-assistant/home-assistant/pull/30409
|
||||
[#30524]: https://github.com/home-assistant/home-assistant/pull/30524
|
||||
[@kane610]: https://github.com/Kane610
|
||||
[@andrewsayre]: https://github.com/andrewsayre
|
||||
[@balloob]: https://github.com/balloob
|
||||
[@michaeldavie]: https://github.com/michaeldavie
|
||||
[cloud docs]: /integrations/cloud/
|
||||
[environment_canada docs]: /integrations/environment_canada/
|
||||
[google_assistant docs]: /integrations/google_assistant/
|
||||
[smartthings docs]: /integrations/smartthings/
|
||||
[unifi docs]: /integrations/unifi/
|
||||
|
||||
## If you need help...
|
||||
|
||||
...don't hesitate to use our very active [forums](https://community.home-assistant.io/) or join us for a little [chat](https://discord.gg/c5DvZ4e).
|
||||
|
@ -16,7 +16,6 @@ The following will take you through the steps required to install Hass.io.
|
||||
- [Tinkerboard][tinker]
|
||||
- [Odroid-C2][odroid-c2]
|
||||
- [Odroid-XU4][odroid-xu4]
|
||||
- [OrangePi-Prime][opi-prime]
|
||||
- [Intel-Nuc][intel-nuc]
|
||||
|
||||
- As a virtual appliance:
|
||||
@ -218,7 +217,6 @@ A detailed guide about running Hass.io as a virtual machine is available in the
|
||||
[tinker]: https://github.com/home-assistant/hassos/releases/download/3.7/hassos_tinker-3.7.img.gz
|
||||
[odroid-c2]: https://github.com/home-assistant/hassos/releases/download/3.7/hassos_odroid-c2-3.7.img.gz
|
||||
[odroid-xu4]: https://github.com/home-assistant/hassos/releases/download/3.7/hassos_odroid-xu4-3.7.img.gz
|
||||
[opi-prime]: https://github.com/home-assistant/hassos/releases/download/3.7/hassos_opi-prime-3.7.img.gz
|
||||
[intel-nuc]: https://github.com/home-assistant/hassos/releases/download/3.7/hassos_intel-nuc-3.7.img.gz
|
||||
[vmdk]: https://github.com/home-assistant/hassos/releases/download/3.7/hassos_ova-3.7.vmdk.gz
|
||||
[vhdx]: https://github.com/home-assistant/hassos/releases/download/3.7/hassos_ova-3.7.vhdx.gz
|
||||
|
Loading…
x
Reference in New Issue
Block a user