I want two input fields to be subtracted from each other and then stored in a global token.
this must be in a dan card.
I want two input fields to be subtracted from each other and then stored in a global token.
this must be in a dan card.
What have you tried? What isn’t working? What don’t you understand? Where is your code?
You have been posting variations of the same question for days now.
module.exports = async (options) => {
const { app, args } = options;
const w = Number(args.number_1);
const x = Number(args.number_2);
const y = (args.Answer);
const y = await this.homey.flow.createToken(`${y}`, {
type: "number",
title: `${y}`,
});
const z = (w + x);
const result = (z === y);
app.log(`The sum of ( ${w} + ${x} ) = ( ${z} = ${result} )`);
await myToken.setValue(result);
}
this is the basic version, this is to test and then work out further, but the basics don’t work yet.
You can’t declare a const twice (y
) to begin with. But your app.json
is invalid, hence the errors.
module.exports = async (options) => {
const { app, args } = options;
const w = Number(args.number_1);
const x = Number(args.number_2);
const y = (args.Answer);
const z = await this.homey.flow.createToken(`${y}`, {
type: "number",
title: `${y}`,
});
const z = (w + x);
const result = (z === y);
app.log(`The sum of ( ${w} + ${x} ) = ( ${z} = ${result} )`);
await z.setValue(result);
}
{
"id": "sum_of_two_numbers",
"title": {
"en": "sum of two numbers",
"nl": "som van twee getallen",
"de": "summe von zwei Zahlen",
"fr": "somme de deux nombres",
"it": "somma di due numeri",
"sv": "summa av tvĂĄ nummer",
"no": "sum av to tall",
"es": "suma de dos nĂşmeros",
"da": "sum af to tal"
},
"hint": {
"en": "Sum of two numbers is equal to ...",
"nl": "Som van twee getallen gelijk is aan ...",
"de": "Summe zweier Zahlen gleich ist ...",
"fr": "Somme de deux nombres est Ă©gale Ă ...",
"it": "Somma di due numeri è uguale a ...",
"sv": "Summa av två tal är lika med ...",
"no": "Sum av to tall er lik ...",
"es": "Suma de dos nĂşmeros es igual a ...",
"da": "Sum af to tal er lig med ..."
},
"titleFormatted": {
"en": "Operation [[number_1]] + [[number_2]] = [[Answer]] (sum)",
"nl": "Bewerking [[number_1]] + [[number_2]] = [[Answer]] (som)",
"de": "Operation [[number_1]] + [[number_2]] = [[Answer]] (summe)",
"fr": "L'opération [[number_1]] + [[number_2]] = [[Answer]] (somme)",
"it": "L'operazione [[number_1]] + [[number_2]] = [[Answer]] (somma)",
"sv": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (summa)",
"no": "Operasjonen [[number_1]] + [[number_2]] = [[Answer]] (sum)",
"es": "La operaciĂłn [[number_1]] + [[number_2]] = [[Answer]] (suma)",
"da": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (sum)"
},
"args": [
{
"name": "number_1",
"type": "number",
"placeholder": {
"en": "Number 1",
"nl": "Nummer 1",
"de": "Nummer 1",
"fr": "Numéro 1",
"it": "Numero 1",
"sv": "Nummer 1",
"no": "Nummer 1",
"es": "Numero 1",
"da": "Nummer 1"
},
"min": 0,
"max": 9999999999,
"step": 1e-7
},
{
"name": "number_2",
"type": "number",
"placeholder": {
"en": "Number 2",
"nl": "Nummer 2",
"de": "Nummer 2",
"fr": "Numéro 2",
"it": "Numero 2",
"sv": "Nummer 2",
"no": "Nummer 2",
"es": "Numero 2",
"da": "Nummer 2"
},
"min": 0,
"max": 9999999999,
"step": 1e-7
},
{
"type": "droptoken",
"name": "Answer"
}
]
}
{
"id": "sum_of_two_numbers",
"title": {
"en": "sum of two numbers",
"nl": "som van twee getallen",
"de": "summe von zwei Zahlen",
"fr": "somme de deux nombres",
"it": "somma di due numeri",
"sv": "summa av tvĂĄ nummer",
"no": "sum av to tall",
"es": "suma de dos nĂşmeros",
"da": "sum af to tal"
},
"hint": {
"en": "Sum of two numbers is equal to ...",
"nl": "Som van twee getallen gelijk is aan ...",
"de": "Summe zweier Zahlen gleich ist ...",
"fr": "Somme de deux nombres est Ă©gale Ă ...",
"it": "Somma di due numeri è uguale a ...",
"sv": "Summa av två tal är lika med ...",
"no": "Sum av to tall er lik ...",
"es": "Suma de dos nĂşmeros es igual a ...",
"da": "Sum af to tal er lig med ..."
},
"titleFormatted": {
"en": "Operation [[number_1]] + [[number_2]] = [[Answer]] (sum)",
"nl": "Bewerking [[number_1]] + [[number_2]] = [[Answer]] (som)",
"de": "Operation [[number_1]] + [[number_2]] = [[Answer]] (summe)",
"fr": "L'opération [[number_1]] + [[number_2]] = [[Answer]] (somme)",
"it": "L'operazione [[number_1]] + [[number_2]] = [[Answer]] (somma)",
"sv": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (summa)",
"no": "Operasjonen [[number_1]] + [[number_2]] = [[Answer]] (sum)",
"es": "La operaciĂłn [[number_1]] + [[number_2]] = [[Answer]] (suma)",
"da": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (sum)"
},
"args": [
{
"name": "number_1",
"type": "number",
"placeholder": {
"en": "Number 1",
"nl": "Nummer 1",
"de": "Nummer 1",
"fr": "Numéro 1",
"it": "Numero 1",
"sv": "Nummer 1",
"no": "Nummer 1",
"es": "Numero 1",
"da": "Nummer 1"
},
"min": 0,
"max": 9999999999,
"step": 1e-7
},
{
"name": "number_2",
"type": "number",
"placeholder": {
"en": "Number 2",
"nl": "Nummer 2",
"de": "Nummer 2",
"fr": "Numéro 2",
"it": "Numero 2",
"sv": "Nummer 2",
"no": "Nummer 2",
"es": "Numero 2",
"da": "Nummer 2"
},
"min": 0,
"max": 9999999999,
"step": 1e-7
},
{
"type": "droptoken",
"name": "Answer"
}
]
}
Please read the relevant documentation.
module.exports = async (options) => {
const { app, args } = options;
const w = Number(args.number_1);
const x = Number(args.number_2);
const y = (args.Answer);
const z = await this.homey.flow.createToken(`${y}`, {
type: "number",
title: `${y}`,
});
const z = (w + x);
const result = (Number(z) === Number(y));
app.log(`The sum of ( ${w} + ${x} ) = ( ${z} = ${result} )`);
await z.setValue(result);
}
{
"id": "sum_of_two_numbers",
"title": {
"en": "sum of two numbers",
"nl": "som van twee getallen",
"de": "summe von zwei Zahlen",
"fr": "somme de deux nombres",
"it": "somma di due numeri",
"sv": "summa av tvĂĄ nummer",
"no": "sum av to tall",
"es": "suma de dos nĂşmeros",
"da": "sum af to tal"
},
"hint": {
"en": "Sum of two numbers is equal to ...",
"nl": "Som van twee getallen gelijk is aan ...",
"de": "Summe zweier Zahlen gleich ist ...",
"fr": "Somme de deux nombres est Ă©gale Ă ...",
"it": "Somma di due numeri è uguale a ...",
"sv": "Summa av två tal är lika med ...",
"no": "Sum av to tall er lik ...",
"es": "Suma de dos nĂşmeros es igual a ...",
"da": "Sum af to tal er lig med ..."
},
"titleFormatted": {
"en": "Operation [[number_1]] + [[number_2]] = [[Answer]] (sum)",
"nl": "Bewerking [[number_1]] + [[number_2]] = [[Answer]] (som)",
"de": "Operation [[number_1]] + [[number_2]] = [[Answer]] (summe)",
"fr": "L'opération [[number_1]] + [[number_2]] = [[Answer]] (somme)",
"it": "L'operazione [[number_1]] + [[number_2]] = [[Answer]] (somma)",
"sv": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (summa)",
"no": "Operasjonen [[number_1]] + [[number_2]] = [[Answer]] (sum)",
"es": "La operaciĂłn [[number_1]] + [[number_2]] = [[Answer]] (suma)",
"da": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (sum)"
},
"tokens": [
{
"name": "Answer",
"type": "number",
"title": { "en": "Answer" },
"example": { "en": "5" }
}
],
"args": [
{
"name": "number_1",
"type": "number",
"placeholder": {
"en": "Number 1",
"nl": "Nummer 1",
"de": "Nummer 1",
"fr": "Numéro 1",
"it": "Numero 1",
"sv": "Nummer 1",
"no": "Nummer 1",
"es": "Numero 1",
"da": "Nummer 1"
},
"min": 0,
"max": 9999999999,
"step": 1e-7
},
{
"name": "number_2",
"type": "number",
"placeholder": {
"en": "Number 2",
"nl": "Nummer 2",
"de": "Nummer 2",
"fr": "Numéro 2",
"it": "Numero 2",
"sv": "Nummer 2",
"no": "Nummer 2",
"es": "Numero 2",
"da": "Nummer 2"
},
"min": 0,
"max": 9999999999,
"step": 1e-7
},
{
"type": "number",
"name": "Answer"
}
]
}
// register action ... runlisteners
actions.forEach(({ id }) => {
this.log('Adding runListener for action', id);
this.homey.flow.getActionCard(id)
.registerRunListener(async (args, state) => {
const action = require(`./flow/actions/${id}`);
const result = await action(timezone, tokens, args);
return Promise.resolve(result);
})
});
How should I solve that no new token is created but user can determine a token themselves.
See code above.
Have you fixed the error of defining the const z variable twice?
If you post sample code make sure it is free of such simple errors or we don’t know if that is simply the cause.
the problem is i want the user to be free to choose any variable(token) created in the homey flow interface and not a new one how do i do this ?
twice the same variable is not ok, I know that too, but how do you solve this problem?
Either give one of them a different name or define it with let instead of const.
I’m pretty sure you can’t, at least not using the SDK (perhaps with the Web API but doubt it). Tokens (also global tokens) are tied to a specific app, and only that app can change their value.