Moisture sensor a pump and a sonoff th10

Hello,
I used a arduino nano to water my plants. Now i want to try this with a sonoff th10.
I need help to change the code and to comunicate withe HA over mqtt to see the
moisture level and start the pump if the soil is to dry.

thanks for you help!

Here ist the code I used for the nano:

int messwert=0;
int PUMPE=4;
void setup()
{
Serial.begin(9600);
pinMode (4,OUTPUT);
}
void loop()
{

//Hier beginnt der Hauptteil  

 messwert=analogRead(A0); //Die Spannung an dem Sensor wird ausgelesen und unter der Variable „messwert“ gespeichert.

  Serial.print("Test Europaletten:"); //Ausgabe am Serial-Monitor: Das Wort „Feuchtigkeits-Messwert:"

  Serial.println(messwert); //und im Anschluss der eigentliche Messwert.

  delay(1000); //Zum Schluss noch eine kleine Pause, damit nicht zu viele Zahlenwerte über den Serial-Monitor rauschen.;

if (messwert < 550 )

{
digitalWrite(PUMPE, HIGH);
}
else
{
digitalWrite(PUMPE, LOW);
}
}

You need to use the pubsub client to subscribe and publish MQTT messages.

There are plenty of examples on how to use it in the forum (and elsewhere on the net). This was one of my favourites

Thanks for your help. Is it possible to use my code and transmit the results over mqtt to HA?

Yes, you use the publish method from the pubsub library.

Hi, do you have any sample code for me, that I can use or modify?
Regards

Ingo

This is top of the list when searching for pubsubclient in the forum. You use the magnifying glass icon at the top right of the page.

Hi ,

I want to get the moisture level and start the pump if the soil is to dry using Nodemcu and a soil moisture) .Do you have a working code ready. And if possible send the sketch diagram showing the connections to all the components.
Thanks,
MJ