Fan for zwift with alice

Hello. I want to apologize in advance for the clumsy solutions, code and workmanship. Firstly, I have very crooked hands, and secondly, I try to do it with minimal effort and from what is at hand - the main thing is that it works stably and performs the necessary functions.



Purpose: I train regularly on a bicycle, and in winter, trainings take place at home on a bicycle rack (by the way, I also have it homemade, and that's another story), almost everyone who trains like this uses a fan to blow.



I have this, a simple outdoor one with three speed buttons.







I found his scheme:





.

Since I have no experience with asynchronous motors and what will happen when two different windings are simultaneously turned on at the same time, I decided not to take risks and not allow this, so I connected the relay as follows:







One relay turns on the fan, the second switches speeds.



It turns out that I use two speeds, the first and third, and it remains possible to use the fan in manual mode at the second speed.



The relay block used the following:







The controller used the ESP8266: I was







flashing it in the Arduino IDE.



The simplest code:



#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define OUTPUT1  5
#define OUTPUT2  0


char auth[] = "           Blynk";

char ssid[] = "    ";
char pass[] = "    ";

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
digitalWrite(OUTPUT1, pinValue);
  // process received value
}
BLYNK_WRITE(V2)
{
  int pinValue = param.asInt();
  digitalWrite(OUTPUT2, pinValue);
}

void setup()
{

pinMode(OUTPUT1, OUTPUT);
pinMode(OUTPUT2, OUTPUT);
digitalWrite(OUTPUT1, HIGH );
digitalWrite(OUTPUT2, HIGH );

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:

}

void loop()
{
  Blynk.run();
}


The main thing is to get your code char auth [] = "Here is your authorization code that will be sent to your mail after registering on Blynk";

for control, you can use the links

blynk-cloud.com 'your code authorization' / update / V1? value = 1 to disable the first relay

blynk-cloud.com 'your code authorization' / update / V1? value = 0 to enable the first relay

similarly for the second

blynk- cloud.com 'your authorization code' / update / V2? value = 1 blynk-cloud.com 'your authorization code' / update / V2? value = 0



Initially, I used this device and several more at home for simple control of various devices via the Internet. Also, these links can be used with Alice through the skill "Brownie Kuzya" works correctly to enable and disable various devices.



It turns out, if you stop at this level, you can make a smart socket with an alice at a cost of 250 rubles for parts and it will have 2 channels and there will be a bunch of free conclusions on the MK.



We continue further. The fan runs, turns on, turns off, etc. but I wanted even more automation. Initially, I thought in the direction of receiving data directly into the microcontroller from the power sensor. I even started to study the ANT + protocol, but difficulties arose with the ANT + module, they seem to be on sale, but some are expensive, until I got my hands on the purchase and then I accidentally stumbled upon a zwift-client python application that can receive data from my account. To install $ pip install zwift-client I read a little about python and learned how to read my data, wrote a small script:



import time
import requests
from zwift import Client
username = '  '
password = ' '
player_id =    

client = Client(username, password)
world = client.get_world(1)
world.player_status(player_id)
i=1
change1=1
change2=1
powVKL=185

venrabota0='https://blynk-cloud.com//update/V1?value=1'
venspeed0='https://blynk-cloud.com//update/V1?value=0'
venrabota1='https://blynk-cloud.com//update/V2?value=0'
venspeed1='https://blynk-cloud.com//update/V2?value=1'
requests.get(venrabota0, verify=False)
requests.get(venspeed0, verify=False)
print(' ')   
while i<10:
    poweruser=world.player_status(player_id).power
    cadenceuser=world.player_status(player_id).cadence
    heartrateuser=world.player_status(player_id).heartrate
    speeduser=world.player_status(player_id).speed//1000000
    print(': '+str(poweruser))
    print(': '+str(cadenceuser))
    print(': '+str(heartrateuser))
    print(': '+str(speeduser))
    
    if change1==1 and speeduser>1: 
        requests.get(venrabota1, verify=False)
        change1=0
    if change1==0 and speeduser<1: 
        requests.get(venrabota0, verify=False)
        change1=1   
        
    if change2==1 and poweruser>powVKL: 
        requests.get(venspeed1, verify=False)
        change2=0
    if change2==0 and poweruser<=powVKL: 
        requests.get(venspeed0, verify=False)
        change2=1   
            
    time.sleep(1) # Delay for 1 minute (60 seconds)


It reads my data and when the movement starts, the fan turns on, and when the power is more than 185 W, an increased speed is turned on.



In principle, like everything. In fact, the solution is unfinished, there are still a bunch of ideas for its further development and for the game (changing the fan speed when it enters the draft) and the idea of โ€‹โ€‹displaying information about its parameters, power cadence speed on rotating blades, controlling this and other devices directly from the clock, etc. .d. there will never be an end.



All Articles