Change this code:
signal = valorForCircuit(circuit)
if temp == nil then
circuit = entity.get_circuit_network(defines.wire_type.green)
signal = valorForCircuit(circuit)
To this:
local signal = valorForCircuit(circuit)
if signal == nil then
circuit = entity.get_circuit_network(defines.wire_type.green)
signal = valorForCircuit(circuit)
Key differences: Use "local" and use the correct variable name!