The dwarfs, being highly attuned to the ores and minerals that make up their underground worlds, discovered the (totally non-magical) power of magnetism quite early on. This soon lead to the discovery of electricity and electric power.
The electric power was used to propel trains along the underground railroads the dwarfs use for transporting rock and ore through their tunnels. Dwarfs are still fanatical puritans when it comes to the actual digging, like it is genetically code into them to dig by hand using only their pickaxes. This puritanism does not encompass methods for disposing of rubble. The easier it is to get rid of excess rock and ore, the more time remains for digging.
Hence the invention of carts to drag out the rubble in. This lead to railroads to easier push the carts out which lead to electrical motors to power the trains.
Apart from digging, the average dwarf also enjoys a bit of engineering or construction work in their spare time.
For now, let’s say that the dwarfs had the knowledge and use of electricity a few hundred years before the humans or the hobbits would have discovered it had they been left to do it themselves. The dwarfs were willing to share their knowledge, but neither the humans nor the hobbits were particularly interested in it for a long time.
The humans were generally more interested in precious stones and metals and the hobbits, always comfortable with their current way of life, weren’t really bothered.