(Answering in more detail, as this is the top search hit for "ESP8266 Vin", at least for me)
TL;DR: Vin is NOT directly connected to USB power. There is a protection diode between USB+/VU and Vin, which has a limited current capacity.
If your board provides VU, that one is directly connected to USB power.
As long as you only power 1-2 tiny devices, it ...
As far as I can see, the relay will stay on when val is less or equal than 500, and stay off when val is higher than 500.
However, there might be a problem when val keeps fastly moving around 500; it will switch on and off quite fast.
To prevent this, you should make two 'triggers', e.g. turn it on when the value <= 480, and turn it off when the value >=...