Darsunt:
Gas valves are actually very simple to understand. Once you understand how they work, it'll almost seem embarrassing to have to explain how they work cuz they're so simple.
When you look at a gas valve, imagine two valves in series.
The gas port where the tube to the pilot light connects is between the two valves, so that gas can flow to the pilot light as long as the first valve, or "safety" valve is open. If the second valve, or "main" valve is open, it can also flow to the burner trays.
Both valves are operated by electromagnets. The electric power to hold the first valve open, and therefore allow gas flow to the pilot light comes from the thermocouple or thermopile immersed in the pilot light flame. The thermocouple or thermopile generates electricity from the heat of the pilot light flame.
So, if the pilot light flame goes out, then the voltage to hold the safety electromagnetic valve open is lost and the safety valve closes, thereby shutting off gas flow completely, including the gas flow to the pilot light.
The second electromagnetic valve in the gas valve, the "main" valve, allows gas flow through a much larger tube to the burner trays. This second electromagnetic valve gets power from either a 24 VAC transformer or the thermopile. Up until recently flue dampers were not required on water heaters so 120 VAC power wasn't needed to operate hot water heaters. As a result hot water heaters typcially used thermopiles to generate more electricity than a thermocouple could, and used that electricity to operate both electromagnetic valves in the water heater's gas valve.
A thermopile is nothing more than about 25 thermocouples all connected in series, so that a thermopile generates about 750 millivolts instead of the 30 millivolts that a thermocouple produces.
On a boiler or furnace, there will be 120 VAC power available to operate the circulating pump or blower, and so by using a 24 volt transformer this 120 volt power can be converted into the same 24 VAC power that the safety controls on a boiler or furnace operate on. By simply putting the second electromagnetic valve in series with all of the safety controls, the second electromagnetic valve will open and allow gas to flow to the burner trays as long as every safety control in that "control circuit" allows power to flow through it. If any safety control detects a problem, it interrupts the circuit to that second electromagnetic valve, thereby shutting off gas flow to the burner trays (but not the pilot light).
This is where I fly off on a tangent:
Typically, the thermostat in a house won't be connected directly to that 24 VAC control circuit to the main valve in the gas valve. That's because to heat up a house you also need the boiler's circulating pump or furnace blower to come on to deliver the heat to the house. I'm much more familiar with hot water heating systems, so I'll describe the typical arrangement for a boiler. Typically the thermostat will be connected to a double pole 24 volt relay, and when that relay gets energized, it completes two circuits; a 120 VAC circuit to the boiler circulating pump or furnace blower, and a 24 VAC circuit through to the temperature control (or "aquastat") on the boiler. When power flows through that aquastat circuit, it energizes a second relay that completes a 24 VAC circuit through all the safety controls to the "main valve" in the gas valve. So, as long as the thermostat is calling for heat, the aquastat is controlling the boiler temperature setting (from 160 to 190 deg. F) and turning on and shutting off the gas valve to maintain the boiler water temperature at that setting. If the first relay completed the circuit to the gas valve directly, then the boiler would keep firing until it kicked itself out on high limit. By having that first relay control a circuit through the aquastat that controls a second relay which operates the gas valve, then the aquastat controls the gas valve to, in turn, control the water temperature in the heating system. A boiler will typically have a "ladder diagram" which shows the start up sequence as sequence of "loops" (kinda like a ladder).
Newer boilers or furnaces will simply have a "controller" that the thermostat connects to that does all this and more.
Back to the chase...
So, to diagnose a gas valve, first check to see if the pilot light is on. If so, then the thermocouple or thermopile is generating enough voltage to keep the safety valve open. If the appliance is a hot water heater but it's not firing up, the thermopile might be weak. It may be producing enough power to open the safety valve, but not enough to open both the safety and main valves together. If replacing the thermopile doesn't work, then you need a new gas valve.
If the appliance is a boiler or furnace, it'll use 24 VAC to operate the "main" valve. Check to see if you're getting 24 VAC at the terminals on the gas valve. If so, and the boiler or furnace isn't firing up, then you need a new gas valve. If you don't have 24 VAC at the gas valve terminals, check for continuity across all the safety devices in the control circuit of the boiler or furnace as it's likely one of the safety devices is interrupting the circuit to the main valve.
The "button" you have to push on a gas valve when lighting the pilot light simply overrides the first electromagnetic valve to allow gas to flow to the pilot light. Once the thermocouple or thermopile is hot enough, the electricity it generates will be sufficient to hold that electromagnet open and you can release that "button". This can often take a few seconds.
Also, thermocouples gradually lose their ability to generate sufficient voltage to operate that safety electromagnet, and when they do, gas flow to the pilot light stops. So, a pilot light that won't stay lit is often the result of an old and weak thermocouple. Different thermocouples get replaced differently. Most of the time you can just pull down on them to pull them out of a spring clip that holds them in place. Other thermocouples will be held in with a thumb screw you loosen from below to pull the thermocouple out. Basically, if it doesn't have a thumb screw on the bottom, pull down on it.
Some gas appliances, like natural gas burning fireplaces will have a "dual" pilot light that has two pilot light flames; one for a thermocouple and the other that continuously heats a thermopile. The thermocouple will produce the voltage to hold the safety valve open in the gas valve, and the thermopile will produce the voltage that goes through the control circuit to the second electromagnetic valve. In this way, the fire place can be turned on, turned up, turned down and shut off with just the turn of a switch even without external electric power being supplied to it.
This is what a thermoCOUPLE looks like:
The copper "tube" is really a coaxial cable. The outside of the cable is copper and there's an insulated copper wire that runs inside it. When the end of the thermocouple is heated, a voltage is generated between the two copper conductors.
This is what a thermoPILE looks like:
The distinguishing characteristic of a thermopile is that it connects to the gas valve with two electric wires (each with a terminal crimped onto it) rather than with a single nut like the thermocouple does.
And, finally, since both a thermocouple and a thermopile simply create a voltage difference between two wires when their ends are heated, different lengths of thermocouples will all generate the same voltage, just as thermopiles of different length. So you can use a longer thermocouple to replace a shorter one, and use a longer thermopile to replace a shorter one. They're like extension cords or garden hoses or battery booster cables in that respect. That's important to know when you're water heater's pilot light goes out and the hardware store doesn't have a thermopile of the right length. (Just buy a longer one.)