Title itself is very clear. I wonder if there is any mechanical race created by either Valar or races of Middle Earth (probably by dwarfs). What is important to me here is that this race(s) must be either created as sentient beings or gained their sentiency over the course of time after its creation, not just servants.
There are no examples of purely mechanical creatures in Tolkien's writings. However, there are examples of constructed creatures1:
In a certain sense, the Dwarves themselves are a constructed race, as covered by In The Hobbit, what were the origins of the Dwarves?
The crucial difference between Dwarves (in their earliest days) and Elves and Men is that the Dwarves had no souls: they could only live so long as their maker (the Vala Aulë) concentrated on them:
Now Ilúvatar knew what was done, and in the very hour that Aulë's work was complete, and he was pleased, and began to instruct the Dwarves in the speech that he had devised for them, Ilúvatar spoke to him; and Aulë heard his voice and was silent. And the voice of Ilúvatar said to him: 'Why hast thou done this? Why dost thou attempt a thing which thou knowest is beyond thy power and thy authority? For thou hast from me as a gift thy own being only, and no more; and therefore the creatures of thy hand and mind can live only by that being, moving when thou thinkest to move them, and if thy thought be elsewhere, standing idle. Is that thy desire?'
The Silmarillion III Quenta Silmarillion Chapter 2: "Of Aulë and Yavanna"
However, Ilúvatar (God) gave the Dwarves souls of their own shortly after this.
Getting more at the heart of the question, an early draft of "The Fall of Gondolin" included creatures of metal and fire:
[O]n a time Melko assembled all his most cunning smiths and sorcerers, and of iron and flame they wrought a host of monsters such as have only at that time been seen and shall not again be till the Great End. Some were all of iron so cunningly linked that they might flow like slow rivers of metal or coil themselves around and above all obstacles before them, and these were filled in their innermost depths with the grimmest of the Orcs with scimitars and spears; others of bronze and copper were given hearts and spirits of blazing fire, and they blasted all that stood before them with the terror of their snorting or tramples whatso escaped the ardour of their breath; yet others were creatures of pure flame that writhed like ropes of molten metal, and they brought to ruin whatever fabric they came nigh, and iron and stone melted before them and became as water, and upon them rode the Balrogs in hundreds
History of Middle Earth II: The Book of Lost Tales Part 2 Chapter III: "The Fall of Gondolin"
It's not clear to what extent these creates can be considered "alive." Part of the point of Melkor (Melko in the above draft) is that he cannot create truly living creatures, only mockeries much like Aulë and the Dwarves, above. But for the sake of argument, let's suggest that they were alive. How could that be?
One obvious solution is Aulë's: they live so long as Melkor wills them to live. This seems like the most likely explanation, considering the line "and shall not again be until the Great End" (i.e. when Melkor breaks through the Door of Night and returns to Middle Earth). Then, to the extent that they can be considered "sentient", they only have sentience when Melkor wills them to live.
Another possibility is that they were inhabited by Maiar spirits, the same class of beings as Sauron and (some contend) the Balrogs. If so, they gained sentience at the moment of their creation, before Eä ever existed.
Finally, it's possible that they're inhabited by non-Maiar spirits. It's a common assertion that, because only Ilúvatar can create truly independent life, all sentient creatures that aren't Elves, Men, Dwarves, or Ents (or their genetic descendants, like the Hobbits) are just embodied Maiar. However, there's little evidence to support this; The Silmarillion suggests the existence of other spirits (emphasis mine):
These are the names of the Valar and the Valier, and here is told in brief their likenesses, such as the Eldar beheld them in Aman. [...] Though Manwë is their King and holds their allegiance under Eru, in majesty they are peers, surpassing beyond compare all others, whether of the Valar and the Maiar, or of any other order that Ilúvatar has sent into Eä.
The Silmarillion II Valaquenta
However, as with all things related to The Silmarillion, how closely this follows Tolkien's last thoughts is a matter of debate.
If this is true, however, then these creatures gained sentience immediately upon their creation.
Dragons were also constructed by Melkor, although exactly how is unclear. However, it is clear that they were an "original"2 thought of Melkor's, not something that in any form existed before:
FA 155: Morgoth perceived now that the Orcs unaided were no match for the Noldor, save in such numbers as he could not yet muster. Therefore he sought in his heart for new counsel, and he bethought him of dragons.
FA 260: Here Glaurung, the first of the Urulóki, the fire-drakes of the North, came forth from Angband's gate by night. He was yet young and scarce half-grown
History of Middle-Earth XI The War of the Jewels I "The Grey Annals" §115-116
There are no occurrences of creatures gaining sentience over time; sentience, and really life itself, is a gift from Ilúvatar and not something that can be earned or acquired. At one point in The Silmarillion, Melkor goes looking for the Flame Imperishable, which is the source of all Life (and souls), but he's unable to:
To Melkor among the Ainur had been given the greatest gifts of power and knowledge, and he had a share in all the gifts of his brethren. He had gone often alone into the void places seeking the Imperishable Flame; for desire grew hot within him to bring into Being things of his own, and it seemed to him that Ilúvatar took no thought for the Void, and he was impatient of its emptiness. Yet he found not the Fire, for it is with Ilúvatar.
The Silmarillion I Ainulindalë
1 For my purposes, I'm not including creatures that were created by breeding or corrupting existing creatures, meaning creatures like Orcs and Uruk-Hai. Those don't really fit with the spirit of the question.
2 In fairness, the extent to which any thought (especially of the Valar) is "original" is up for debate; in the words of Eru Ilúvatar (emphasis mine):
Then Ilúvatar spoke, and he said: 'Mighty are the Ainur, and mightiest among them is Melkor; but that he may know, and all the Ainur, that I am Ilúvatar, those things that ye have sung, I will show them forth, that ye may see what ye have done. And thou, Melkor, shalt see that no theme may be played that hath not its uttermost source in me, nor can any alter the music in my despite. For he that attempteth this shall prove but mine instrument in the devising of things more wonderful, which he himself hath not imagined.'
The Silmarillion I Ainulindalë
No there is not. In fact Tolkien hated the 'machine' as he called it. On the 30th January 1945 he wrote a letter to his son which contained:
Well the first War of the Machines seems to be drawing to its final inconclusive chapter – leaving, alas, everyone the poorer, many bereaved or maimed and millions dead, and only one thing triumphant: the Machines. As the servants of the Machines are becoming a privileged class, the Machines are going to be enormously more powerful. What's their next move? -Letter 96
We can also see throughout the Lord of The Rings that industrialisation is always portrayed as a very 'evil' thing, destroying the ecology of Middle-Earth, whether it be the destruction of Fangorn or the scouring of the Shire:
It was one of the saddest hours in their lives. The great chimney rose up before them; and as they drew near the old village across the Water, through rows of new mean houses along each side of the road, they saw the new mill in all its frowning and dirty ugliness: a great brick building straddling the stream, which it fouled with a steaming and stinking overflow. All along the Bywater Road every tree had been felled. As they crossed the bridge and looked up the Hill they gasped. Even Sam's vision in the Mirror had not prepared him for what they saw. The Old Grange on the west side had been knocked down, and its place taken by rows of tarred sheds. All the chestnuts were gone. The banks and hedgerows were broken. Great waggons were standing in disorder in a field beaten bare of grass. Bagshot Row was a yawning sand and gravel quarry. Bag End up. beyond could not be seen for a clutter of large huts. 'They've cut it down!' cried Sam. 'They've cut down the Party Tree!' -Return Of The King / Scouring of The Shire
In short there is not much to go on, but a documentary made a number of years ago with Christopher Tolkien echoing this. I shall try to find more information if I can.