Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thermostat module #1603

Merged
merged 6 commits into from
Mar 25, 2019
Merged

Add thermostat module #1603

merged 6 commits into from
Mar 25, 2019

Conversation

ElderJoy
Copy link
Contributor

@ElderJoy ElderJoy commented Mar 3, 2019

No description provided.

@Misiu
Copy link

Misiu commented Mar 4, 2019

@ElderJoy this looks awesome. Do I understand that I can use a single relay and DS18B20 sensor connected to the same device or I can use two devices - one with relay and second with a sensor?
Description of changes and the functionality would be more than welcome 🙂
maybe You could add a screenshot showing UI panel?

@ElderJoy
Copy link
Contributor Author

ElderJoy commented Mar 4, 2019

Hi @Misiu! Thank you. Opearion description:

  • Thermostat module intended to control relay basing on temperature sensor data (remote or local) and temperature range.
  • I used this module in gas boiler controller. But I wanted to keep up remote temperature, that measured by another sonoff with DS18B20 in other room.
  • Once a minute thermostat decide switch relay on or off depends on operation conditions. Temperature usually changes slowly, so this is suitable interval for most cases.
  • Operation priority:
  1. Remote temperature, that obtained by mqtt from remote sensor. You can setup remote sensor name in web page. Used standard heartbeat data in Json format. If remote temperature is in actual state (obtained not far than remote temperature waiting interval (2 minutes default)) then it would be prioritized source.
  2. If there is no remote sensor or it's data not actual - local sensor used. For case if something happened with remote sensor. Local sensor use average temperature, so it can differ from current instant temperature value or be invalid at the moment.
  3. If there is no local sensor or it's data not stable yet - use timings for on\off intervals. For worst case to avoid freeze in heat system.
  4. To prevent overheating in simple heaters (gas boilers usually have protection against overheating) thermostat use max heating time. After that period regardless on wether max temperature gained or not thermostat switch relay off for min rest time. After that time it will return to heating if max temp not gained.
  • Thermostat calculates time when relay was switched on for today, yesterday, current and last month and total. This feature would work if ntp is sync'd.
  • Thermostat intended to use in connection with smart home system (openHab). However it is optional. It send mqtt request for remote temperature interval regularly (every 15 seconds by default) and use it. If server answered it decided as on line. If server does not respond for THERMOSTAT_SERVER_LOST_INTERVAL (2 minutes by default) it decided as lost. Requests established Temperature interval stored locally.
  • Themperature range stored in nvram and can be configured from web interface and by mqtt. If temperature range setup by web interface, thermostat send mqtt request to server with new interval.
  • Thermostat adds temperature range and remote temperature to the heartbeat message.

So you can use local or remote sensor for your choice. Just skip remote sensor name setup.

thermostat_web
img_20190203_153255

It also support I2C display where indicating status, temp. interval, local and remote temp.
On screenshot display 4 icons that mean (inverse in opposite case):

  1. WiFi connection established successfully
  2. Mqtt connection established successfully
  3. openHab connection (responded on interval update request)
  4. actual remote temperature present.

Kamin - remote temp. source
Kitchen - local temp.
Display can be easily connected to uart pins of sonoff th10. Default setup use pins GPIO1 and GPIO3:

img_20190203_153810

@xoseperez
Copy link
Owner

It looks like the thermostat and display modules are missing in the PR. Also, I would not change the MQTT_USE_JSON value generally since it will impact all devices. Instead, create a new device in the hardware module (itead-sonoff-th-thermostat?) and set there any specific flags it should have.

@ElderJoy
Copy link
Contributor Author

ElderJoy commented Mar 6, 2019

Hi Xose,
I going to fix conflicts, you've mentioned. There are several connected questions:

  1. Missing in PR... Do you mean add thermostat and display to espurna_modules in progmem.h? Will add.
  2. As I understand, in the index.html parts of code, that belong to correspondent module should be marked as removeIf(!thermostat) to exclude it if module does not used? Will do this.
  3. You marked espurna.ino as conflicting around thermostat definition. What should be fixed there?
  4. I agree with you that general change of MQTT_USE_JSON is not a good idea. But creating separate hardware module will limit module usage for particular device (TH?) of forced to create multiple devices with thermostat configuration. Probably it would be better to set MQTT_USE_JSON depending on THERMOSTAT_SUPPORT? It would not affect MQTT_USE_JSON in default case as THERMOSTAT_SUPPORT switched off by default but enable JSON for thermostat usage if one select it. Also THERMOSTAT_SUPPORT definition could be commented to notify this dependency.

1. Add thermostat to the espurna_modules in progmem.h
2. Add thermostat to webui, gulp, html, js.
3. in general.h MQTT_USE_JSON returned to 0 by default and 1 if thermostat enabled.
# Conflicts:
#	code/espurna/config/webui.h
#	code/espurna/data/index.all.html.gz
#	code/espurna/data/index.light.html.gz
#	code/espurna/data/index.rfbridge.html.gz
#	code/espurna/data/index.rfm69.html.gz
#	code/espurna/data/index.sensor.html.gz
#	code/espurna/data/index.small.html.gz
#	code/espurna/espurna.ino
#	code/espurna/static/index.all.html.gz.h
#	code/espurna/static/index.light.html.gz.h
#	code/espurna/static/index.rfbridge.html.gz.h
#	code/espurna/static/index.rfm69.html.gz.h
#	code/espurna/static/index.sensor.html.gz.h
#	code/espurna/static/index.small.html.gz.h
#	code/espurna/web.ino
#	code/gulpfile.js
#	code/html/index.html
@ElderJoy
Copy link
Contributor Author

ElderJoy commented Mar 8, 2019

Hi Xose,
I resolved mentioned conflicts:

  1. Add thermostat to the espurna_modules in progmem.h
  2. Add thermostat to webui, gulp, html, js.
  3. In general.h MQTT_USE_JSON returned to 0 by default and 1 if thermostat enabled.

@xoseperez xoseperez merged commit 5d5e915 into xoseperez:dev Mar 25, 2019
@ElectricImpossible
Copy link

ElectricImpossible commented Dec 29, 2019

Looks very impressive, @ElderJoy do you have a bin file that I can flash to my TH16?

@ElderJoy
Copy link
Contributor Author

Looks very impressive, @ElderJoy do you have a bin file that I can flash to my TH16?

My binaries outdated. I built them year ago. Espurna project developing quite fast, so it gone far since. So, I recommend you build it from hoseperez/espurna sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants