Hi,
what are the possibility to get electric network info from the API ? and to tweak them ?
There is the energy variable on the LuaEntity (mainly for accumulators?), and also the consumption_modifier.
But I did not find any other variables... Is there any ?
Is there a way to
- read the effective consumption of an entity ? for example, to check if an electric consumer is under-electrified (status of the green electric bar on the entity), i.e. consumes less than it could.
- read the global electric production and consumption of one network (the values that are displayed in the panel when you click a pole). And also the global accumulator remaining capacity ?
- change electric consumption of a device on the fly ?
Thanks for your help.
API and electricity ?
API and electricity ?
Last edited by binbinhfr on Mon Apr 18, 2016 9:23 am, edited 1 time in total.
My mods on the Factorio Mod Portal 

-
- Burner Inserter
- Posts: 11
- Joined: Mon Apr 11, 2016 12:10 pm
- Contact:
Re: API and electricity ?
I've been working with a similar set of questions. I'm trying to generate a "new pollution" and need to know how effectively my polluter entity is operating, but I can't find any API calls that will let me do that. Reading the electrical consumption of an entity was one proxy that I thought might work, but I think maybe this stuff just isn't in the API (yet). Another possibility was to check actual pollution emission (which surely must be proportional to the building's activity) compared to the prototype's max emission level, but I don't see a way to do even that.binbinhfr wrote:Hi,
what are the possibility to get electric network info from the API ? and to tweak them ?
There is the energy variable on the LuaEntity (mainly for accumulators?), and also the consumption_modifier.
But I did not find any other variables... Is there any ?
Is there a way to
- read the effective consumption of an entity ? for example, to check if an electric consumer is under-electrified (status of the green electric bar on the entity), i.e. consumes less than it could.
- read the global electric production and consumption of one network (the values that are displayed in the panel when you click a pole).
- change electric consumption of a device on the fly ?
Thanks for your help.
Do you know if there is a way to trigger an event when a given recipe or item is produced? My polluting buildings output sulfur (scrubbed from the air), so if I could keep track of their production it would be enough for me.
Re: API and electricity ?
I'm afraid that there is only "on_player_crafted_item", but this event is not triggered by a machine creating an item... If the devs are around here, we would really like some extensions of this nice APIQuantumtroll wrote:Do you know if there is a way to trigger an event when a given recipe or item is produced? My polluting buildings output sulfur (scrubbed from the air), so if I could keep track of their production it would be enough for me.

My mods on the Factorio Mod Portal 

Re: API and electricity ?
So no way to get electricity values ?... 

My mods on the Factorio Mod Portal 

-
- Filter Inserter
- Posts: 841
- Joined: Mon Sep 14, 2015 7:40 am
- Contact:
Re: API and electricity ?
The energy variable should work for any sort of electrically-powered entity. What I'm not sure of, however, is what the maximum value is for e.g. inserters that means "fully powered", as opposed to values less than that, which would mean not fully powered. Of course, testing for zero energy is the trivial case
.
You may need to test empirically, by using something like:

You may need to test empirically, by using something like:
Code: Select all
/c game.local_player.print(game.local_player.selected.energy)
Re: API and electricity ?
good idea, I tested it on several electric entity, but it seems to give logical values only for accumulators. For other devices, the values seem to have no correlation with the object electrical power.
But the fact is that an energy is not a power. And for example, on an assembly machine, you can read the max electric power consumed, and the green bar represents the effective consumed power. This is not an energy but an energy/s. So I doubt that the energy variable contains something useful in that case.
But the fact is that an energy is not a power. And for example, on an assembly machine, you can read the max electric power consumed, and the green bar represents the effective consumed power. This is not an energy but an energy/s. So I doubt that the energy variable contains something useful in that case.

My mods on the Factorio Mod Portal 

-
- Burner Inserter
- Posts: 11
- Joined: Mon Apr 11, 2016 12:10 pm
- Contact:
Re: API and electricity ?
No, energy is not useful for anything besides boilers and accumulators. And perhaps batteries and other equipment that have an energy pool, but definitely not energy consumption.
Re: API and electricity ?
So no clue on how to access these consumption data/variables ?Quantumtroll wrote:No, energy is not useful for anything besides boilers and accumulators. And perhaps batteries and other equipment that have an energy pool, but definitely not energy consumption.
My mods on the Factorio Mod Portal 

-
- Burner Inserter
- Posts: 11
- Joined: Mon Apr 11, 2016 12:10 pm
- Contact:
Re: API and electricity ?
No clue. If I had one, I could continue with my mod!binbinhfr wrote: So no clue on how to access these consumption data/variables ?
Re: API and electricity ?
I am actually very late with 5 years and I don't know when they did implement this.
But for all future visitors, now it works with entity.energy.
This returns the stored energy in joule. https://lua-api.factorio.com/latest/Lua ... ity.energy
you can use this, if you just implement the same buffer and the same usage, ore you have to do math.
But for all future visitors, now it works with entity.energy.
This returns the stored energy in joule. https://lua-api.factorio.com/latest/Lua ... ity.energy
you can use this, if you just implement the same buffer and the same usage, ore you have to do math.