"Call-service API error. Error Message: expected float for dictionary value @ data['brightness']"

Hello guys,
i’m new and i’m starting deploy this project:
Raspberry pi4 whit:
Home Assistant Core
Rhasspy
MagicMirror when all it’s ok.
First i do the IntentHandling of Rhasspy whit HomeAssistant for call a simple automation, and it work all, but now i want more option…like wheater, radio, simple script for do somethings…
so i download nodered, i install the homeassistant node, i connect whit rhasspy (Remote HTTP http://192.168.1.167:1880/intent) and try some on/off light whit a tts back, and it work!!
But now when i try to set brightness_pct or color_name for change color or brightness i recive this error:
“Call-service API error. Error Message: expected float for dictionary value @ data[‘brightness_pct’]”
Configuration of nodered is :
Template Node:
{
“domain”: “light”,
“service”: “turn_on”,
“data”: {
“brightness_pct”: “{{slots.brightness}}”
}
}
(Mustache Template)
(Parsed JSON)

connect whit a simple call service node whit:
server: homeassistant
domain: light
service: turn_on
identity id : light.mylightbulb

i recive the correctly the intent slot brightness from rhasspy

What i’m doing wrong? :thinking:

Try without the “” around {{slots.brightness}}, that makes the value a text and a number (float to be exact) is expected there

Just try, i recive this error:
1/14/2021, 7:14:55 PMnode: SetBrightness msg : string[41]

“Unexpected token } in JSON at position 39”

After some quick testing:

This works in my test

{
“domain”: “light”,
“service”: “turn_on”,
“data”: {
“brightness_pct”: {{slots.brightness}}
}
}

I didn’t get any errors, but I didn’t have your automated input either. I just used an inject node to create a small sample data

{
“brightness”: 5.1
}

which I then moved from payload to slots with a change node. If you can post the exact message you get from rhasspy I can try with that.

You are sending the brightness as a string, not as a number.
Try this
“brightness_pct”: {{slots.brightness}}

i always recieve this error if i remove “”

1/14/2021, 8:39:40 PMnode: SetBrightnessmsg : string[40]

“Unexpected token “ in JSON at position 2”

Rhasspy i think work right…
[SetBrightness]
brightness at (0…100){brightness_pct}

In nodered i recieve the intent correctly:

1/14/2021, 8:39:39 PMnode: 71d92aa1.d5f414msg.payload : Object

object

intent: object

entities: array[1]

slots: object

brightness_pct: 10

…after i have a switch node for the command, when read [SetBrightness] pass it to a template node whit this inside:

{
“domain”: “light”,
“service”: “turn_on”,
“data”: {
“brightness_pct”: {{slots.brightness_pct}}
}
}

Propriety: msg.payload
Format: mustache template
Output as: Parse JSON

this node is connect to a call services node of the lightbulb…
but always if i remove the “” i recive error:
1/14/2021, 8:39:40 PMnode: SetBrightnessmsg : string[40]

“Unexpected token “ in JSON at position 2”

the mustache format is correct? Parsed JSON also right?

Check yor quotation marks. at position 2 is one and I had to replace them when I copied your template. Might be the wrong character there

Always the same…i’m sure it’s a stupid syntax error…i’m tired :triumph: :triumph:
But yes the quotes change when copyed on the web, i have to replace one by one
but now have this error:

1/14/2021, 9:58:03 PMnode: luminositàmsg : string[41]

“Unexpected token } in JSON at position 72”

I try also set some brightness value and it work, when i insert {{slots.brightness}} give me the error

I had the same error when there was no slots.brightness set. I need to see the input into that node to help you with that, pretty sure you are just trying to access a variable that is not there. Put a debug node after your input from rhasspy, set it to complete msg object and post it here.

You have pretty print double quotes, that is not json
Those should be a "

I will setup something similar to try and reproduce your error

Can you put an export of your flow here?
Because I do not see a reason why you should need the template node.

You can put your data in the data field of the call service node right?

From Rhasspy have this JSON send:
{
“intent”: {
“name”: “ImpostaLuminosita”,
“confidence”: 1
},
“entities”: [
{
“entity”: “brightness”,
“value”: 10,
“value_details”: {
“kind”: “Number”,
“value”: 10
},
“raw_value”: “dieci”,
“start”: 13,
“end”: 15,
“raw_start”: 13,
“raw_end”: 18
}
],
“slots”: {
“brightness”: 10
},
“text”: “luminosità a 10”,
“raw_text”: “luminosità a dieci”,
“tokens”: [
“luminosità”,
“a”,
“10”
],
“raw_tokens”: [
“luminosità”,
“a”,
“dieci”
],
“wakeword_id”: “alexa_raspberry-pi”,
“siteId”: “default”,
“sessionId”: “default-alexa_raspberry-pi-7f333036-c12a-4a91-bbf0-06dd66d94cd2”,
“customData”: null,
“wakewordId”: “alexa_raspberry-pi”,
“lang”: null
}

on nodered debug node i recive this:

I found your problem. Your whole json input is part of payload so you should be calling payload.slots.brightness.

Honestly I don’t know…
I tried to put value directly in the call service node, in the slot data, but it didn’t work, looking on the web I noticed that, the flows I found all have a template node in front of it, so I thought it was necessary to pass the values…

Here the link of my flow: (it’s orrible i know…i’m just try :smiley: )
https://drive.google.com/file/d/1h85GNT8i8nkZVqbdpiJS_7beLjlcdK4m/view?usp=sharing

IT WORK!!! I love you! :smiling_face_with_three_hearts:

Sinceyou are an expert on the subject,
do I always need a template node to pass the values to the call service node??
Or can I directly use the data slot of the call service node?

1 Like

I am in no way an expert at node red, I am barely able to do anything with it. I just found your problem because I tested around and ran into the same error when I used a variable that didn’t exist.

What I did play around with is the change node that can move values around and stuff, but in your case the template node seems easier.