Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- switch 1:
- - platform: mqtt
- name: "1.Radiator IR"
- state_topic: "/Nicolina/switchConfirm10/"
- command_topic: "/Nicolina/switch10/"
- payload_on: "1"
- payload_off: "0"
- qos: 0
- retain: true
- switch:
- sensor:
- - platform: yr
- - platform: mqtt
- state_topic: 'ha/temperature1'
- name: 'Temp DHT22'
- unit_of_measurement: '°C'
- value_template: '{{ value_json.temperature }}'
- pt cod din attach ai nevoie de fisierele astea:
- #include <ESP8266WiFi.h>
- #include <PubSubClient.h>
- #include <DallasTemperature.h>
- #include <ArduinoJson.h>
- gasesti ultimele versiuni cautand pe google esp8266 si numele. apoi le descarci de pe github si le import in soft ul Arduino IDE inainte sa dai push la cod. pffff tu ai mai lucrat cu Arduino inainte deci stii.... eu nu stiam.
- ==============================================================================================
- ESP8266 Temp + MQ5 Sensor template.txt
- ===============================================================================================
- #include <ESP8266WiFi.h>
- #include <PubSubClient.h>
- //#include <OneWire.h>
- #include <DallasTemperature.h>
- #include <ArduinoJson.h>
- // Data wire is plugged into pin 2 on the Arduino
- #define ONE_WIRE_BUS 5
- // Setup a oneWire instance to communicate with any OneWire devices
- // (not just Maxim/Dallas temperature ICs)
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- // Update these with values suitable for your network.
- const char* ssid = "WIFI";
- const char* password = "WIFIpassword";
- const char* mqtt_server = "HA-Server-IP-address";
- const char* mqtt_client_id = "Client-ID-Unique-per-device";
- const char* mqtt_user = "Username (mine-is-homeassistant)";
- const char* mqtt_password = "password4HA";
- const char* mqtt_sensor_topic = "weather/station1";
- const char* mqtt_sensor_topic_gas = "weather/gas";
- WiFiClient espClient;
- PubSubClient client(espClient);
- long lastMsg = 0;
- float temp = 0;
- int inPin = 5; // DHT - D1/GPIO5
- void setup_wifi() {
- delay(10);
- // We start by connecting to a WiFi network
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- void reconnect() {
- // Loop until we're reconnected
- while (!client.connected()) {
- Serial.print("Attempting MQTT connection...");
- // Attempt to connect
- if (client.connect("mqtt_client_id, mqtt_user, mqtt_password")) {
- Serial.println("connected");
- } else {
- Serial.print("failed, rc=");
- Serial.print(client.state());
- Serial.println(" try again in 5 seconds");
- // Wait 5 seconds before retrying
- delay(5000);
- }
- }
- }
- void setup()
- {
- Serial.begin(115200);
- setup_wifi();
- client.setServer(mqtt_server, 1883);
- pinMode(inPin, INPUT);
- sensors.begin();
- }
- String sPayload;
- char* cPayload;
- String sPayload_gas;
- char* cPayload_gas;
- void loop()
- {
- if (!client.connected()) {
- reconnect();
- }
- client.loop();
- long now = millis();
- if (now - lastMsg > 6000) {
- lastMsg = now;
- sensors.setResolution(12);
- sensors.requestTemperatures(); // Send the command to get temperatures
- temp = sensors.getTempCByIndex(0);
- Serial.println("");
- if((temp > -20) && (temp <60))
- {
- StaticJsonBuffer<200> jsonBuffer;
- JsonObject& payload = jsonBuffer.createObject();
- payload["temperature"] = temp;
- sPayload = "";
- payload.printTo(sPayload);
- cPayload = &sPayload[0u];
- client.publish(mqtt_sensor_topic, cPayload, true);
- // Now we can publish stuff!
- Serial.print(F("\nPublishing "));
- Serial.print(cPayload);
- Serial.print("...");
- }
- }
- float sensor_volt;
- float sensorValue;
- sensorValue = analogRead(A0);
- sensor_volt = sensorValue/1024*5.0;
- StaticJsonBuffer<200> jsonBuffer;
- JsonObject& payload_gas = jsonBuffer.createObject();
- payload_gas["sensorValue"] = sensor_volt;
- sPayload_gas = "";
- payload_gas.printTo(sPayload);
- cPayload_gas = &sPayload_gas[0u];
- Serial.print("sensor_volt = ");
- Serial.print(sensor_volt);
- Serial.println("V");
- client.publish(mqtt_sensor_topic_gas, cPayload_gas, true);
- Serial.print(F("\nPublishing "));
- Serial.print(cPayload_gas);
- Serial.print("...");
- delay(1000);
- }
- =====================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement