alexa-samples / alexa-smarthome

Resources for Alexa Smart Home developers.
https://alexa.design/smarthome
Other
680 stars 336 forks source link

My smarthome skill stopped discovering devices suddenly #116

Closed phantom-j closed 5 years ago

phantom-j commented 5 years ago

My smarthome skill suddenly stopped discovering devices but it's controlling already added devices .

this is my lambda function

` import logging import time import json import uuid import boto3

logger = logging.getLogger() logger.setLevel(logging.INFO)

client = boto3.client('iot-data')

user=boto3.client('cognito-idp')

s3 = boto3.client('s3') bucket = 'aur*****' def get_usersub(access_token): response=user.get_user(AccessToken=access_token) return response["UserAttributes"][0]["Value"]

def get_devices(user_id): response = s3.get_object(Bucket=bucket, Key=user_id+"/alexa.json")

print(response['Body'].read())

devicedata=json.loads(response['Body'].read())
MY_APPLIANCES=[]
for eachdevice in devicedata["Devices"]:
    for singledevice in eachdevice["device_list"]:
        MY_APPLIANCES.append(singledevice)
return MY_APPLIANCES

MY_APPLIANCES = [ ]

def lambda_handler(request, context):

try:
    logger.info("Directive:")
    logger.info(json.dumps(request, indent=4, sort_keys=True))
    #user_id=get_usersub(request['directive']['payload']['scope']['token'])
    version = get_directive_version(request)

    if version == "3":
        logger.info("Received v3 directive!")
        if request["directive"]["header"]["name"] == "Discover":
            response = handle_discovery_v3(request)
        else:
            response = handle_non_discovery_v3(request)

    else:
        logger.info("Received v2 directive!")
        if request["header"]["namespace"] == "Alexa.ConnectedHome.Discovery":
            response = handle_discovery()
        else:
            response = handle_non_discovery(request)

    logger.info("Response:")
    logger.info(json.dumps(response, indent=4, sort_keys=True))

    if version == "3":
        logger.info("Validate v3 response")

    return response
except ValueError as error:
    logger.error(error)
    raise

def handle_discovery(): header = { "namespace": "Alexa.ConnectedHome.Discovery", "name": "DiscoverAppliancesResponse", "payloadVersion": "2", "messageId": get_uuid() } payload = { "discoveredAppliances": MY_APPLIANCES } response = { "header": header, "payload": payload } return response

def handle_non_discovery(request): device_id = request['payload']['appliance']['applianceId'] request_name = request["header"]["name"]

if request_name == "TurnOnRequest":
    header = {
        "namespace": "Alexa.ConnectedHome.Control",
        "name": "TurnOnConfirmation",
        "payloadVersion": "2",
        "messageId": get_uuid()
    }
    payload = {}
    light = True
elif request_name == "TurnOffRequest":
    header = {
        "namespace": "Alexa.ConnectedHome.Control",
        "name": "TurnOffConfirmation",
        "payloadVersion": "2",
        "messageId": get_uuid()
    }
    light = False
elif request_name == "SetPercentageRequest":
    header = {
        "namespace": "Alexa.ConnectedHome.Control",
        "name": "SetPercentageConfirmation",
        "payloadVersion": "2",
        "messageId": get_uuid()
    }
    light = True

logger.info('turning %s %s' % ('on' if light else 'off', device_id))
response = client.update_thing_shadow(
    thingName=device_id,
    payload=json.dumps({
        "state": {
            "desired": {
                "light": light
            }
        }
    })
)
logger.info('received {}'.format(response))
payload = {}
response = {
    "header": header,
    "payload": payload
}
return response

def get_appliance_by_appliance_id(appliance_id): for appliance in MY_APPLIANCES: if appliance["applianceId"] == appliance_id: return appliance return None

def get_utc_timestamp(seconds=None): return time.strftime("%Y-%m-%dT%H:%M:%S.00Z", time.gmtime(seconds))

def get_uuid(): return str(uuid.uuid4())

def handle_discovery_v3(request): endpoints = [] user_id=get_usersub(request['directive']['payload']['scope']['token']) MY_APPLIANCES=get_devices(user_id) for appliance in MY_APPLIANCES: endpoints.append(get_endpoint_from_v2_appliance(appliance))

response = {
    "event": {
        "header": {
            "namespace": "Alexa.Discovery",
            "name": "Discover.Response",
            "payloadVersion": "3",
            "messageId": get_uuid()
        },
        "payload": {
            "endpoints": endpoints
        }
    }
}
return response

def handle_non_discovery_v3(request): request_namespace = request["directive"]["header"]["namespace"] request_name = request["directive"]["header"]["name"] device_id = request["directive"]["endpoint"]["endpointId"] user_id=get_usersub(request['directive']['endpoint']['scope']['token']) if request_namespace == "Alexa.PowerController": if request_name == "TurnOn": value = "ON" light = True elif request_name == "TurnOff": value = "OFF" light = False

    logger.info('turning %s %s' % ('on' if light else 'off', device_id))
    response = client.update_thing_shadow(
        thingName=user_id,
        payload=json.dumps({
            "state": {
                "desired": {
                    "alexa":{
                    device_id: ['power',{"binary":value}]
                    }
                }
            }
        })
    )
    logger.info('received {}'.format(response))

    response = {
        "context": {
            "properties": [
                {
                    "namespace": "Alexa.PowerController",
                    "name": "powerState",
                    "value": value,
                    "timeOfSample": get_utc_timestamp(),
                    "uncertaintyInMilliseconds": 500
                }
            ]
        },
        "event": {
            "header": {
                "namespace": "Alexa",
                "name": "Response",
                "payloadVersion": "3",
                "messageId": get_uuid(),
                "correlationToken": request["directive"]["header"]["correlationToken"]
            },
            "endpoint": {
                "scope": {
                    "type": "BearerToken",
                    "token": "access-token-from-Amazon"
                },
                "endpointId": request["directive"]["endpoint"]["endpointId"]
            },
            "payload": {}
        }
    }
    return response
elif request_namespace == "Alexa.PercentageController":
    if request_name == "SetPercentage":
        value = request["directive"]["payload"]
        light = value
    elif request_name == "AdjustPercentage":
        value = request["directive"]["payload"]
        light = value

    logger.info('turning %s %s' % ('on' if light else 'off', device_id))
    response = client.update_thing_shadow(
        thingName=user_id,
        payload=json.dumps({
            "state": {
                "desired": {
                    "alexa":{
                    device_id: ['percent',light]
                    }
                }
            }
        })
    )
    logger.info('received {}'.format(response))

    response = {
        "context": {
        "properties": [ {
        "namespace": "Alexa.PercentageController",
        "name": "percentage",
        "value": value,
        "timeOfSample": get_utc_timestamp(),
        "uncertaintyInMilliseconds": 1000
            } ]
        },
        "event": {
        "header": {
        "namespace": "Alexa",
        "name": "Response",
        "payloadVersion": "3",
        "messageId": get_uuid(),
        "correlationToken": request["directive"]["header"]["correlationToken"]
        },
        "endpoint": {
        "scope": {
        "type": "BearerToken",
        "token": "access-token-from-Amazon"
                },
                "endpointId": request["directive"]["endpoint"]["endpointId"]
                },
            "payload": {}
        }
    }
    return response

elif request_namespace == "Alexa.PowerLevelController":
    if request_name == "SetPowerLevel":
        value = request["directive"]["payload"]["powerLevel"]
        light = value
    elif request_name == "AdjustPowerLevel":
        value = request["directive"]["payload"]["powerLevelDelta"]
        light = value

    logger.info('turning %s %s' % ('on' if light else 'off', device_id))
    response = client.update_thing_shadow(
        thingName=user_id,
        payload=json.dumps({
            "state": {
                "desired": {
                    "alexa":{
                    device_id: ['percent',light]
                    }
                }
            }
        })
    )
    logger.info('received {}'.format(response))

    response = {
        "context": {
        "properties": [ {
        "namespace": "Alexa.PowerLevelController",
        "name": "powerLevel",
        "value": value,
        "timeOfSample": get_utc_timestamp(),
        "uncertaintyInMilliseconds": 0
            } ]
        },
        "event": {
        "header": {
        "namespace": "Alexa",
        "name": "Response",
        "payloadVersion": "3",
        "messageId": get_uuid(),
        "correlationToken": request["directive"]["header"]["correlationToken"]
        },
        "endpoint": {
        "scope": {
        "type": "BearerToken",
        "token": "access-token-from-Amazon"
                },
                "endpointId": request["directive"]["endpoint"]["endpointId"]
                },
            "payload": {}
        }
    }
    return response

elif request_namespace == "Alexa.ColorController":
    if request_name == "SetColor":
        hue = request["directive"]["payload"]
        saturation = request["directive"]["payload"]
        brightness = request["directive"]["payload"]
        light = True
    logger.info('turning %s %s' % ('on' if light else 'off', device_id))
    response = client.update_thing_shadow(
        thingName=user_id,
        payload=json.dumps({
            "state": {
                "desired": {
                    "alexa":{
                    device_id: ['color',light]
                    }
                }
            }
        })
    )
    logger.info('received {}'.format(response))

    response = {
        "context": {
        "properties": [ {
        "namespace": "Alexa.ColorController",
        "name": "color",
        "value": {
            "hue": hue,
            "saturation": saturation,
            "brightness": brightness
        },
        "timeOfSample": get_utc_timestamp(),
        "uncertaintyInMilliseconds": 1000
            } ]
        },
        "event": {
        "header": {
        "namespace": "Alexa",
        "name": "Response",
        "payloadVersion": "3",
        "messageId": get_uuid(),
        "correlationToken": request["directive"]["header"]["correlationToken"]
        },
        "endpoint": {
        "scope": {
        "type": "BearerToken",
        "token": "access-token-from-Amazon"
                },
                "endpointId": request["directive"]["endpoint"]["endpointId"]
                },
            "payload": {}
        }
    }
    return response

elif request_namespace == "Alexa.ColorTemperatureController":
    if request_name == "DecreaseColorTemperature":
        value = "7000"
        light = value
    elif request_name == "IncreaseColorTemperature":
        value = "2000"
        light = value
    elif request_name == "SetColorTemperature":
        value = request["directive"]["payload"]["colorTemperatureInKelvin"]
        light = True

    logger.info('turning %s %s' % ('on' if light else 'off', device_id))
    response = client.update_thing_shadow(
        thingName=user_id,
        payload=json.dumps({
            "state": {
                "desired": {
                    "alexa":{
                    device_id: ['percent',light]
                    }
                }
            }
        })
    )
    logger.info('received {}'.format(response))

    response = {
        "context": {
        "properties": [ {
        "namespace": "Alexa.ColorTemperatureController",
        "name": "colorTemperatureInKelvin",
        "value": value,
        "timeOfSample": get_utc_timestamp(),
        "uncertaintyInMilliseconds": 500
            } ]
        },
        "event": {
        "header": {
        "namespace": "Alexa",
        "name": "Response",
        "payloadVersion": "3",
        "messageId": get_uuid(),
        "correlationToken": request["directive"]["header"]["correlationToken"]
        },
        "endpoint": {
        "scope": {
        "type": "BearerToken",
        "token": "access-token-from-Amazon"
                },
                "endpointId": request["directive"]["endpoint"]["endpointId"]
                },
            "payload": {}
        }
    }
    return response

elif request_namespace == "Alexa.BrightnessController":
    if request_name == "SetBrightness":
        value = request["directive"]["payload"]["brightness"]
        light = request["directive"]["payload"]
    elif request_name == "AdjustBrightness":
        value = request["directive"]["payload"]["brightnessDelta"]
        light = request["directive"]["payload"]
        #value = 25
    logger.info('turning %s %s' % ('on' if light else 'off', device_id))
    response = client.update_thing_shadow(
        thingName=user_id,
        payload=json.dumps({
            "state": {
                "desired": {
                    "alexa":{
                    device_id: ['brightness',light]
                    }
                }
            }
        })
    )
    logger.info('received {}'.format(response))

    response = {
        "context": {
        "properties": [ {
        "namespace": "Alexa.BrightnessController",
        "name": "brightness",
        "value": abs(value),
        "timeOfSample": get_utc_timestamp(),
        "uncertaintyInMilliseconds": 1000
            } ]
        },
        "event": {
        "header": {
        "namespace": "Alexa",
        "name": "Response",
        "payloadVersion": "3",
        "messageId": get_uuid(),
        "correlationToken": request["directive"]["header"]["correlationToken"]
        },
        "endpoint": {
        "scope": {
        "type": "BearerToken",
        "token": "access-token-from-Amazon"
                },
                "endpointId": request["directive"]["endpoint"]["endpointId"]
                },
            "payload": {}
        }
    }
    return response

elif request_namespace == "Alexa.ThermostatController":
    if request_name == "SetTargetTemperature":
        value = request["directive"]["payload"]["targetSetpoint"]
        name = "targetSetpoint"
        light = request["directive"]["payload"]
    elif request_name == "AdjustTargetTemperature":
        value = request["directive"]["payload"]["targetSetpointDelta"]
        name = "targetSetpoint"
        light = request["directive"]["payload"]
    elif request_name == "SetThermostatmode":
        value = request["directive"]["payload"]["thermostatMode"]["value"]
        name = "thermostatMode"
        light = request["directive"]["payload"]

    logger.info('turning %s %s' % ('on' if light else 'off', device_id))
    response = client.update_thing_shadow(
        thingName=user_id,
        payload=json.dumps({
            "state": {
                "desired": {
                    "alexa":{
                    device_id: ["thermostat",value]
                    }
                }
            }
        })
    )
    logger.info('received {}'.format(response))

    response = {
        "context": {
        "properties": [ {
        "namespace": "Alexa.ThermostatController",
        "name": name,
        "value": value,
        "timeOfSample": get_utc_timestamp(),
        "uncertaintyInMilliseconds": 500
            } ]
        },
        "event": {
        "header": {
        "namespace": "Alexa",
        "name": "Response",
        "payloadVersion": "3",
        "messageId": get_uuid(),
        "correlationToken": request["directive"]["header"]["correlationToken"]
        },
        "endpoint": {
                "endpointId": request["directive"]["endpoint"]["endpointId"]
                },
            "payload": {}
        }
    }
    return response

elif request_namespace == "Alexa.ChannelController":
    if request_name == "ChangeChannel":
        value = request["directive"]["payload"]
        light = value
    elif request_name == "SkipChannels":
        value = request["directive"]["payload"]
        light = value

    logger.info('turning %s %s' % ('on' if light else 'off', device_id))
    response = client.update_thing_shadow(
        thingName=user_id,
        payload=json.dumps({
            "state": {
                "desired": {
                    "alexa":{
                    device_id: ["channel",light]
                    }
                }
            }
        })
    )
    logger.info('received {}'.format(response))

    response = {
        "context": {
        "properties": [ {
        "namespace": "Alexa.ChannelController",
        "name": "channel",
        "value": value,
        "timeOfSample": get_utc_timestamp(),
        "uncertaintyInMilliseconds": 0
            } ]
        },
        "event": {
        "header": {
        "namespace": "Alexa",
        "name": "Response",
        "payloadVersion": "3",
        "messageId": get_uuid(),
        "correlationToken": request["directive"]["header"]["correlationToken"]
        },
        "endpoint": {
                "endpointId": request["directive"]["endpoint"]["endpointId"]
                },
            "payload": {}
        }
    }
    return response

elif request_namespace == "Alexa.Speaker":
    if request_name == "SetVolume":
        value = request["directive"]["payload"]
        light = value
    elif request_name == "AdjustVolume":
        value = request["directive"]["payload"]
        light = value
    elif request_name == "SetMute":
        value = request["directive"]["payload"]
        light = value

    logger.info('turning %s %s' % ('on' if light else 'off', device_id))
    response = client.update_thing_shadow(
        thingName=user_id,
        payload=json.dumps({
            "state": {
                "desired": {
                    "alexa":
                        {
                    device_id: ['speaker',light]
                    }
                }
            }
        })
    )
    logger.info('received {}'.format(response))

    response = {
        "context": {
        "properties": [ {
        "namespace": request_namespace,
        "name": request_name,
        "value": value,
        "timeOfSample": get_utc_timestamp(),
        "uncertaintyInMilliseconds": 0
            } ]
        },
        "event": {
        "header": {
        "namespace": "Alexa",
        "name": "Response",
        "payloadVersion": "3",
        "messageId": get_uuid(),
        "correlationToken": request["directive"]["header"]["correlationToken"]
        },
        "endpoint": {
                "endpointId": request["directive"]["endpoint"]["endpointId"]
                },
            "payload": {}
        }
    }
    return response

elif request_namespace == "Alexa.SceneController":
    if request_name == "Activate":
        name = "ActivatonStarted"
        light = "ON"
    elif request_name == "Deactivate":
        name = "DeactivationStarted"
        light = "OFF"

    logger.info('turning %s %s' % ('on' if light else 'off', device_id))
    response = client.update_thing_shadow(
        thingName=user_id,
        payload=json.dumps({
            "state": {
                "desired": {
                    "alexa":{
                    device_id: ['power',{"binary":light}]
                    }
                }
            }
        })
    )
    logger.info('received {}'.format(response))

    response = {
        "context" : { },
        "event": {
            "header": {
            "messageId": get_uuid(),
            "correlationToken": request["directive"]["header"]["correlationToken"],
            "namespace": "Alexa.SceneController",
            "name": "ActivationStarted",
            "payloadVersion": "3"
},
        "endpoint": {
            "scope": {
            "type": "BearerToken",
            "token": "access-token-from-Amazon"
        },
        "endpointId": request["directive"]["endpoint"]["endpointId"]
        },
         "payload": {
            "cause" : {
            "type" : "VOICE_INTERACTION"
        },
    "timestamp" : get_utc_timestamp()
}

} } return response

elif request_namespace == "Alexa.Authorization":
    if request_name == "AcceptGrant":
        response = {
            "event": {
                "header": {
                    "namespace": "Alexa.Authorization",
                    "name": "AcceptGrant.Response",
                    "payloadVersion": "3",
                    "messageId": "5f8a426e-01e4-4cc9-8b79-65f8bd0fd8a4"
                },
                "payload": {}
            }
        }
        return response

# other handlers omitted in this example

v3 utility functions

def get_endpoint_from_v2_appliance(appliance): endpoint = { "endpointId": appliance["applianceId"], "manufacturerName": appliance["manufacturerName"], "friendlyName": appliance["friendlyName"], "description": appliance["friendlyDescription"], "displayCategories": [], "cookie": appliance["additionalApplianceDetails"], "capabilities": [] } endpoint["displayCategories"] = get_display_categories_from_v2_appliance(appliance) endpoint["capabilities"] = get_capabilities_from_v2_appliance(appliance) return endpoint

def get_directive_version(request): try: return request["directive"]["header"]["payloadVersion"] except: try: return request["header"]["payloadVersion"] except: return "-1"

def get_endpoint_by_endpoint_id(endpoint_id): appliance = get_appliance_by_appliance_id(endpoint_id) if appliance: return get_endpoint_from_v2_appliance(appliance) return None

def get_display_categories_from_v2_appliance(appliance): model_name = appliance["modelName"] if model_name == "Smart Switch": displayCategories = ["SWITCH"] elif model_name == "Smart Light": displayCategories = ["LIGHT"] elif model_name == "Smart White Light": displayCategories = ["LIGHT"] elif model_name == "Smart Thermostat": displayCategories = ["THERMOSTAT"] elif model_name == "Smart Lock": displayCategories = ["SMARTLOCK"] elif model_name == "Smart Scene": displayCategories = ["SCENE_TRIGGER"] elif model_name == "Smart Activity": displayCategories = ["ACTIVITY_TRIGGER"] elif model_name == "Smart Camera": displayCategories = ["CAMERA"] else: displayCategories = ["OTHER"] return displayCategories

def get_capabilities_from_v2_appliance(appliance): model_name = appliance["modelName"] if model_name == 'Smart Switch': capabilities = [ { "type": "AlexaInterface", "interface": "Alexa.PowerController", "version": "3", "properties": { "supported": [ { "name": "powerState" } ], "proactivelyReported": True, "retrievable": True } } ] elif model_name == "Smart Light": capabilities = [ { "type": "AlexaInterface", "interface": "Alexa.PowerController", "version": "3", "properties": { "supported": [ { "name": "powerState" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.ColorController", "version": "3", "properties": { "supported": [ { "name": "color" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.ColorTemperatureController", "version": "3", "properties": { "supported": [ { "name": "colorTemperatureInKelvin" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.BrightnessController", "version": "3", "properties": { "supported": [ { "name": "brightness" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.PowerLevelController", "version": "3", "properties": { "supported": [ { "name": "powerLevel" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.PercentageController", "version": "3", "properties": { "supported": [ { "name": "percentage" } ], "proactivelyReported": True, "retrievable": True } } ] elif model_name == "Smart White Light": capabilities = [ { "type": "AlexaInterface", "interface": "Alexa.PowerController", "version": "3", "properties": { "supported": [ { "name": "powerState" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.ColorTemperatureController", "version": "3", "properties": { "supported": [ { "name": "colorTemperatureInKelvin" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.BrightnessController", "version": "3", "properties": { "supported": [ { "name": "brightness" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.PowerLevelController", "version": "3", "properties": { "supported": [ { "name": "powerLevel" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.PercentageController", "version": "3", "properties": { "supported": [ { "name": "percentage" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.ThermostatController", "version": "3", "properties": { "supported":[ { "name": "lowerSetpoint" }, { "name": "targetSetpoint" }, { "name": "upperSetpoint" }, { "name": "thermostatMode" } ], "proactivelyReported": True, "retrievable": True } }, { "type": "AlexaInterface", "interface": "Alexa.PercentageController", "version": "3", "properties": { "supported": [ { "name": "percentage" } ], "proactivelyReported": True, "retrievable": True } }, { "type":"AlexaInterface", "interface":"Alexa.TemperatureSensor", "version":"3", "properties":{ "supported":[ { "name":"temperature" } ], "proactivelyReported":False, "retrievable":True } }

    ]
elif model_name == "Smart Scene":
    capabilities = [
        {
            "type": "AlexaInterface",
            "interface": "Alexa.SceneController",
            "version": "3",
            "supportsDeactivation": False,
            "proactivelyReported": True
        }
    ]

elif model_name == "Smart Activity":
    capabilities = [
        {
            "type": "AlexaInterface",
            "interface": "Alexa.PowerController",
            "version": "3",
            "properties": {
                "supported": [
                    { "name": "powerState" }
                ],
                "proactivelyReported": True,
                "retrievable": True
            }
        },
        {
            "type": "AlexaInterface",
            "interface": "Alexa.Speaker",
            "version": "3",
            "properties": {
                "supported": [
                    { "name": "volume" },
                    { "name": "muted" }
                ],
                "proactivelyReported": True,
                "retrievable": True
            }
        },
        {
            "type": "AlexaInterface",
            "interface": "Alexa.ChannelController",
            "version": "3",
            "properties": {
                "supported": [
                    { "name": "channel" }
                ],
                "proactivelyReported": True,
                "retrievable": True
            }
        }
    ]

elif model_name == "Smart Thermostat":
    capabilities = [
        {
            "type": "AlexaInterface",
            "interface": "Alexa.PowerController",
            "version": "3",
            "properties": {
                "supported": [
                    { "name": "powerState" }
                ],
                "proactivelyReported": True,
                "retrievable": True
            }
        },
        {
            "type": "AlexaInterface",
            "interface": "Alexa.PercentageController",
            "version": "3",
            "properties": {
                "supported": [
                    { "name": "percentage" }
                ],
                "proactivelyReported": True,
                "retrievable": True
            }
        },
        {
            "type": "AlexaInterface",
            "interface": "Alexa.ThermostatController",
            "version": "3",
            "properties": {
                "supported":[
                    {
                        "name": "lowerSetpoint"
                    },
                    {
                        "name": "targetSetpoint"
                    },
                    {
                        "name": "upperSetpoint"
                    },
                    {
                        "name": "thermostatMode"
                    }
                ],
                "proactivelyReported": True,
                "retrievable": True
            }
        },
        {
             "type":"AlexaInterface",
             "interface":"Alexa.TemperatureSensor",
             "version":"3",
             "properties":{
                "supported":[
                   {
                      "name":"temperature"
                   }
                ],
                "proactivelyReported":False,
                "retrievable":True
             }
        }

    ]

else:
    # in this example, just return simple on/off capability
    capabilities = [
        {
            "type": "AlexaInterface",
            "interface": "Alexa.PowerController",
            "version": "3",
            "properties": {
                "supported": [
                    { "name": "powerState" }
                ],
                "proactivelyReported": True,
                "retrievable": True
            }
        },  
        {
            "type": "AlexaInterface",
            "interface": "Alexa.PercentageController",
            "version": "3",
            "properties": {
                "supported": [
                    { "name": "percentage" }
                ],
                "proactivelyReported": True,
                "retrievable": True
            }
        }

    ]

# additional capabilities that are required for each endpoint
endpoint_health_capability = {
    "type": "AlexaInterface",
    "interface": "Alexa.EndpointHealth",
    "version": "3",
    "properties": {
        "supported":[
            { "name":"connectivity" }
        ],
        "proactivelyReported": True,
        "retrievable": True
    }
}
alexa_interface_capability = {
    "type": "AlexaInterface",
    "interface": "Alexa",
    "version": "3"
}
capabilities.append(endpoint_health_capability)
capabilities.append(alexa_interface_capability)
return capabilities

`

