Arduino Cloud IRremote.h virtual switch to send the ir signal NodeMcu v3

Hello! :slight_smile:

Could someone help me write the code so that when the switch is pressed (on), the IR diode sends a signal? (power will be cut off). This is my first ride with Arduino Cloud, and I'm also not good at programming xD

After turning the ESP power back on, I would like the switch to be reset to the OFF position to avoid a loop.
I know it would be easier to use the "push button" version, but
I want to use the on/off button because it looks more fancy :stuck_out_tongue_winking_eye:

now a quick description if you're still here :upside_down_face: :

I made a box for 18650 cells charged by a solar panel.

In winter I will have to charge the cells at home.
I came up with the idea that I could add ESP (nodemcu v3 CH340) to check the charge level from home. The whole project was good fun for me, so I also added an air humidity and temperature module. all code works as it should.

and now my problem, I'm completely stuck with sending an infrared signal that will turn off the switch. (I will turn everything on with the remote control through the window, but I like to compile everything so :stuck_out_tongue: )

I would like to use a diode to turn off the power from the phone.

...and I want to save energy. I came up with the idea that I could use an infrared switch.

Code:



  String message;
  float voltage;
  CloudTemperatureSensor temperature;
  int bat_percentage;
  CloudRelativeHumidity humidity;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include "DHT.h"
#define DHTTYPE DHT22     // DHT 22
#define DHTPIN D4 //DHT22 Pin D4(GPIO 2)
DHT dht(DHTPIN, DHTTYPE);

int analogInPin  = A0;    // Analog input pin
int sensorValue; 
float calibration = 0.36; // Check Battery voltage using multimeter & add/subtract the value
void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  dht.begin();
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 
  // Defined in thingProperties.h
  initProperties();
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}
void loop() {
  ArduinoCloud.update();
 
  float hm= dht.readHumidity();
  float temp=dht.readTemperature();
  
  sensorValue = analogRead(analogInPin);
  voltage = (((sensorValue * 3.3) / 1024) * 2 + calibration); //multiply by two as voltage divider network is 100K & 100K Resistor
 
  bat_percentage = mapfloat(voltage, 2.8, 4.2, 0, 100); //2.8V as Battery Cut off Voltage & 4.2V as Maximum Voltage
 
  if (bat_percentage >= 100)
  {
    bat_percentage = 100;
  }
  if (bat_percentage <= 0)
  {
    bat_percentage = 1;
  }
 
  Serial.print("Analog Value = ");
  Serial.print(sensorValue);
  Serial.print("t Output Voltage = ");
  Serial.print(voltage);
  Serial.print("t Battery Percentage = ");
  Serial.println(bat_percentage);
  Serial.print("Humidity ");
  Serial.println(hm);
  Serial.print("Temperature ");
  Serial.println(temp);

  delay(1000);
    humidity=hm;
    temperature=temp;
    msg="Temperature = " + String (temperature)+"  Humidity = " + String(humidity);
  
  
}
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

/*
  Since Temperature is READ_WRITE variable, onTemperatureChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onTemperatureChange()  {
  // Add your code here to act upon Temperature change
}

/*
  Since Humidity is READ_WRITE variable, onHumidityChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onHumidityChange()  {
  // Add your code here to act upon Humidity change
}

/*
  Since Message is READ_WRITE variable, onMessageChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onMsgChange()  {
  // Add your code here to act upon Msg change
}

void dht_sensor_getdata()
  {
    float hm= dht.readHumidity();
    Serial.print("Humidity ");
    Serial.println(hm);
    float temp=dht.readTemperature();
      Serial.print("Temperature ");
    Serial.println(temp);
    humidity=hm;
    temperature=temp;
    msg="Temperature = " + String (temperature)+"  Humidity = " + String(humidity);
  }

let's say my signal will be
IrSender.send0nkyo(0x91C0, 0x9E10, 1);

Pin: D2

Please, can anyone help me? I watched a lot of videos on YouTube and either it's on a different website than Arduno Cloud or using a physical button