(Deutsch) Lost Places: Glaswerk Ilmenau, Teil 2, Neubau

Sorry, this entry is only available in Deutsch.

Posted in Foto | Leave a comment

Lost places: Glaswerk Ilmenau, Teil 1: Übersicht

Lost places ist eine Kategorie in der Fotografie, bei der “vom Menschen verlassene Orte” fotografisch in Szene gesetzt werden. Dabei wird dokumentiert, was ist. Es wird nichts verändert oder arrangiert.

Posted in Foto | 2 Comments

WiFi power plug with temperature sensor

In the first part I’ve shown how a WiFi-power plug from Amazon can be easiely equipped with an own firmware to connect it via MQTT to the own home automation server. The manufacturer cloud is no longer needed in this case. A nice feature of the described model is a free extension pin of the integrated controller which can be used for own extensions. I want to use it to add a temperature sensor.

The WiFi power plug I’ve bought under the trade mark “Arrinew”. In the meantime it is no longer available but the same model is shown under various other names: Expower, Horsky, Elegiant, Allomn, Mopoin… Sure, other will follow. There are chinese companies which rent cloud services for such gear, and in principle, every dealer can order hundertthousands of these play tools under an own brand. This business model makes me some headache. If the dealer won’t (or cannot) continue it’s business the cloud is closed and the WiFi powerplug is useless. Of course, this don’t bother us because we use our onw firmware without beeing forced to any cloud.

DS18B20 IC

But back to the main topic: We use a Dallas DS18B20 digital temperature sensor which is available as TO-92 (housing with wires) or as encapsulated wired sensor. The chip measures the temperature and provides it as a digital word on a so called on-wire bus signal. The one-wire bus protocol allows acessing more sensors with only one signal wire. That’s perfect for our application.

Versions of the DS18B20 temperature sensor, plain IC vs. encapsulated wired version

The sensor needs beside the data lione also a supply voltate (3..5V) and ground. The following picture shows how it can be wired in the WiFi-powerplug.

Because I have connected the sensor to the 5V supply (because the 3.3V seems to be less powerfull in this case) I added also a protection resistor (about 470 ohms, not so critical) in the data wire.

Wiring of the temperture sensor, red=+5V, yellow=data, white/green=ground

Measuring the air temperature is a somewhat more complicated thing as it first assumes. The temperature in a room is different in different places and not so stable (height over ground, distance to materials with different temperature, air movements…). So, it makes no sense to try to be very precise. OK, 1K accuracy is not too much. And for a possible precise measurement the external version of the sensor is a must because it can be placed free in the room on an interesting place. For me, it was too much effort, I want a possible simple temperature measurement. so I decided to place the chip sensor on top of the plug housing.

Wrong position of the sensor, the housing becomes too warm there

This is a bad trap to step into, the place I selected first becomes relatively warm, too warm to make a sensefull measurement. The sensor shows constant over 30°. I moved it than from the button area to a possibly cold area beside the plug. There it works well, compared with other sensors in the same room.

possible placement for the sensor

Who needs it? First, it’s always a good feature in the home automation to know a room temperature. Especially usefull is such a measurement, if the plug is used to control any form of a room heater.

Posted in home automation | Tagged , | Leave a comment

Arrinew / SWA1 WiFi power switch

With home automation more early than later this cheap WiFi power switches come into the game. I use (and build up continuously) a home automation system based on Home assistant (hass) and was looking for a possibility to switch on and off two lamps for plants (yes, also for my Chili plantage 😉 ).

This Wifi switches usually connect to their producers cloud service. All commands go first from the house over the internet to the server and than back over the internet to the switch. This is an easy to establish but very ugly thing. First, nobody else has any right to know, what in my house is controled and second, if the Internet connection or the producers server is down, the system doesn’t work. And beleave me, this is more often the case as someone may assume.

But fortunately nearly all WiFi power switches use the same chip and they can usually programed with an own or alternative firmware so they never have to see their cloud service in their whole life. So, my own home automation system takes over the role of the producers cloud.

At the German Amazon site I found a cheap pair of such WiFi power switches which are sold unter the label “Arrinew”. I think, their may be sold also under various other labels. Therefore, more unique is the model “SWA1” and the label on the internal PCB board 101-SWA1351-361

This power switches have realy a good mechanical quality. Also the electronics inside looks very significant. Unbeleaveable what they sell for under 10,-€/piece.

Who want’s to read further should know what an ESP8266 is and also MQTT should be a known concept.

The objective of this article is to replace the firmware of the power switch with an own program to integrate it into my own hosted home automation system. There are principially two ways: Use of one of the free operating systems for ESP-family (Takoma, EasyESP) or write an own software with the Arduino libraries and environment. Because I want learn a little bit, I like transparency and doesn’t like to struggle with various problems of the ESP-operating systems and finaly because I found a good example for such a firmware, I choose the second way and set up an own firmware.

The Arrinew power switches are prepared to be programmed in such a way that the required contacts are internally available. But they are not proper labeled and the ESP-chip is covered by a metal plate, so that the contacts cannot be followed visually or a continuitiy check. Luckily by googling the PCB board label I found this page where somebody has done great work by hacking these information.

An interesting detail is further that there is also an unused GPIO-pin available. Because there are never enough temperature sensors spreaded in the house this pin asks for beeing used to connect a digital one wire temperatur sensor. But this is a topic for another post.

As mentioned, the program for the power switch I have also stolen from Matt and have it a little bit modified. Now, it looks so:


// Flash mode: DOUT
// Flash Frequency: 40MHz
// Flash Size: 1MB (512kB SPIFFS)
// Reset method: None
// Crystal Frequency: 26MHz
// CPU frequency: 160MHz
// Upload speed: 921600

