AI = find_dataref("sim/operation/prefs/ai_flies_aircraft")
AVpower = find_dataref("sim/cockpit2/switches/avionics_power_on")
APUgen = find_dataref("sim/cockpit2/electrical/APU_generator_on")
gen1 = find_dataref("sim/cockpit2/electrical/generator_on[0]")
gen2 = find_dataref("sim/cockpit2/electrical/generator_on[1]")

function avionics_power()
	if APUgen == 0 and gen1 == 0 and gen2 == 0 then
		AVpower = 0	
	end
	if AI == 1 then
		if APUgen == 1 or gen1 == 1 or gen2 == 1 then
			AVpower = 1
		end	
	end	
end


run_at_interval(avionics_power, 0.25)