Hi there,
i would like to have a ‘wanted temperature’ slider or knob.
I can’t seem to find any information about this subject.
I only see the default trigger options ‘if temp is below, then,…’
any suggestions here?
Kind regards.
Hi there,
i would like to have a ‘wanted temperature’ slider or knob.
I can’t seem to find any information about this subject.
I only see the default trigger options ‘if temp is below, then,…’
any suggestions here?
Kind regards.
So you want to be able to change the temp setting without going into the triggers and changing those right? You could use a analog slider with your values and then use a “if/else” statement in your code. Do you have any code together we could see? Thanks
hi vapor83,
you mean adding a an analog virtualwrite to a esp chip?
I was thingking to do try this on my sonoff TH10.
But how can i make it work on a RPI? this way i cant build a rpi zero in a hottub and still make changes on the go. with an ESP is still have to use serial to upload the code?
I don’t know a lot about coding, so i tried cayenne because it is ‘drag and drop’
Here is my code for the sonoff. (my comments are in dutch and i’m guessing de rest is very messy :p)
Kind Regards!
#include <CayenneMQTTESP8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTESP8266.h>
//define CAYENNE_DEBUG
//#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#define VIRTUAL_PIN_RELAY 12 //virtuele pin voor relais
#define DIGITAL_PIN 12 //gpio relais
#define DIGITAL_LED 13 //gpio blue led
#define VIRTUAL_PIN 14 //virtuele pin van sensor
// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin = 14;
OneWire oneWire(tmpPin);
DallasTemperature sensors(&oneWire);
unsigned long lastMillis = 0;
// WiFi network info.
char ssid = “—l”;
char wifiPassword = “—”;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “—”;
char password = “—”;
char clientID = “—”;
void setup() {
// put your setup code here, to run once:
pinMode(DIGITAL_PIN, OUTPUT);
pinMode(DIGITAL_LED, OUTPUT);
digitalWrite(DIGITAL_PIN, LOW);
digitalWrite(DIGITAL_LED, !LOW);
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
sensors.begin();
}
void loop() {
// put your main code here, to run repeatedly:
Cayenne.loop();
// WiFi.status() != WL_CONNECTED;
//{
//digitalWrite(DIGITAL_LED, !HIGH); // turn the LED on (HIGH is the voltage level)
//delay(500); // wait for a second
//digitalWrite(DIGITAL_LED, !LOW); // turn the LED off by making the voltage LOW
//delay(5000); // wait for a second
//}
Cayenne.loop();
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
lastMillis = millis();
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN);
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempCByIndex(0));
}
}
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“CAYENNE_IN_DEFAULT(%u) - %s, %s”, request.channel, getValue.getId(), getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
int i = getValue.asInt();
if (i == 0)
{
digitalWrite(DIGITAL_PIN, !HIGH);
}
else
{
digitalWrite(DIGITAL_PIN, !LOW);
}
}
here is a modified code that shows how to control a digital pin when the temp gets above or below the setting on the cayenne dashboard. It uses a analog slider on virtual pin 10. I hopefully this helps, let me know if you have questions.
#include <CayenneMQTTESP8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// define CAYENNE_DEBUG
// #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#define VIRTUAL_PIN_RELAY 12 // virtuele pin voor relais
#define DIGITAL_PIN 12 // gpio relais
#define DIGITAL_LED 13 // gpio blue led
#define VIRTUAL_PIN 14 // virtuele pin van sensor
// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin = 14;
float temp = 0.0; // temperature variable to hold sensor data
int heatSetting = 70; // default temp when it powers on
OneWire oneWire(tmpPin);
DallasTemperature sensors(&oneWire);
unsigned long lastMillis = 0;
// WiFi network info.
char ssid[] = “”;
char wifiPassword[] = “”;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “”;
char password[] = “”;
char clientID[] = “”;
void setup()
{
// put your setup code here, to run once:
pinMode(DIGITAL_PIN, OUTPUT);
pinMode(DIGITAL_LED, OUTPUT);
digitalWrite(DIGITAL_PIN, LOW);
digitalWrite(DIGITAL_LED, !LOW);
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
sensors.begin();
}
void loop()
{
// put your main code here, to run repeatedly:
Cayenne.loop();
// WiFi.status() != WL_CONNECTED;
// {
// digitalWrite(DIGITAL_LED, !HIGH); // turn the LED on (HIGH is the voltage level)
// delay(500); // wait for a second
// digitalWrite(DIGITAL_LED, !LOW); // turn the LED off by making the voltage LOW
// delay(5000); // wait for a second
// }
// Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 60000)
{
lastMillis = millis();
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN);
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
temp = sensors.getTempCByIndex(0);// sets a variable to hold the temp value
Cayenne.celsiusWrite(VIRTUAL_PIN, temp); // use the variable instead
if (heatSetting > temp) // evaluates the heat setting compared to the actual temp
{
digitalWrite(DIGITAL_PIN, HIGH);
}
else
{
digitalWrite(DIGITAL_PIN, LOW);
}
}
} // loop
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“CAYENNE_IN_DEFAULT(% u) - % s, % s”, request.channel, getValue.getId(), getValue.asString());
// Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
int i = getValue.asInt();
if (i == 0)
{
digitalWrite(DIGITAL_PIN, !HIGH);
}
else
{
digitalWrite(DIGITAL_PIN, !LOW);
}
}
CAYENNE_IN(10) //vrtual pin
{
heatSetting = getValue.asInt(); // must be whole numbers on dashboard
}