Variables? (where is the structure defined?)

The following variables have been automatically generated for my first sketch:

bool entrance;
CloudDimmedLight island;
CloudColoredLight garage;

I assume that I can use "entrance" as a boolean. I'm a little less sure what "island" will return, eg, a byte (or int) with a value 0-100 or 0-255?

But "garage" eludes me. Is this going to come back as a Pantone code, a 3-digit RGB matrix, maybe a character string like "red-ish"? And what are the utterances in the Alexa skill that have been pre-set for this variable?

I'm sure there's a list somewhere that describes all the variables that are automatically defined for a Property?

Here's a hint. Code shared by Arduino_Ginuino shows the colored light "variable" is a bunch of stuff:

void onMoodLightChange() {
  uint8_t r, g, b;
  moodLight.getValue().getRGB(r, g, b);
  if (moodLight.getSwitch()) {
    Serial.println("R:"+String(r)+" G:"+String(g)+ " B:"+String(b));
  }
}

moodLight.getSwitch() is a boolean for on/off
moodLight.getValue().getRGB(r, g, b) populates three bytes with RGB values

I checked these two assumptions in my own code and it works.

Surprise! I asked Alexa to make "garage" turquoise and the Nano printed out:

Garage is on
R:34 G:122 B:114

So where is the magic list of all the defined color utterances?

For "red" I got R:122 G:0 B:0 and for "blue" I got R:0 G:0 B:122. Asking for "dim" or "bright" returned different RGB values and the utterance "I'm not sure what went wrong."

Dr_Quark:
I'm sure there's a list somewhere that describes all the variables that are automatically defined for a Property?

There's no documentation like this that I know of. The closest thing is the ArduinoCloudThing library's source code:

The CloudDimmedLight class is here:

The CloudColoredLight class is here:

From the properties selection window, I can list all the Smart Home properties. In the left column I make some broad assumptions about what their variable is, where everything that is on/off is probably a boolean:

?? Colored light
bool Contact Sensor
?? Dim Light
bool Light
bool Motion Sensor
bool Smart Plug
bool Switch
float Temp C
float Temp F
?? TV

Pert, from your CloudDimmedLight class link above, I see this code:

   float getBrightness() {
      return _value.bri;
    }
...
    bool getSwitch() {
      return _value.swi;
    }

so from the code I posted previously (moodLight.getSwitch()), can I assume that I can get the state of the dimmed light using the exact same code?

