Hello,
Since a couple of months I am trying to learn home assistant, node red, java script only to make any kind of automatization, unfortunately I haven’t understood many things yet and I would like to understand some based things that are continue to block every kind of automatization I am trying to achieve.
At the time being, at home I have all smart wall switches with tasmota firmware which act as switches for all the smart bulbs in my house. I am using mqtt commands to comunicate between the smart switches and the smart bulbs.
Mainly I am using node red to build flow automatizations. Here I need to understand how to better use the call service node and in deep the field with the json data.
Usually to understand an entity which service could be activated or which attributes could be changed,
I am using the developer tool (state and service) and I look into the generated yaml code. The other thing is to use an inject+current state node+debug node in nodered.
Taking information from both, I am trying to write functions and calling call service nodes. In the data field of the call service node I am trying to put the json string built on the previous taken information.
Here I have the big problems. The entity in question is the light entity.
Here below two generated objects from the light state.
{
"entity_id": "light.luci_camera",
"state": true,
"attributes": {
"min_color_temp_kelvin": 2000,
"max_color_temp_kelvin": 6535,
"min_mireds": 153,
"max_mireds": 500,
"supported_color_modes": [
"brightness",
"color_temp",
"hs"
],
"color_mode": "hs",
"brightness": 255,
"hs_color": [
48.134,
2.008
],
"rgb_color": [
255,
253,
249
],
"xy_color": [
0.328,
0.333
],
"entity_id": [
"light.luce_1cm",
"light.luce_2cm",
"light.luce_3cm"
],
{
"entity_id": "light.luci_camera",
"state": true,
"attributes": {
"min_color_temp_kelvin": 2000,
"max_color_temp_kelvin": 6535,
"min_mireds": 153,
"max_mireds": 500,
"supported_color_modes": [
"brightness",
"color_temp",
"hs"
],
"color_mode": "color_temp",
"brightness": 255,
"color_temp_kelvin": 6535,
"color_temp": 153,
"hs_color": [
54.768,
1.6
],
"rgb_color": [
255,
254,
250
],
"xy_color": [
0.326,
0.333
],
"entity_id": [
"light.luce_1cm",
"light.luce_2cm",
"light.luce_3cm"
],
Here the variable that I need to change using the call service function is color_mode from “hs” to “color_temp” and viceversa.
Before going ahead, I achieved to change the colours of the smart bulbs with the following json string put in data field :
{
"entity_id": "light.luci_camera",
"rgb_color": [255,254,250]
}
And I succeeded to do this only after looking at the developer mode :
service: light.turn_on
data:
rgb_color:
- 255
- 254
- 250
target:
entity_id: light.luci_camera
At the beginning I wrote as it shown in the debug window :
{
"entity_id": "light.luci_camera",
"attributes": {
"rgb_color": [255,254,250]
}
}
But it returned the error : “Call-service error. extra keys not allowed @ data[‘attributes’]”
So I deleted the “attributes” object from the json string.
Here I have a lot of questions, but mainly why? What is the right approach to understand for an entity which values can be modified and how to put them into the data field as json so it will work?
I lost every time a lot of time in order to find the right structure, is there exist a method which will help me to understand better, instead of doing many tries and lost hours until I achieve something?
Returning to my main question : how to change the color_mode as json string properly in the data field of the call service node so it will work? Or in other words how to switch from colour mode to while mode and viceversa?