I'm trying to get the AddOrUpdate request to work for my Alexa smart devices. Discovery works as intended, and I can confirm that the endpointId matches here. I first questioned my access token, but I can use the same access token to control my devices and it works, so I assume that the token is valid.
Here is an example request made for an AddOrUpdate that I am making.
{
"method":"POST",
"uri":"https://api.amazonalexa.com/v3/events",
"headers":{
"Content-Type":"application/json",
"Authorization":"Bearer my_token_here"
},
"json":{
"event":{
"header":{
"messageId":"my_message_id_here",
"namespace":"Alexa.Discovery",
"name":"AddOrUpdateReport",
"payloadVersion":"3"
},
"payload":{
"endpoints":[
{
"endpointId":"2897",
"description":"my_desc",
"friendlyName":"Dimmer",
"manufacturerName":"name_here",
"displayCategories":[
"LIGHT"
],
"capabilities":[
{
"type":"AlexaInterface",
"interface":"Alexa.PowerController",
"version":"3",
"properties":{
"supported":[
{
"name":"powerState"
}
],
"proactivelyReported":true,
"retrievable":true
}
},
{
"type":"AlexaInterface",
"interface":"Alexa.BrightnessController",
"version":"3",
"properties":{
"supported":[
{
"name":"brightness"
}
],
"proactivelyReported":true,
"retrievable":true
}
},
{
"type":"AlexaInterface",
"interface":"Alexa.EndpointHealth",
"version":"3",
"properties":{
"supported":[
{
"name":"connectivity"
}
],
"proactivelyReported":true,
"retrievable":true
}
}
],
"cookie":{
"modelName":"IotSwitch",
"isReachable":true
}
},
{
"endpointId":"832",
"description":"Activity Scene",
"friendlyName":"Open door",
"manufacturerName":"my_name",
"version":"Unknown",
"displayCategories":[
"ACTIVITY_TRIGGER"
],
"capabilities":[
{
"type":"AlexaInterface",
"interface":"Alexa.SceneController",
"version":"3",
"properties":{
"proactivelyReported":false,
"supportsDeactivation":false
}
}
],
"cookie":{
"modelName":"ResidentialActivity",
"isReachable":true
}
},
{
"endpointId":"833",
"description":"Activity Scene",
"friendlyName":"Close door",
"manufacturerName":"my_name",
"version":"Unknown",
"displayCategories":[
"ACTIVITY_TRIGGER"
],
"capabilities":[
{
"type":"AlexaInterface",
"interface":"Alexa.SceneController",
"version":"3",
"properties":{
"proactivelyReported":false,
"supportsDeactivation":false
}
}
],
"cookie":{
"modelName":"ResidentialActivity",
"isReachable":true
}
},
{
"endpointId":"834",
"description":"Activity Scene",
"friendlyName":"Movie time",
"manufacturerName":"my_name",
"version":"Unknown",
"displayCategories":[
"ACTIVITY_TRIGGER"
],
"capabilities":[
{
"type":"AlexaInterface",
"interface":"Alexa.SceneController",
"version":"3",
"properties":{
"proactivelyReported":false,
"supportsDeactivation":false
}
}
],
"cookie":{
"modelName":"ResidentialActivity",
"isReachable":true
}
}
],
"scope":{
"type":"BearerToken",
"token":"my_token_here"
}
}
}
}
}
Related
i have some trouble in control device from google assistant. I have synced 2 devices to google assistant, only have diffence in ids and names, just like this
{
"payload":{
"devices":[
{
"id":"FtxvyT43euwCPT4b7pVzam-d113a8cb2ccb4f6ba9e4831cb90a7695",
"type":"action.devices.types.AC_UNIT",
"traits":[
"action.devices.traits.OnOff",
"action.devices.traits.TemperatureSetting",
"action.devices.traits.FanSpeed",
"action.devices.traits.Modes"
],
"name":{
"defaultNames":[
"西蒙电气"
],
"name":"I7温控器中弘",
"nicknames":[
"i7-温控器-中弘"
]
},
"willReportState":false,
"attributes":{
"availableFanSpeeds":{
"speeds":[
{
"speed_name":"auto",
"speed_values":[
{
"speed_synonym":[
"auto",
"automatic"
],
"lang":"en"
}
]
},
{
"speed_name":"low",
"speed_values":[
{
"speed_synonym":[
"low",
"slow"
],
"lang":"en"
}
]
},
{
"speed_name":"medium",
"speed_values":[
{
"speed_synonym":[
"medium"
],
"lang":"en"
}
]
},
{
"speed_name":"high",
"speed_values":[
{
"speed_synonym":[
"high",
"fast"
],
"lang":"en"
}
]
}
],
"ordered":true
},
"availableModes":[
{
"name":"mode",
"name_values":[
{
"name_synonym":[
"mode"
],
"lang":"en"
}
],
"settings":[
{
"setting_name":"Sleep",
"setting_values":[
{
"setting_synonym":[
"sleep"
],
"lang":"en"
}
]
},
{
"setting_name":"Airsupply",
"setting_values":[
{
"setting_synonym":[
"airsupply",
"air supply"
],
"lang":"en"
}
]
}
],
"ordered":true
}
],
"availableThermostatModes":[
"heat",
"cool"
],
"thermostatTemperatureUnit":"C"
},
"deviceInfo":{
"manufacturer":"西蒙电气",
"model":"I7温控器中弘",
"hwVersion":"1.0",
"swVersion":"2.0"
},
"customData":{}
},
{
"id":"bYJDj2XYve3yLKPUnjNCp3-bbb06180c6c647738b3eb12e3d474e71",
"type":"action.devices.types.AC_UNIT",
"traits":[
"action.devices.traits.OnOff",
"action.devices.traits.TemperatureSetting",
"action.devices.traits.FanSpeed",
"action.devices.traits.Modes"
],
"name":{
"defaultNames":[
"西蒙电气"
],
"name":"I7中央空调",
"nicknames":[
"i7-中央空调"
]
},
"willReportState":false,
"attributes":{
"availableFanSpeeds":{
"speeds":[
{
"speed_name":"auto",
"speed_values":[
{
"speed_synonym":[
"auto",
"automatic"
],
"lang":"en"
}
]
},
{
"speed_name":"low",
"speed_values":[
{
"speed_synonym":[
"low",
"slow"
],
"lang":"en"
}
]
},
{
"speed_name":"medium",
"speed_values":[
{
"speed_synonym":[
"medium"
],
"lang":"en"
}
]
},
{
"speed_name":"high",
"speed_values":[
{
"speed_synonym":[
"high",
"fast"
],
"lang":"en"
}
]
}
],
"ordered":true
},
"availableModes":[
{
"name":"mode",
"name_values":[
{
"name_synonym":[
"mode"
],
"lang":"en"
}
],
"settings":[
{
"setting_name":"Sleep",
"setting_values":[
{
"setting_synonym":[
"sleep"
],
"lang":"en"
}
]
},
{
"setting_name":"Airsupply",
"setting_values":[
{
"setting_synonym":[
"airsupply",
"air supply"
],
"lang":"en"
}
]
}
],
"ordered":true
}
],
"availableThermostatModes":[
"heat",
"cool"
],
"thermostatTemperatureUnit":"C"
},
"deviceInfo":{
"manufacturer":"西蒙电气",
"model":"I7中央空调",
"hwVersion":"1.0",
"swVersion":"2.0"
},
"customData":{}
}
]
}
}
When i say something like set aircondition temperature to 22℃, 'i7-中央空调' returns a success, but 'i7-温控器-中弘' shows 'not support this mode'. So what cause it? And, what should i do?
You should have WillReportState = true since you do not have commandOnlyTemperatureSetting = true. You either need to specify the device cannot report state and is commandOnly or have the devices report state. Check out the TemperatureSetting trait attributes for more details.
If you're still having issues after that update, check yourlogs to identify the particular issue for that device.
I have a below JSON input coming from a source system:
{
"d":{
"results":[
{
"userId":"123",
"employmentType":"Full time",
"employment":{
"compansation":{
"results":[
{
"payments":{
"results":[
{
"payType":"Annual Salary",
"value":"70000"
},
{
"payType":"Annual Leave",
"value":"1000"
},
{
"payType":"Other Payments",
"value":"2000"
}
]
}
}
]
}
}
},
{
"userId":"456",
"employmentType":"Full time",
"employment":{
"compansation":{
"results":[
{
"payments":{
"results":[
{
"payType":"Annual Salary",
"value":"80000"
},
{
"payType":"Annual Leave",
"value":"2000"
},
{
"payType":"Other Payments",
"value":"3000"
}
]
}
}
]
}
}
},
{
"userId":"123",
"employmentType":"Full time",
"employment":{
"compansation":{
"results":[
{
"payments":{
"results":[
{
"payType":"Annual Salary",
"value":"90000"
},
{
"payType":"Annual Leave",
"value":"3000"
},
{
"payType":"Other Payments",
"value":"4000"
}
]
}
}
]
}
}
}
]
}
}
I want to filter "employment/compansation/payments" to use "payType" "Annual Salay" and "Annual Leave" only; and filter out "payType: Other Payments". Then sum both "Annual Salary" and "Annual Leave" and generate final output like:
[
{
"userId":"123",
"employmentType":"Full time",
"totalSalary":"71000"
},
{
"userId":"456",
"employmentType":"Full time",
"totalSalary":"82000"
},
{
"userId":"789",
"employmentType":"Full time",
"totalSalary":"93000"
}
]
Can I achieve this by only using native Logic App actions? Without using Functions or even JavaScript code? And how?
You can use the "Filter Array" connector in Logic App.
This might be a duplicate question, with similar question being answered here.
I am new in groovy and I want to construct a json object with the builder
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{ "match": { "content": "scontent" } },
{ "match": { "title":"stitle" } }
]
}
},
{
"bool": {
"should": [
{ "match": { "a1": "v1" } },
{ "match": { "a2":"v2" } },
... and so on ...
{ "match": { "an":"vn" } }
]
}
}
]
}
},
"highlight": {
"fields": {
"content":{}
}
}
}
I search a lot of on other posts on stackoverflow and I write this code
So I did this but no way to get what I want :
JsonBuilder builder = new JsonBuilder()
def body = builder {
from Lib.or(qQuery.start, 0)
size Lib.or(qQuery.num, 10)
query {
bool {
must [
{
bool {
should [
{ match { content 'scontent' } },
{ match { title 'stitle' } }
]
}
},
{
bool {
should myVals.collect {[
'match' : { it.key it.value }
]}
}
}
]
}
}
highlight {
fields {
content {}
}
}
}
Thanks for any help !
I think you can make this work with the JsonBuilder as is, but it is usually easier to create the data structure using maps and lists (which is what the builder outputs) in groovy as you have more control there.
Example code:
import groovy.json.*
def data = [
query: [
bool: [
must: [
[bool:
[should: [
[match: [ content: 'scontent']],
[match: [ title: 'stitle']]
]]
],
[bool:
[should: [
[match: [ a1: 'v1']],
[match: [ a2: 'v2']],
[match: [ vn: 'vn']]
]]
]
]
]
]
]
println JsonOutput.prettyPrint(JsonOutput.toJson(data))
produces:
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"content": "scontent"
}
},
{
"match": {
"title": "stitle"
}
}
]
}
},
{
"bool": {
"should": [
{
"match": {
"a1": "v1"
}
},
{
"match": {
"a2": "v2"
}
},
{
"match": {
"vn": "vn"
}
}
]
}
}
]
}
}
}
I did not include your full json as it takes up some space, but the structure is there. Note the use of lists ([valueA, valueB]) vs maps ([someKey: someValue]) in the data structure.
Granted this makes the JsonBuilder less than 100% useful but I haven't seen any concise ways of including lists of large json objects in a list within the structure. You can do:
def json = JsonBuilder()
json.query {
bool('list', 'of', 'values')
}
but for larger structures as list elements I would say go with the lists and maps approach.
//Existing Json that i have
[
{
"Id":1,
"Authors":[
{
"Id":10,
"Name":"Arun"
},
{
"Id":14,
"Name":"Arjun"
}
],
"tags":[
{
"Name":"Java"
}
]
},
{
"Id":5,
"Authors":[
{
"Id":7,
"Name":"Shyama"
}
],
"tags":[
{
"Name":"C#"
},
{
"Name":"C++"
}
]
}
]
//New Json (converted)
//Here i want to combine both the author
[
{
"Id":1,
"Authors":"Arun, Arjun",
"tags":"Java"
},
{
"Id":5,
"Authors":"Shyama",
"tags":"C#,C++"
}
]
//Controller that i have created
$scope.request = response.data;//request contain all json data
//---------- logic to create new json------------
}
var json = [
{
"Id":1,
"Authors":[
{
"Id":10,
"Name":"Arun"
},
{
"Id":14,
"Name":"Arjun"
}
],
"tags":[
{
"Name":"Java"
}
]
},
{
"Id":5,
"Authors":[
{
"Id":7,
"Name":"Shyama"
}
],
"tags":[
{
"Name":"C#"
},
{
"Name":"C++"
}
]
}
];
for (var i=0, j=json.length; i<j; i++) {
json[i].Authors = json[i].Authors.map(function(item) {return item.Name;}).join(',');
json[i].tags = json[i].tags.map(function(item) {return item.Name;}).join(',');
}
console.log(json);
i have the following json file. i am unable to get the data dynamically. please help me to solve this issue.
my requirement is i need to view the url value based on the submodule ie; sname || id. if i am accessing the sname as chapter1 i need to get all the vid -> url values that are present for that sub module.
[
{
"name":"Introduction - About The PMP Credential",
"sub1":[
{
"sname":"Introduction to PMP",
"id":"1",
"vid":[
{
"url":"www.abcd.co"
},
{
"url":"www.xyz.com"
},
{
"url":"www.xyz.com"
}
]
},
{
"sname":"Chapter1",
"id":"2",
"vid":[
{
"url":"www.abcd.co"
},
{
"url":"www.xyz.com"
}
]
},
{
"sname":"Justification",
"id":"3",
"vid":[
{
"url":"www.abcd.co"
},
{
"url":"www.xyz.com"
}
]
}
]
},
{
"name":"Project Management Framework",
"sub1":[
{
"sname":"Project Seminar",
"id":"4",
"vid":[
{
"url":"www.abcd.co"
},
{
"url":"www.xyz.com"
}
]
},
{
"sname":"Introduction to Communication Management",
"id":"5",
"vid":[
{
"url":"www.abcd.co"
},
{
"url":"www.xyz.com"
}
]
},
{
"sname":"Final Communication Management",
"id":"6",
"vid":[
{
"url":"www.abcd.co"
},
{
"url":"www.xyz.com"
}
]
},
{
"sname":"Modules",
"id":"7",
"vid":[
{
"url":"www.abcd.co"
},
{
"url":"www.xyz.com"
}
]
}
]
},
{
"name":"Cost Management",
"sub1":[
{
"sname":"Introduction to Cost Management",
"id":"8",
"vid":[
{
"url":"www.abcd.co"
},
{
"url":"www.xyz.com"
}
]
},
{
"sname":"Cost Management Introduction",
"id":"9",
"vid":[
{
"url":"www.abcd.co"
},
{
"url":"www.xyz.com"
}
]
}
]
}
]
<div ng-repeat="item_nm in test">{{item_nm.name}}
<div ng-repeat="sub1_dt in item_nm.sub1">
{{sub1_dt.sname}}
<div ng-repeat="vid in sub1_dt.vid">
{{vid.url}}
</div>
</div>
</div>
This will display name and corresponding sname and its url.