This is a slightly more complicated question than it first appears! As far as natural electricity goes, lightning has long been an element of horror stories, being the essential force of nature in Frankenstein; or, The Modern Prometheus (1818), and lightning strikes being a characteristic event of many Gothic novels and even early 20th century stories such as H. P. Lovecraft's "The Picture in the House" (1921):
A moment later came the titanic thunderbolt of thunderbolts; blasting that accursed house of unutterable secrets and bringing the oblivion which alone saved my mind.
During the 19th century in particular there was a rising awareness of electricity as a natural force that could be harnessed with technology, and innovation in this line was sometimes grisly and horrific - while full reanimation was a pipe dream, galvanism was a hot topic, as scientists became aware that electricity could cause dead limbs to twitch - and increasingly became aware of electrical technology's capacity for other, more amazing things - telegraphy, telephony, motion pictures, electric lights, radio, television, x-rays...and as these advances took place they began to take their place in horror literature and media.
In the early 20th century, this was most evident in short stories like William Hope Hodgson's "The Gateway of the Monster" (1910) and Lord Dunsany's "The Electric King" (1930), where supernatural horror fiction collided with "gadget"-style scientifiction, and would-be occult detectives and ghostbreakers added far more than the traditional bell, book, and candle to their arsenals:
"Now, anyone, except you who know something of my methods of investigation, might consider all this a piece of useless and foolish superstition; but you all remember the Black Veil case, in which I believe my life was saved by a very similar form of protection, whilst Aster, who sneered at it, and would not come inside, died. I got the idea from the Sigsand MS., written, so far as I can make out, in the 14th century. At first, naturally, I imagined it was just an expression of the superstition of his time; and it was not until a year later that it occurred to me to test his 'Defense,' which I did, as I've just said, in that horrible Black Veil business. You know how that turned out. Later, I used it several times, and always I came through safe, until that Moving Fur case. It was only a partial 'defense' therefore, and I nearly died in the pentacle. After that I came across Professor Garder's 'Experiments with a Medium.' When they surrounded the Medium with a current, in vacuum, he lost his power—almost as if it cut him off from the Immaterial. That made me think a lot; and that is how I came to make the Electric Pentacle, which is a most marvelous 'Defense' against certain manifestations. I used the shape of the defensive star for this protection, because I have, personally, no doubt at all but that there is some extraordinary virtue in the old magic figure. Curious thing for a Twentieth Century man to admit, is it not? But, then, as you all know, I never did, and never will, allow myself to be blinded by the little cheap laughter. I ask questions, and keep my eyes open.
"In this last case I had little doubt that I had run up against a supernatural monster, and I meant to take every possible care; for the danger is abominable.
"I turned-to now to fit the Electric Pentacle, setting it so that each of its 'points' and 'vales' coincided exactly with the 'points' and 'vales' of the drawn pentagram upon the floor. Then I connected up the battery, and the next instant the pale blue glare from the intertwining vacuum tubes shone out.
"I glanced about me then, with something of a sigh of relief, and realized suddenly that the dusk was upon me, for the window was grey and unfriendly. Then 'round at the big, empty room, over the double barrier of electric and candle light. I had an abrupt, extraordinary sense of weirdness thrust upon me—in the air, you know; as it were, a sense of something inhuman impending.
This is the same basic idea that eventually led to Ghostbusters (1984). But the reference to mediums is deliberate: the late 19th/early 20th century coincided with the rise in Spiritualism as well as electricity, and the two sometimes came together in odd combinations. Spirit photography isn't strictly electrical--but electrical improvements in sound recording technology inspired people to try and record ghosts, and the "discovery" of voices in ambient background noise in the 1950s by Attila von Szalay and the Society of Psychical Research gave rise to the contemporary idea of "electronic voice phenomenon."
There are other odd ducks out there - but the whole crux of the Spiritualism experience was that the dead could in some way effect the physical world, either through a living medium or through some discernable phenomenon (such as rapping on tables or walls). This and the idea of poltergeist phenomenon became the basis of the idea that ghosts could conceivably affect electrical and electronic devices.
For the most part, though, there's not a strong early correlation between technology in the sense of supernatural phenomenon disrupting electricity. It does exist sometimes - you can see it in works where compasses "go crazy," with magnetism understood as closely-related to electricity - but it isn't a strong trope during the first half of the 20th century.
What you do get are theatrical devices and special effects. Dimming the lights suddenly to cause pitch darkness on stage was and is an effective mechanism to inspire sudden terror, made safer when dealing with electric lights as opposed to a gas lamp. It's hard to point out a "first" for this, and it wasn't restricted solely to ghosts: many locked-room mysteries involved sudden blackouts, isolated locations where the power fails, where telephone or telegraph lines are cut off, etc. (see, for example, Agatha Christie's Murder on the Orient Express (1934)). In a century that increasingly became connected by electrical devices, the failure of those devices helped to isolate the characters and increase the tension of the scenes, and this became much more prevalent in 1980s horror films like Poltergeist (1982), which helped to spread the idea.