thermferm/thermferm.c

changeset 515
7ab5cf2afc0c
parent 510
2da3d3340403
child 516
65299c11774b
equal deleted inserted replaced
514:f5a00ad53329 515:7ab5cf2afc0c
1231 * Maximum error is 40 degrees for now. 1231 * Maximum error is 40 degrees for now.
1232 */ 1232 */
1233 deviation = 40000; 1233 deviation = 40000;
1234 if ((unit->air_temperature == 0) || 1234 if ((unit->air_temperature == 0) ||
1235 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) { 1235 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) {
1236 if (unit->air_temperature != temp) 1236 if (unit->air_temperature != temp) {
1237 unit->mqtt_flag |= MQTT_FLAG_DATA; 1237 unit->mqtt_flag |= MQTT_FLAG_DATA;
1238 pub_domoticz_temp(unit->air_idx, temp);
1239 }
1238 unit->air_temperature = temp; 1240 unit->air_temperature = temp;
1239 unit->air_state = 0; 1241 unit->air_state = 0;
1240 } else { 1242 } else {
1241 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); 1243 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp);
1242 } 1244 }
1251 rc = device_in(unit->beer_address, &temp); 1253 rc = device_in(unit->beer_address, &temp);
1252 if (rc == DEVPRESENT_YES) { 1254 if (rc == DEVPRESENT_YES) {
1253 deviation = 40000; 1255 deviation = 40000;
1254 if ((unit->beer_temperature == 0) || 1256 if ((unit->beer_temperature == 0) ||
1255 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { 1257 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) {
1256 if (unit->beer_temperature != temp) 1258 if (unit->beer_temperature != temp) {
1257 unit->mqtt_flag |= MQTT_FLAG_DATA; 1259 unit->mqtt_flag |= MQTT_FLAG_DATA;
1260 pub_domoticz_temp(unit->beer_idx, temp);
1261 }
1258 unit->beer_temperature = temp; 1262 unit->beer_temperature = temp;
1259 unit->beer_state = 0; 1263 unit->beer_state = 0;
1260 } else { 1264 } else {
1261 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); 1265 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp);
1262 } 1266 }
1275 if (rc == DEVPRESENT_YES) { 1279 if (rc == DEVPRESENT_YES) {
1276 if (temp) { 1280 if (temp) {
1277 if (unit->door_state == 0) { 1281 if (unit->door_state == 0) {
1278 syslog(LOG_NOTICE, "Unit `%s' door closed", unit->name); 1282 syslog(LOG_NOTICE, "Unit `%s' door closed", unit->name);
1279 unit->door_state = 1; 1283 unit->door_state = 1;
1284 pub_domoticz_output(unit->door_idx, unit->door_state);
1280 unit->mqtt_flag |= MQTT_FLAG_DATA; 1285 unit->mqtt_flag |= MQTT_FLAG_DATA;
1281 } 1286 }
1282 } else { 1287 } else {
1283 if (unit->door_state) { 1288 if (unit->door_state) {
1284 syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name); 1289 syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name);
1285 unit->door_state = 0; 1290 unit->door_state = 0;
1291 pub_domoticz_output(unit->door_idx, unit->door_state);
1286 unit->mqtt_flag |= MQTT_FLAG_DATA; 1292 unit->mqtt_flag |= MQTT_FLAG_DATA;
1287 } 1293 }
1288 } 1294 }
1289 } else { 1295 } else {
1290 unit->door_state = 1; 1296 unit->door_state = 1;
1301 if (rc == DEVPRESENT_YES) { 1307 if (rc == DEVPRESENT_YES) {
1302 if (temp) { 1308 if (temp) {
1303 if (unit->psu_state == 0) { 1309 if (unit->psu_state == 0) {
1304 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is on", unit->name); 1310 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is on", unit->name);
1305 unit->psu_state = 1; 1311 unit->psu_state = 1;
1312 pub_domoticz_output(unit->psu_idx, unit->psu_state);
1306 unit->mqtt_flag |= MQTT_FLAG_DATA; 1313 unit->mqtt_flag |= MQTT_FLAG_DATA;
1307 } 1314 }
1308 } else { 1315 } else {
1309 if (unit->psu_state) { 1316 if (unit->psu_state) {
1310 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is off", unit->name); 1317 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is off", unit->name);
1311 unit->psu_state = 0; 1318 unit->psu_state = 0;
1319 pub_domoticz_output(unit->psu_idx, unit->psu_state);
1312 unit->mqtt_flag |= MQTT_FLAG_DATA; 1320 unit->mqtt_flag |= MQTT_FLAG_DATA;
1313 } 1321 }
1314 } 1322 }
1315 } else { 1323 } else {
1316 unit->psu_state = 1; 1324 unit->psu_state = 1;
1649 } else { 1657 } else {
1650 int power = round(unit->PID_heat->OutP); 1658 int power = round(unit->PID_heat->OutP);
1651 if (unit->heater_state != power) { 1659 if (unit->heater_state != power) {
1652 syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->name, unit->heater_state, power); 1660 syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->name, unit->heater_state, power);
1653 unit->heater_state = power; 1661 unit->heater_state = power;
1662 pub_domoticz_output(unit->heater_idx, unit->heater_state);
1654 if (unit->heater_address) 1663 if (unit->heater_address)
1655 unit->mqtt_flag |= MQTT_FLAG_DATA; 1664 unit->mqtt_flag |= MQTT_FLAG_DATA;
1656 } 1665 }
1657 } 1666 }
1658 } else { 1667 } else {
1660 unit->heater_wait--; 1669 unit->heater_wait--;
1661 } else { 1670 } else {
1662 if (unit->heater_state) { 1671 if (unit->heater_state) {
1663 syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->name); 1672 syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->name);
1664 unit->heater_state = 0; 1673 unit->heater_state = 0;
1674 pub_domoticz_output(unit->heater_idx, unit->heater_state);
1665 if (unit->heater_address) 1675 if (unit->heater_address)
1666 unit->mqtt_flag |= MQTT_FLAG_DATA; 1676 unit->mqtt_flag |= MQTT_FLAG_DATA;
1667 } 1677 }
1668 } 1678 }
1669 } 1679 }
1670 if (unit->door_state) 1680 if (unit->door_state) {
1671 device_out(unit->heater_address, unit->heater_state); 1681 device_out(unit->heater_address, unit->heater_state);
1672 else 1682 pub_domoticz_output(unit->heater_idx, unit->heater_state);
1683 } else {
1673 device_out(unit->heater_address, 0); 1684 device_out(unit->heater_address, 0);
1685 pub_domoticz_output(unit->heater_idx, 0);
1686 }
1674 } 1687 }
1675 1688
1676 if (unit->cooler_address && ! unit->heater_state) { 1689 if (unit->cooler_address && ! unit->heater_state) {
1677 if (unit->PID_cool->OutP >= 50) { 1690 if (unit->PID_cool->OutP >= 50) {
1678 if (unit->cooler_wait < unit->cooler_delay) { 1691 if (unit->cooler_wait < unit->cooler_delay) {
1680 } else { 1693 } else {
1681 int power = round(unit->PID_cool->OutP); 1694 int power = round(unit->PID_cool->OutP);
1682 if (unit->cooler_state != power) { 1695 if (unit->cooler_state != power) {
1683 syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->name, unit->cooler_state, power); 1696 syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->name, unit->cooler_state, power);
1684 unit->cooler_state = power; 1697 unit->cooler_state = power;
1698 pub_domoticz_output(unit->cooler_idx, unit->cooler_state);
1685 if (unit->cooler_address) 1699 if (unit->cooler_address)
1686 unit->mqtt_flag |= MQTT_FLAG_DATA; 1700 unit->mqtt_flag |= MQTT_FLAG_DATA;
1687 } 1701 }
1688 } 1702 }
1689 } else { 1703 } else {
1691 unit->cooler_wait--; 1705 unit->cooler_wait--;
1692 } else { 1706 } else {
1693 if (unit->cooler_state) { 1707 if (unit->cooler_state) {
1694 syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->name); 1708 syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->name);
1695 unit->cooler_state = 0; 1709 unit->cooler_state = 0;
1710 pub_domoticz_output(unit->cooler_idx, unit->cooler_state);
1696 if (unit->cooler_address) 1711 if (unit->cooler_address)
1697 unit->mqtt_flag |= MQTT_FLAG_DATA; 1712 unit->mqtt_flag |= MQTT_FLAG_DATA;
1698 } 1713 }
1699 } 1714 }
1700 } 1715 }
1701 if (unit->door_state) 1716 if (unit->door_state) {
1702 device_out(unit->cooler_address, unit->cooler_state); 1717 device_out(unit->cooler_address, unit->cooler_state);
1703 else 1718 pub_domoticz_output(unit->cooler_idx, unit->cooler_state);
1719 } else {
1704 device_out(unit->cooler_address, 0); 1720 device_out(unit->cooler_address, 0);
1721 pub_domoticz_output(unit->cooler_idx, 0);
1722 }
1705 } 1723 }
1706 if (debug) 1724 if (debug)
1707 fprintf(stdout, "Final: PIDheat=%.2f PWRheat=%d PIDcool=%.2f PWRcool=%d\n", 1725 fprintf(stdout, "Final: PIDheat=%.2f PWRheat=%d PIDcool=%.2f PWRcool=%d\n",
1708 unit->PID_heat->OutP, unit->heater_state, unit->PID_cool->OutP, unit->cooler_state); 1726 unit->PID_heat->OutP, unit->heater_state, unit->PID_cool->OutP, unit->cooler_state);
1709 1727
1717 unit->fan_wait++; 1735 unit->fan_wait++;
1718 } else { 1736 } else {
1719 if (! unit->fan_state) { 1737 if (! unit->fan_state) {
1720 syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->name); 1738 syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->name);
1721 unit->fan_state = 100; 1739 unit->fan_state = 100;
1740 pub_domoticz_output(unit->fan_idx, unit->fan_state);
1722 if (unit->fan_address) 1741 if (unit->fan_address)
1723 unit->mqtt_flag |= MQTT_FLAG_DATA; 1742 unit->mqtt_flag |= MQTT_FLAG_DATA;
1724 } 1743 }
1725 } 1744 }
1726 } else { 1745 } else {
1728 unit->fan_wait--; 1747 unit->fan_wait--;
1729 } else { 1748 } else {
1730 if (unit->fan_state) { 1749 if (unit->fan_state) {
1731 syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->name); 1750 syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->name);
1732 unit->fan_state = 0; 1751 unit->fan_state = 0;
1752 pub_domoticz_output(unit->fan_idx, unit->fan_state);
1733 if (unit->fan_address) 1753 if (unit->fan_address)
1734 unit->mqtt_flag |= MQTT_FLAG_DATA; 1754 unit->mqtt_flag |= MQTT_FLAG_DATA;
1735 } 1755 }
1736 } 1756 }
1737 } 1757 }
1910 * Turn everything off 1930 * Turn everything off
1911 */ 1931 */
1912 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0; 1932 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
1913 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; 1933 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
1914 device_out(unit->heater_address, unit->heater_state); 1934 device_out(unit->heater_address, unit->heater_state);
1935 pub_domoticz_output(unit->heater_idx, unit->heater_state);
1915 device_out(unit->cooler_address, unit->cooler_state); 1936 device_out(unit->cooler_address, unit->cooler_state);
1937 pub_domoticz_output(unit->cooler_idx, unit->cooler_state);
1916 device_out(unit->fan_address, unit->fan_state); 1938 device_out(unit->fan_address, unit->fan_state);
1939 pub_domoticz_output(unit->fan_idx, unit->fan_state);
1917 device_out(unit->light_address, unit->light_state); 1940 device_out(unit->light_address, unit->light_state);
1918 unit->mqtt_flag = MQTT_FLAG_DATA; 1941 unit->mqtt_flag = MQTT_FLAG_DATA;
1919 publishDData(unit); 1942 publishDData(unit);
1920 syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->name, UNITMODE[unit->mode]); 1943 syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->name, UNITMODE[unit->mode]);
1921 } 1944 }

mercurial