this is discovery request test response i got

`Response: { "event": { "header": { "payloadVersion": "3", "namespace": "Alexa.Discovery", "name": "Discover.Response", "messageId": "684bad02-6f88-4915-9c50-9df11680903e" }, "payload": { "endpoints": [ { "endpointId": "b8:27:eb:35:95:cf-1", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.ColorController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "color" } ], "proactivelyReported": true } }, { "interface": "Alexa.ColorTemperatureController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "colorTemperatureInKelvin" } ], "proactivelyReported": true } }, { "interface": "Alexa.BrightnessController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "brightness" } ], "proactivelyReported": true } }, { "interface": "Alexa.PowerLevelController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerLevel" } ], "proactivelyReported": true } }, { "interface": "Alexa.PercentageController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "percentage" } ], "proactivelyReported": true } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Aura Office Room Cove Light", "displayCategories": [ "LIGHT" ], "description": "" }, { "endpointId": "b8:27:eb:35:95:cf-2", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Aura Office Room Hanging Light", "displayCategories": [ "SWITCH" ], "description": "" }, { "endpointId": "b8:27:eb:35:95:cf-3", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.PercentageController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "percentage" } ], "proactivelyReported": true } }, { "interface": "Alexa.ThermostatController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "lowerSetpoint" }, { "name": "targetSetpoint" }, { "name": "upperSetpoint" }, { "name": "thermostatMode" } ], "proactivelyReported": true } }, { "interface": "Alexa.TemperatureSensor", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "temperature" } ], "proactivelyReported": false } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Aura Office Room AC", "displayCategories": [ "THERMOSTAT" ], "description": "" }, { "endpointId": "b8:27:eb:35:95:cf-4", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.PercentageController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "percentage" } ], "proactivelyReported": true } }, { "interface": "Alexa.ThermostatController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "lowerSetpoint" }, { "name": "targetSetpoint" }, { "name": "upperSetpoint" }, { "name": "thermostatMode" } ], "proactivelyReported": true } }, { "interface": "Alexa.TemperatureSensor", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "temperature" } ], "proactivelyReported": false } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Aura Meeting Room AC", "displayCategories": [ "THERMOSTAT" ], "description": "" }, { "endpointId": "b8:27:eb:35:95:cf-5", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.Speaker", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "volume" }, { "name": "muted" } ], "proactivelyReported": true } }, { "interface": "Alexa.ChannelController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "channel" } ], "proactivelyReported": true } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Aura Meeting Room TV", "displayCategories": [ "ACTIVITY_TRIGGER" ], "description": "" }, { "endpointId": "b8:27:eb:35:95:cf-6", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.PercentageController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "percentage" } ], "proactivelyReported": true } }, { "interface": "Alexa.ThermostatController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "lowerSetpoint" }, { "name": "targetSetpoint" }, { "name": "upperSetpoint" }, { "name": "thermostatMode" } ], "proactivelyReported": true } }, { "interface": "Alexa.TemperatureSensor", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "temperature" } ], "proactivelyReported": false } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Aura Cellar AC", "displayCategories": [ "THERMOSTAT" ], "description": "" }, { "endpointId": "b8:27:eb:35:95:cf-Good Night", "capabilities": [ { "interface": "Alexa.SceneController", "supportsDeactivation": false, "version": "3", "type": "AlexaInterface", "proactivelyReported": true }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Aura Good Night", "displayCategories": [ "SCENE_TRIGGER" ], "description": "" }, { "endpointId": "b8:27:eb:35:95:cf-Good Morning", "capabilities": [ { "interface": "Alexa.SceneController", "supportsDeactivation": false, "version": "3", "type": "AlexaInterface", "proactivelyReported": true }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Aura Good Morning", "displayCategories": [ "SCENE_TRIGGER" ], "description": "" }, { "endpointId": "b8:27:eb:60:c0:9a-3", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.Speaker", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "volume" }, { "name": "muted" } ], "proactivelyReported": true } }, { "interface": "Alexa.ChannelController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "channel" } ], "proactivelyReported": true } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Aura Attic HomeTheatre", "displayCategories": [ "ACTIVITY_TRIGGER" ], "description": "" }, { "endpointId": "b8:27:eb:60:c0:9a-4", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.ColorController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "color" } ], "proactivelyReported": true } }, { "interface": "Alexa.ColorTemperatureController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "colorTemperatureInKelvin" } ], "proactivelyReported": true } }, { "interface": "Alexa.BrightnessController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "brightness" } ], "proactivelyReported": true } }, { "interface": "Alexa.PowerLevelController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerLevel" } ], "proactivelyReported": true } }, { "interface": "Alexa.PercentageController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "percentage" } ], "proactivelyReported": true } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Aura Attic Cove Light", "displayCategories": [ "LIGHT" ], "description": "" }, { "endpointId": "b8:27:eb:b4:f8:06-2", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.ColorController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "color" } ], "proactivelyReported": true } }, { "interface": "Alexa.ColorTemperatureController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "colorTemperatureInKelvin" } ], "proactivelyReported": true } }, { "interface": "Alexa.BrightnessController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "brightness" } ], "proactivelyReported": true } }, { "interface": "Alexa.PowerLevelController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerLevel" } ], "proactivelyReported": true } }, { "interface": "Alexa.PercentageController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "percentage" } ], "proactivelyReported": true } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Room1 Hall Temperature", "displayCategories": [ "LIGHT" ], "description": "" }, { "endpointId": "b8:27:eb:b4:f8:06-3", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.Speaker", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "volume" }, { "name": "muted" } ], "proactivelyReported": true } }, { "interface": "Alexa.ChannelController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "channel" } ], "proactivelyReported": true } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Room1 Dining HomeTheatre", "displayCategories": [ "ACTIVITY_TRIGGER" ], "description": "" }, { "endpointId": "b8:27:eb:b4:f8:06-4", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.ColorController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "color" } ], "proactivelyReported": true } }, { "interface": "Alexa.ColorTemperatureController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "colorTemperatureInKelvin" } ], "proactivelyReported": true } }, { "interface": "Alexa.BrightnessController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "brightness" } ], "proactivelyReported": true } }, { "interface": "Alexa.PowerLevelController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerLevel" } ], "proactivelyReported": true } }, { "interface": "Alexa.PercentageController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "percentage" } ], "proactivelyReported": true } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Room1 Dining Wall Light", "displayCategories": [ "LIGHT" ], "description": "" }, { "endpointId": "b8:27:eb:b4:f8:06-5", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Room1 Hall Kettel", "displayCategories": [ "SWITCH" ], "description": "" }, { "endpointId": "b8:27:eb:b4:f8:06-6", "capabilities": [ { "interface": "Alexa.PowerController", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "powerState" } ], "proactivelyReported": true } }, { "interface": "Alexa.EndpointHealth", "version": "3", "type": "AlexaInterface", "properties": { "retrievable": true, "supported": [ { "name": "connectivity" } ], "proactivelyReported": true } }, { "interface": "Alexa", "version": "3", "type": "AlexaInterface" } ], "cookie": {}, "manufacturerName": "Latigid Engineering pvt.ltd.", "friendlyName": "Room1 Hall Geyser", "displayCategories": [ "SWITCH" ], "description": "" } ] } } }

Request ID: "be61b8d7-480a-4690-a7d0-fb96a513dc6d"

Function Logs: { "interface": "Alexa.PowerController", "properties": { "proactivelyReported": true, "retrievable": true, "supported": [ { "name": "powerState" } ] }, "type": "AlexaInterface", "version": "3" }, { "interface": "Alexa.EndpointHealth", "properties": { "proactivelyReported": true, "retrievable": true, "supported": [ { "name": "connectivity" } ] }, "type": "AlexaInterface", "version": "3" }, { "interface": "Alexa", "type": "AlexaInterface", "version": "3" } ], "cookie": {}, "description": "", "displayCategories": [ "SWITCH" ], "endpointId": "b8:27:eb:b4:f8:06-5", "friendlyName": "Room1 Hall Kettel", "manufacturerName": "Latigid Engineering pvt.ltd." }, { "capabilities": [ { "interface": "Alexa.PowerController", "properties": { "proactivelyReported": true, "retrievable": true, "supported": [ { "name": "powerState" } ] }, "type": "AlexaInterface", "version": "3" }, { "interface": "Alexa.EndpointHealth", "properties": { "proactivelyReported": true, "retrievable": true, "supported": [ { "name": "connectivity" } ] }, "type": "AlexaInterface", "version": "3" }, { "interface": "Alexa", "type": "AlexaInterface", "version": "3" } ], "cookie": {}, "description": "", "displayCategories": [ "SWITCH" ], "endpointId": "b8:27:eb:b4:f8:06-6", "friendlyName": "Room1 Hall Geyser", "manufacturerName": "Latigid Engineering pvt.ltd." } ] } } } [INFO] 2019-04-23T20:32:08.167Z be61b8d7-480a-4690-a7d0-fb96a513dc6d Validate v3 response END RequestId: be61b8d7-480a-4690-a7d0-fb96a513dc6d REPORT RequestId: be61b8d7-480a-4690-a7d0-fb96a513dc6d Duration: 848.22 ms Billed Duration: 900 ms Memory Size: 128 MB Max Memory Used: 66 MB
`

it seems fine but i dont understand why it stopped discovering devices suddenly.

phantom-j commented 5 years ago

Add something to descrption field , don't leave it blank. They made that field mandatory.