Also, can I get the float value of the dim setting with moodlight.getBrightness()? (it is beyond me why brightness would be a float. Wouldn't a nice byte of 0-100 do just fine?)

I'll do some code experiments and report back.

HooRah!!!! It works!

void onIslandChange() { // dimmed
    Serial.print("Island is on/off: ") ;
    Serial.println(island.getSwitch()) ;
    Serial.println(island.getBrightness(),2) ;

except the value printed out for brightness seems to be an integer, eg, it prints out "75" or "50" without the fractional decimal places.

Update: I removed the ",2" from the print statement and it printed "50.00", so brightness is definitely returned as a float. Converting the returned value to an int using (int) within the print statement, it prints "50"

Dr_Quark:
So where is the magic list of all the defined color utterances?

I suspect they are hidden away in the non-public code for the Arduino IoT Cloud service. I'm sure the cloud service is sending RGB or HSB values to your Arduino board, not color names.

Dr_Quark:
it is beyond me why brightness would be a float. Wouldn't a nice byte of 0-100 do just fine?

Probably 0-100 range is used because this makes sense to the user, who is used to thinking of percentages. But for an application where you want to do smooth fades (in the Arduino sketch), 100 steps is not great. Especially at the lower brightness levels, the LED brightness jumps up quickly, so you want as much resolution as possible.

Dr_Quark:
HooRah!!!! It works!

Nice work!

Dr_Quark:
except the value printed out for brightness seems to be an integer, eg, it prints out "75" or "50" without the fractional decimal places.

Update: I removed the ",2" from the print statement and it printed "50.00", so brightness is definitely returned as a float. Converting the returned value to an int using (int) within the print statement, it prints "50"

The brightness slider on the Arduino IoT Cloud dashboard works in steps of 1, but you still might want to have the greater resolution for controlling the brightness in your sketch code.

Pert wrote: ...for an application where you want to do smooth fades (in the Arduino sketch), 100 steps is not great. Especially at the lower brightness levels, the LED brightness jumps up quickly, so you want as much resolution as possible.

I'm not doing fades in my application. I'm running strings of 8-17 Watt 115v LEDs (regular house bulbs). All I want to be able to do is on/off and one setting of dim. I may get more sophisticated in the future, but right now each of these strings has a pre-set dim level.

To give you an idea of how difficult it is to dim these bulbs using phase-cutting, it turns out that the Arduino clock in a 60 Hz half cycle is limited to 130 ticks (that's because in order to prevent overflow you need to use the prescaler). My 8 levels of dim settings start at 65 ticks and go to 107. You can imagine how little power is left in the half-cycle if you don't trigger your TRIAC until 107 ticks. I have tried to devine the power supplies in these bulbs. Some are easily and smoothly dimmed, some aren't. i have a couple of LEDs in my stairwell that are set at a delay of 95 ticks and they still put out more than a nightlight, but they don't illuminate for about 4 seconds after power is applied. Think about what kind of power supply takes than long to charge up with that tiny little slice of the half-cycle.

So all I want to do is to be able to detect if Alexa is handing back to the Thing a bright or dim on/off. I may use the actual dim setting in later code.

Dr_Quark:
I'm not doing fades in my application. I'm running strings of 8-17 Watt 115v LEDs (regular house bulbs). All I want to be able to do is on/off and one setting of dim.

I was just explaining why Arduino might have decided on the float type. Others might have different applications which do benefit from the availability of more than 100 brightness levels.

Sounds like a nice project though!

Dr_Quark:
I have tried to devine the power supplies in these bulbs. Some are easily and smoothly dimmed, some aren't.

Maybe old news to you, but I thought this bigclive video about dimming the household LED bulbs was interesting:

Well, the issue still is not solved. There is still the question what the variables were, not only for the dimmed and colored light.

I'm still trying to implement this project: Arduino Nano IOT cloud Project
In this project various "tv.get_XXX" parameters are used, but what the property: type: "TV" is and what variables to use, that is not shared with public.

Also (as commented):

Ok, I found at least something in the GITHubArduino library. Under

Arduino-libraries/ArduinoCloudThing/src/types/automation/CloudTelevision.h

I think I also found a Bug in line 180 . I can't do tv.setVolume only tv.getVolume. And in the library on GITHUB there seems to be a mixup.
As I don't have an account for GITHub I'll just post it here, hope thats ok.

This is an excerpt from line 170 to 188

170
171 void setSwitch(bool const swi) {
172 _value.swi = swi;
173 updateLocalTimestamp();
174 }
175
176 bool getSwitch() {
177 return _value.swi;
178 }
179
180 void setSwitch(uint8_t const vol) { <<<<<<<<<<<< (should this not be: setVolume?)
181 _value.vol = vol;
182 updateLocalTimestamp();
183 }
184
185 uint8_t getVolume() {
186 return _value.vol;
187 }
188

janpho:
I'm still trying to implement this project: Arduino Nano IOT cloud Project

Just to help others, here's the working link:
https://create.arduino.cc/projecthub/313276/full-control-of-your-tv-using-alexa-and-arduino-iot-cloud-9e7c4d
You posted the HTML to embed the project, rather than just the link alone, and the forum doesn't support embedding.

janpho:
In this project various "tv.get_XXX" parameters are used, but what the property: type: "TV" is

The type of tv is on the thingProperties tab of the sketch:

CloudTelevision tv;

janpho:
and what variables to use, that is not shared with public.

I'm not sure what you mean by "what variables to use'. If you provide more details I'm sure I could help out with that though.

janpho:
Ok, I found at least something in the GITHubArduino library. Under

Arduino-libraries/ArduinoCloudThing/src/types/automation/CloudTelevision.h

Yes, that's exactly the place to look.

janpho:
I think I also found a Bug in line 180 . I can't do tv.setVolume only tv.getVolume. And in the library on GITHUB there seems to be a mixup.
As I don't have an account for GITHub I'll just post it here, hope thats ok.

Thanks so much for reporting that! I have submitted a pull request to fix it:

Thank you.

Do you also know why there is only:

PlaybackCommands getPlaybackCommand() {
return _value.pbc;
}

InputValue getInputValue() {
return _value.inp;
}

uint16_t getChannel() {
return _value.cha;

and not also:

.setPlaybackCommand
.setInputValue
.setChannel

Can you also explain where initial volume /channel/ Input ... is set?

And one more: On this "Dashboard" in the Arduino IOT Cloud, the TV has only one switch (Off / On) shouldn't it have all options? -> Volume, 0 to 100, Channel, input..

The file CloudTelevision.h has been changed, but the problem persists in the online editor :confused:

/tmp/855826823/AV_Control_jan14a/AV_Control_jan14a.ino:105:15: error: 'class CloudTelevision' has no member named 'setVolume'; did you mean 'getVolume'?

tv.setVolume(+=2);

^~~~~~~~~

(not sure if it can actually work like this (+=2)....

janpho:
The file CloudTelevision.h has been changed

...and the world is now a slightly better place. That was fast!

janpho:
The file CloudTelevision.h has been changed, but the problem persists in the online editor :confused:

This is expected. Arduino Web Editor only gets the updates of the libraries after there is a release. The developers of the libraries associate with Arduino IoT Cloud do make releases pretty frequently, so I don't expect it will be too long before there is another release, but I don't know how long.

Until then, if you want the updated library you can do this:

  • Download the library: https://github.com/arduino-libraries/ArduinoCloudThing/archive/master.zip
  • In the Arduino Web Editor, click on "Libraries" from the menu on the left side of the screen.
  • Click the upward pointing arrow button ("Import").
  • If you get a message about importing your sketchbook, click the "Import" button.
  • Select the downloaded ArduinoCloudThing-master.zip file.
  • Click the "Open" button.
  • Wait for the Arduino Web Editor to tell you the library was imported successfully.

janpho:
tv.setVolume(+=2);

^~~~~~~~~

(not sure if it can actually work like this (+=2)....

No. If you want to increment the current volume by 2, do this:

tv.setVolume(tv.getVolume() + 2);

I'll get back to you about your previous questions soon.

Thank you very much! You are really helpful! I think you should write a new tutorial :wink:

janpho:
Do you also know why there is only:

PlaybackCommands getPlaybackCommand() {
return _value.pbc;
}

InputValue getInputValue() {
return _value.inp;
}

uint16_t getChannel() {
return _value.cha;

and not also:

.setPlaybackCommand
.setInputValue
.setChannel

No. I can only guess that they just haven't gotten around to it yet. It looks like CloudTelevision is the most recently added class so it may be a work in progress.

The only way I know of to set these values is like this:

 Television televisionValues(tele.getSwitch(), tele.getVolume(), tele.getMute(), PlaybackCommands::Play, tele.getInputValue(), tele.getChannel());
  television=televisionValues;

or:

 Television televisionValues(tele.getSwitch(), tele.getVolume(), tele.getMute(), tele.getPlaybackCommand(), tele.getInputValue(), tele.getChannel());
  televisionValues.pbc=PlaybackCommands::Play;
  television=televisionValues;

In the above examples, the CloudTelevision object is named television and I'm setting the playback command to play. It's a bit awkward because you must set all the settings at once. In order to avoid changing the other settings, I must call their getter functions (e.g., getSwitch().

janpho:
Can you also explain where initial volume /channel/ Input ... is set?

When you create the TV property, it adds this to the thingProperties.h tab of you sketch:

CloudTelevision television;

where "television" is the TV property's variable name. This calls this version of the CloudTelevision class's constructor:

CloudTelevision() : _value(false, 0, false, PlaybackCommands::None, InputValue::TV, 0), _cloud_value(false, 0, false, PlaybackCommands::None, InputValue::TV, 0) {}

_value is the variable that stores the settings values. _value is a Television class object. Here is the Television class's constructor:

Television(bool const swi, int const vol, bool const mut, PlaybackCommands const pbc, InputValue const inp, int const cha): swi(swi), vol(vol), mut(mut), pbc(pbc), inp(inp), cha(cha) {
    }

So the line:

CloudTelevision television;

sets swi (the switch state) to false, vol (the volume) to 0, mut (mute) to false, pbc to PlaybackCommands::None, and so on. So those are the initial values. If you wanted to set different initial values, you could use the other version of the CloudTelevision constructor:

CloudTelevision(bool const swi, int const vol, bool const mut, PlaybackCommands const pbc, InputValue const inp, int const cha) : _value(swi, vol, mut, pbc, inp, cha), _cloud_value(swi, vol, mut, pbc, inp, cha) {}

and set your desired initial values like this:

CloudTelevision television(true, 42, false, PlaybackCommands::Stop, InputValue::AUX1, 8);

That will set switch state to true, volume to 42, mute to false, playback command to PlaybackCommands::Stop, etc.

There is some good general information on C++ classes here that may be helpful in understanding the ArduinoCloudThing library's source code:
http://www.cplusplus.com/doc/tutorial/classes

janpho:
And one more: On this "Dashboard" in the Arduino IOT Cloud, the TV has only one switch (Off / On) shouldn't it have all options? -> Volume, 0 to 100, Channel, input..

I would think so. Again, it might just be that this is work in progress and they haven't gotten around to it. You can implement this stuff yourself by using other properties. For example, volume could be set using a Custom Int property.

janpho:
Thank you very much! You are really helpful!

You're very welcome. I'm glad if I can be of assistance.

Hello,

well, problems go on.

As the television.h is not finished yet, I tried the other smart home types. The SmartPlug does not work at all. I'm not sure what the problem might be.

code: switch1.setSwitch(false);

error: 'class CloudSmartPlug' has no member named 'setSwitch'

switch1.setSwitch(false);

^~~~~~~~~