sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
228 stars 122 forks source link

Fan speed for nodemcu #193

Closed harymk closed 3 years ago

harymk commented 3 years ago

How can i use fan speed using nodemcu

sivar2311 commented 3 years ago

Can you provide a bit more details? What do you want to know exactly ?

kakopappa commented 3 years ago

@harymk how do you control without Sinric Pro?

harymk commented 3 years ago

With sinric pro. Power on off using relay. I need to adjust fan speed

sivar2311 commented 3 years ago

A relay cannot supply different voltages or dim anything. Your question refers to your circuit - which is not known to us.

The SinricProFan provides you with the functions onRangeValue and onAdjustRangeValue. Implement these functions in your sketch. Within these functions you can control your circuit accordingly. See the example Fan. Remove the Serial.print statements in the callback functions and replace it with your necessary hardware functions (digitalWrite etc).

harymk commented 3 years ago

A want to dim ac voltage for fan

sivar2311 commented 3 years ago

For this you need an ac dimmer

harymk commented 3 years ago

Ok. Do u have example link or something to know about that

sivar2311 commented 3 years ago

Google "Arduino" + "ac dimmer"

jeromemoses commented 1 year ago

@sivar2311 how to control a fan speed within the esp32 loop and that should be updated in sinric pro.

delay(5000); // Wait 5 seconds device_state.fanSpeed = 2; // Set the fan speed to 2 onRangeValue(FAN_ID, device_state.fanSpeed); // Update the fan speed delay(5000); // Wait another 5 seconds device_state.fanSpeed = 3; // Set the fan speed to 3 onRangeValue(FAN_ID, device_state.fanSpeed);

i tried this i thought that will be updated in sinric pro dashboard but it doesn't, only it making changes in esp32 itself , can you please check this and give me a solution to control fan speed from esp32. I mean your example code is a sample of receiving and changing the fan speed right ? i need that to be send a speed value from esp32 to sinric pro.

sivar2311 commented 1 year ago

Hi @jeromemoses, here are a few tips for you:

  1. Don't use delay() this will block your code and the communication with the SinricPro server. If you need delay use the 'blink without delay' idom (see here)
  2. Don't call the callback functions by yourself! These are called by the SDK
  3. Implement your code to control your fan inside the callbacks and let them do the work for you
jeromemoses commented 1 year ago

@sivar2311 Thank you for replying for my problem, i have tried that too didn't work then i had a look on flip switch code in your repository and i come out with an idea theni tried:

void task1(void *pvParameters) { while (true) { // delay(5000); // Wait 5 seconds // device_state.fanSpeed = 2; // Set the fan speed to 2 // onRangeValue(FAN_ID, device_state.fanSpeed); // Update the fan speed // delay(5000); // Wait another 5 seconds // device_state.fanSpeed = 3; // Set the fan speed to 3 // onRangeValue(FAN_ID, device_state.fanSpeed);

Serial.println("teask1_running"); SinricProFanUS &myFan = SinricPro[FAN_ID]; device_state.fanSpeed = 2; onRangeValue(FAN_ID, device_state.fanSpeed); myFan.sendRangeValueEvent(FAN_ID, device_state.fanSpeed); delay(10000);

device_state.fanSpeed = 3; onRangeValue(FAN_ID, device_state.fanSpeed); myFan.sendRangeValueEvent(FAN_ID, device_state.fanSpeed); delay(10000);

vTaskDelay(pdMS_TO_TICKS(1000)); // Delay for 1 second } }

It works now, I just trying to automatically switch the speed of a fan according to the pollution around a such device, this is just test sample for that and its working ESP32 switching fan's speed by itself, but it didn't get updated or didn't see any success popups in sinric pro dashboard but in in alexa app it shows the changes of speed.

If I refresh the sinric pro dashboard pasge it shows the speed changes there also.

This function is in a separate loop in RTOS so that delay won't stop the SinricPro.handle() function which is inside "void loop()"

Anyways its working once again thank you for your concern. @sivar2311

sivar2311 commented 1 year ago

Usually, you do not need a stand-alone task.

Unfortunately, code snippets are not self-explanatory. If you post code snippets, please use code blocks. Otherwise the code is not very readable. You can find instructions on how to do this here.

Instead of code snippets, it would be very helpful if you first describe your project.

It would also be helpful if you create a Git repository and upload your complete project. That way I can get a complete overview and identify problems.

jeromemoses commented 1 year ago

Thank you for your help @sivar2311 , I have done that and its finally works, Also i am looking for a help to do one more project that I want to connect 2 separate ESP32 with single sinric pro switch device. I have tried and yes it works but when I turn the switch state it updates only in sinric pro dashboard not on another ESP. but if i turn switch state at sinric pro dashboard it gets updaded in both ESP.

I am using ESP32 wroom 32, dev module. IDE - PlatformIO.

My aim is to connect ESP8266(12E) with ESP32 through Sinric pro switch.

Please provide me the solution if this option is existed. Thanks you.

sivar2311 commented 1 year ago

Hi @jeromemoses

Your project will not be feasible with SinricPro alone. SinricPro is not designed for device-to-device communication.

The device-to-device communication would must be done additionally. Perhaps ESP-Now would be what you are looking for. Afaik it is compatible between ESP8266 and ESP32.