// Button: GPIO13
// Blue LED: GPIO4
// Red LED + Relay: GPIO5
// Extra Pin: GPIO14, used foor one-wire temperaure sensor

#include <ESP8266WiFiMulti.h>
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <DebouncedInput.h>
#include <OneWire.h>
#include <DallasTemperature.h>


ESP8266WiFiMulti wifiMulti;
WiFiClient espClient;
PubSubClient client(espClient);

#define ONE_WIRE_BUS 14  // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);


bool powerState = false;
unsigned long previousMillis=0;

#define NAME "name for OTA"
#define OTAPW "password for OTA updates"
#define BROKERUSER "MQTT broker user"
#define BROKERPASS "MQTT broker password"

// define here your MQTT topics
#define SUBTOPIC "/powerplugs/switch02/command"
#define PUBTOPIC "/powerplugs/switch02/status"
#define TEMPTOPIC "/powerplugs/switch02/temp"

#define POWERPIN 5
#define BUTTONPIN 13
#define LEDPIN 4
#define TEMP_INTERVALL 10000  // temperature is measured every 10s

DebouncedInput button(BUTTONPIN, 10, true);

void callback(char *topic, byte *payload, unsigned int length) {
    if (!strcmp(topic, SUBTOPIC)) {
        if (!strncmp((char *)payload, "on", length)) {
            digitalWrite(POWERPIN, HIGH);
            powerState = true;
            client.publish(PUBTOPIC, "on", true);
        } else if (!strncmp((char *)payload, "off", length)) {
            digitalWrite(POWERPIN, LOW);
            powerState = false;
            client.publish(PUBTOPIC, "off", true);
        }
    }
}

void setup() {
    button.begin();

    WiFi.mode(WIFI_STA);

    pinMode(POWERPIN, OUTPUT);
    pinMode(LEDPIN, OUTPUT);
    digitalWrite(POWERPIN, LOW);
    digitalWrite(LEDPIN, LOW);

    client.setServer("IP of your MQTT broker", 1883);
    client.setCallback(callback);

    // Add more of these for access to more APs.
    wifiMulti.addAP("WiFi name", "WiFi password");

    ArduinoOTA.setHostname(NAME);
    ArduinoOTA.setPassword(OTAPW);
    ArduinoOTA.begin();

    DS18B20.begin();
}

void loop() 
{
    static uint32_t ts = millis();
    ArduinoOTA.handle();
    client.loop();

    if (wifiMulti.run() != WL_CONNECTED) {
        delay(100);
    } else {
        if (!client.connected()) {
            delay(100);
            if (client.connect(NAME, BROKERUSER, BROKERPASS)) {
                client.subscribe(SUBTOPIC);
            }
        } else {
            if (millis() - ts >= 5000) {
                ts = millis();
                client.publish(PUBTOPIC, powerState ? "on" : "off", true);
            }
        }
    }

    if (button.changedTo(LOW)) {
        powerState = !powerState;
        digitalWrite(POWERPIN, powerState);
        if (client.connected()) {
            client.publish(PUBTOPIC, powerState ? "on" : "off", true);
        }
    }

    digitalWrite(LEDPIN, !client.connected());

  unsigned long currentMillis = millis();
 
  // if you don't use the temperature sensor, comment out the following block
  if(client.connected() && (currentMillis - previousMillis) > TEMP_INTERVALL){
    char h[20];
    float temp;
    DS18B20.requestTemperatures(); 
    temp = DS18B20.getTempCByIndex(0);
    sprintf(h,"%.1f",temp);
    client.publish(TEMPTOPIC,h,true);
    previousMillis=currentMillis;
  }

}

To compile and program this software the Arduino-IDE can be used. There are countless instructions and tutorials. Thanks of the used libraries the code is fairly short.

The following things are worth to be to be mentioned:
Folgende Sachen sind mir aufgefallen:

  • There are two LEDs available. The blue LED is on if the power switch has a connection to the MQTT broker (WiFi works, MQTT broker is available). This is also a good indicator, if the home automation runs. the second LED is red an is on if the power of the plug is switched on.
  • The Arduino library has at least in some conditions problems to resolve local hostnames (from the Fritzbox router) . I had to enter the IP-number of the MQTT broker instead their hostname.
  • The WiFi-Name it case sensitiv
  • The power switch needs as MPTT payload “on” and “off”. But this can be changed in the source code.
Posted in home automation | Tagged , , | 1 Comment

Nightly visitors in the garden

For some month we have observed that one time a week someone opens the heavy cover of our composter, in which we deposit our organic kitchen waste. The cover is not so lightwight and it realy needs some power to open it. The visitor must be much stronger than a cat.

The grey box is the composter of this story

Long time we thought, we know the lad. One time on a late evening in winter our neighbor entered his kitchen balcony and someone hissed beside him. A racoon ()yes, they are new in the area) has eaten bird feed and didn’t enjoy the disturbing. Clear, the racoon eats also our organic kitchen waste. Or?

Now, my brother in law lents me a wild camera, and yes, this should be a handy tool to monitor our visitor.

OK, that isn’t a racoon. Looks like a fox like our kitchen waste. (I think in this video he took a piece of bread)

Foxes in the vegetable garden are not so a nice thing. Some of them carries fox-tapeworms what we definitely don’t want in our vegetables. So we decide to make visits less attractive by putting heavy stones at the composter cover (see the pic above).

As it can be seen, the fox don’t like the idea with the stomes and give up.

two days he thought about the problem. Then he came back:

Foxes are very clever animals (or pets in this case 😉 )

But, it seems too annoying. That was the last time we saw him on the box. One time he came back hunting a bird. The wild camera has taken no further video from him.

Posted in Allgemein | Comments Off on Nightly visitors in the garden