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

Use Timer Configuration with PID cotnrol don't work. #9

Open
6 tasks done
AXYSSA opened this issue Nov 16, 2018 · 18 comments
Open
6 tasks done

Use Timer Configuration with PID cotnrol don't work. #9

AXYSSA opened this issue Nov 16, 2018 · 18 comments

Comments

@AXYSSA
Copy link

AXYSSA commented Nov 16, 2018

Hi guys, I'm Felipe, from Chile... I hope you can help me with this issue, I'm new in the arduino/esp8266 and open source/github world... So this is my first time here hahaha...

I have been working with the Tasmota Sonoff firmware, with the PID Control, for make an intelligent heater that you can control from an android app. The objective is to choose in the app between automatic and manual control, so in manual mode I can power on and off the heater whenever I want, or programming some date and hour of on/off, and in automatic mode I can set the temperature, day (s) and hour (s) that you want it to work .

So, the firmware has three things working (Manual mode and Timer in Tasmota, and Automatic mode with PID) but it does not work together.
It seems that with the PID control just as it is, the device will work just with temperature control, without the possibility of manual and / or timer control.
I did modify the firmware so now I can put the device in Manual mode (direct on / off with MQ command, the hardware button and from webserver), and in Automatic mode with temperature control (PID). Switching the modes using the PID_AUTO command.
I also fixed the "bug" of the button in automatic mode. With the original firmware, if you press the hardware button, It'll toggle the relay state for a second, and back to the calculated power state in the PID. With my modification, it do absolutly nothing, wich is better for now...

So, the issue, is that the Timer never work. Not in Automatic or Manual mode. I tryed it with the originals firmwares (without my modifications) and it don't work eather. Is there any "easy" way that I can make the Timer works, independently of the Automatic or Manual control?

Also, a little doubt, wich is the best wificonfig mode for pairing the sonoff with an android app?

PD1: Sorry if my wnglish is not the best, hahaha...
PD2: Of course I'll share my modifications when i get it working fine...

Also, make sure these boxes are checked [x] before submitting your issue - Thank you!

  • Searched the problem in issues and in the wiki
  • Hardware used : SONOFF TH16
  • Development/Compiler/Upload tools used : Tasmota firmware with PID Control (and timeprop)
  • If a pre-compiled release or development binary was used, which one? : None
  • You have tried latest release or development binaries? : Yes
  • Provide the output of commandstatus 0 :
11:50:11 MQT: ECOLEED/ENERHEAT/DEVW/ENRHT_ID_4291BD/STATUS = {"CMD":"STATUS","Status":{"Module":4,"FriendlyName":["Sonoff"],"Topic":"ENRHT_ID_4291BD","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}
11:50:11 MQT: ECOLEED/ENERHEAT/DEVW/ENRHT_ID_4291BD/STATUS1 = {"CMD":"STATUS1","StatusPRM":{"Baudrate":115200,"GroupTopic":"sonoffs","OtaUrl":"http://sonoff.maddox.co.uk/tasmota/sonoff.bin","RestartReason":"Power on","Uptime":"0T00:00:42","StartupUTC":"2018-11-16T14:49:29","Sleep":0,"BootCount":36,"SaveCount":79,"SaveAddress":"F5000"}}
11:50:11 MQT: ECOLEED/ENERHEAT/DEVW/ENRHT_ID_4291BD/STATUS2 = {"CMD":"STATUS2","StatusFWR":{"Version":"6.2.1.15","BuildDateTime":"2018-11-15T17:02:39","Boot":4,"Core":"2_3_0","SDK":"1.5.3(aec24ac9)"}}
11:50:11 MQT: ECOLEED/ENERHEAT/DEVW/ENRHT_ID_4291BD/STATUS3 = {"CMD":"STATUS3","StatusLOG":{"SerialLog":4,"WebLog":2,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["AXYSN",""],"TelePeriod":300,"SetOption":["00008009","55818000","00000000"]}}
11:50:11 MQT: ECOLEED/ENERHEAT/DEVW/ENRHT_ID_4291BD/STATUS4 = {"CMD":"STATUS4","StatusMEM":{"ProgramSize":492,"Free":508,"Heap":14,"ProgramFlashSize":1024,"FlashSize":1024,"FlashMode":3,"Features":["00000809","0FDAE794","000003A1","23B617CE","000007C0"]}}
11:50:11 MQT: ECOLEED/ENERHEAT/DEVW/ENRHT_ID_4291BD/STATUS5 = {"CMD":"STATUS5","StatusNET":{"Hostname":"ENRHT_ID_4291BD-4541","IPAddress":"192.168.2.186","Gateway":"192.168.2.1","Subnetmask":"255.255.255.0","DNSServer":"192.168.2.1","Mac":"5C:CF:7F:42:91:BD","Webserver":2,"WifiConfig":3}}
11:50:12 MQT: ECOLEED/ENERHEAT/DEVW/ENRHT_ID_4291BD/STATUS6 = {"CMD":"STATUS6","StatusMQT":{"MqttHost":"192.168.2.118","MqttPort":1883,"MqttClientMask":"DEVID_%06X","MqttClient":"DEVID_4291BD","MqttUser":"AXYS_FA_SERVER","MqttType":1,"MAX_PACKET_SIZE":1000,"KEEPALIVE":15}}
11:50:12 MQT: ECOLEED/ENERHEAT/DEVW/ENRHT_ID_4291BD/STATUS7 = {"CMD":"STATUS7","StatusTIM":{"UTC":"Fri Nov 16 14:50:12 2018","Local":"Fri Nov 16 11:50:12 2018","StartDST":"Sun Apr 01 00:00:00 2018","EndDST":"Sun Sep 09 00:00:00 2018","Timezone":-3,"Sunrise":"06:30","Sunset":"20:23"}}
11:50:12 PID_Show_Sensor: mqtt_data: {"CMD":"STATUS10","StatusSNS":{"CMD":"SENSORDATA","Time":"2018-11-16T11:50:12","AM2301":{"Temperature":25.9,"Humidity":34.0},"TempUnit":"C"}
11:50:12 PID_Show_Sensor - json parse failed
11:50:12 MQT: ECOLEED/ENERHEAT/DEVW/ENRHT_ID_4291BD/STATUS10 = {"CMD":"STATUS10","StatusSNS":{"CMD":"SENSORDATA","Time":"2018-11-16T11:50:12","AM2301":{"Temperature":25.9,"Humidity":34.0},"TempUnit":"C"}}
11:50:12 MQT: ECOLEED/ENERHEAT/DEVW/ENRHT_ID_4291BD/STATUS11 = {"CMD":"STATUS11","StatusSTS":{"CMD":"UPTIME","Time":"2018-11-16T11:50:12","Uptime":"0T00:00:43","Vcc":3.163,"POWER":"OFF","Wifi":{"AP":1,"SSId":"AXYSN","BSSId":"60:A4:4C:66:A3:4E","Channel":7,"RSSI":78}}}

To Reproduce
Use the device in Auto or Manual mode. Send through MQ or through webserver the Timer parameters (for example, power on for 5 minutes in one mode minute)

Expected behavior
In any case (Auto or Manual) the Timer work and turn on the led. It doesn't.

(Please, remember to close the issue when the problem has been addressed)

@colinl
Copy link
Owner

colinl commented Nov 16, 2018

Are you using the Timeprop output?

@AXYSSA
Copy link
Author

AXYSSA commented Nov 16, 2018

Yes, I'm

@colinl
Copy link
Owner

colinl commented Nov 16, 2018

In that case you cannot stop the timeprop algorithm from controlling the output. However if you put the PID into manual using PID_AUTO, which you are I think, then you can use PID_MANUAL_POWER to set the power to the level you want. If you set it to 0 or 1 it will set the output fully off or on. If you set it to 0.5 then it will time proportion to 50%. So you can control the output manually to anything you want.

To stop the button from driving the relay I think you just have to write something to the mqtt topic ButtonTopic. That isn't a PID issue that is a standard feature.

@AXYSSA
Copy link
Author

AXYSSA commented Nov 16, 2018

Is there a way to use the PID control without timeprop? If that's the case, I don't really understand the objective of the timeprop output hahaha...
So, if I use the PID without timepro, the Timer should work? and the manual mode too?

@colinl
Copy link
Owner

colinl commented Nov 16, 2018

If you don't define PID_USE_TIMPROP in user_config.h then it won't use it, of course you won't get the time proportioned output on the relay. The pid algorithm will still output a value between 0 and 1 and you can use that to drive the relay yourself however you like.
As for the timer, I don't fully understand what you are trying to do. As far as I know there should be no interaction between timers and the pid/timeprop code except that you can't drive the relay if you you are using the time proportioned output.
What is wrong with putting the pid into manual and then using the timer to drive the pid manual power as I described? Though I have never used the tasmota timers so I don't know much about them.

@AXYSSA
Copy link
Author

AXYSSA commented Nov 16, 2018

Ok, I just make a test with the originals firmwares (without my modifications)

  1. Using Timeprop, with PID_AUTO = 1 (automatic mode)
  • Every 15 seconds (PID_UPDATE_SECS = 15) the PID calculate a power and control the relay.
  • If I press the hardware button, or toggle button in web server, the relay change the state (ON to OFF) and in a brevely moment, back to the previous state (OFF to ON).
  1. Using Timeprop, with PID_AUTO = 0 (manual mode)
  • If I set the MQ comand PID_MANUAL_POWER to 0, the relay stay off.
  • If I set the MQ comand PID_MANUAL_POWER to 1, the relay stay on.
  • If I set the MQ comand PID_MANUAL_POWER to 0.5, the relay switch ON and OFF every 15 or 30 seconds (I didn't understand much how it's working...).
  • In every of the three cases before, if I press the hardware button, or toggle button in web server, the relay change the state (ON to OFF) and in a brevely moment, back to the previous state (OFF to ON).
  1. NOT Using Timeprop ( //#define PID_USE_TIMPROP )
  • happened exactly the same that in test 1 and 2, but with no control on the relay, as you said, just the "power":"x.xxxx" at the serial log, that can be used to operate the relay...
  1. Configuring a Timer through webserver (with and without timeprop). Turn on the relay in 1 more minute.
  • It doesn't appear the parameters in the console.
  • Doesn't change the state of the relay, doesn't work eather with or without PID_USE_TIMPROP.

I'm trying to make two things work:

  • Use the hardware button in the sonoff case, and the toggle button in webserver, in manual mode (not just throug MQ). (I solved this in my modifications).
  • Use the Timer Configuration from webserver and MQ. (in manual and automatic mode)

@ascillato
Copy link

You can use last Tasmota with colinl drivers and you can make the timers to trigger a rule. The rule can use the commands PID_AUTO and PID_MANUAL_POWER to use or not to use the PID

@AXYSSA
Copy link
Author

AXYSSA commented Nov 16, 2018

Oh, ok, I'll try it tomorrow and let you guys know.
Thank you!

@colinl
Copy link
Owner

colinl commented Nov 16, 2018

Does part 4 work if you use the standard tasmotta s/w without pid or timeprop? If not then obviously this isn't a PID issue. You might get help on that problem on the mailing list/forum https://groups.google.com/forum/#!forum/sonoffusers.
By the way, you should have the pid update secs much shorter than the timeprop cycle time. For most applications leaving it at the default value of zero is best, so that it runs the algorithm every time there is a sensor value available.

@colinl
Copy link
Owner

colinl commented Nov 17, 2018

@AXYSSA is the Sonoff connected to a Pi or something for MQTT etc? If so the way I have done a similar thing is by involving the Pi. I have it so that via my dashboard GUI interface to the pi I can select Manual and control the valve from my phone or PC, but also made it so that a long press on the Sonoff button puts it into manual then a short press on the buttons toggles between On and Off. Another long press puts it back into auto. The LED flashes while in manual with it on blinking off when relay is closed, and off, flashing on when relay is open. Variation of the desired temperature is achieved via the Pi rather than in the Sonoff.
I run node-red on the pi (which is great fun to use and has an excellent support forum) which provides the dashboard for all my home automation devices and does the high level control and monitoring.

@AXYSSA
Copy link
Author

AXYSSA commented Nov 19, 2018

Does part 4 work if you use the standard tasmotta s/w without pid or timeprop? If not then obviously this isn't a PID issue. You might get help on that problem on the mailing list/forum https://groups.google.com/forum/#!forum/sonoffusers.
By the way, you should have the pid update secs much shorter than the timeprop cycle time. For most applications leaving it at the default value of zero is best, so that it runs the algorithm every time there is a sensor value available.

Hello again, @colinl, part 4 works fine with standard tasmota (without PID and timeprop). I checked that to see if the UTC configuration was good.
I have set the PID_UPDATE_SECS in 15 secs when it's in automatic (because in the description said that it's well appropriate for a domestic room heating application), and in 1 secs in manual mode. the TIMEPROP_CYCLETIMES is 60. I think it's good enough for a nice work, right?.
Anyway this numbers could be change when I make the real proves with the real heater in a room.

@colinl
Copy link
Owner

colinl commented Nov 19, 2018

Looking again at part 4 above, I see that you are using a timer to switch the relay. That won't work if the timeprop file (xdrv_91_timeprop.ino) is included in the source directory. It is not enough just to remove the #define, which is telling the pid algorithm whether to use it, you must remove the file also.

Looking at xdrv_91 again I can see that it would not be difficult to add a timeprop_enable command to enable/disable the timeprop algorithm completely so you could drive it the way you want to. I would be very happy to apply a PR to add that feature if you wanted to have a crack at it. If you look at how the set power command is implemented you should be able to see how to add an enable/disable feature. I have not got time to do it myself at the moment.

Perhaps the wording on the use of PID_UPDATE_SECS is ambiguous in the description. It says that usually this should be set to 0 to run the algorithm as each process value is received, then suggests that 15 secs may be appropriate. I meant that usually it should be set to zero, and then you should arrange process values to be process values to be available every 15 seconds. That is done with tele_period.

What sort of heater will you be using and how is that heater controlled?

@AXYSSA
Copy link
Author

AXYSSA commented Nov 19, 2018

@AXYSSA is the Sonoff connected to a Pi or something for MQTT etc? If so the way I have done a similar thing is by involving the Pi. I have it so that via my dashboard GUI interface to the pi I can select Manual and control the valve from my phone or PC, but also made it so that a long press on the Sonoff button puts it into manual then a short press on the buttons toggles between On and Off. Another long press puts it back into auto. The LED flashes while in manual with it on blinking off when relay is closed, and off, flashing on when relay is open. Variation of the desired temperature is achieved via the Pi rather than in the Sonoff.
I run node-red on the pi (which is great fun to use and has an excellent support forum) which provides the dashboard for all my home automation devices and does the high level control and monitoring.

Yes, I have the device connected to a MQTT, so I've been testing MQ communication all the time, but not a Pi, because it's going to run from an android app, and my software college can work better with MQ for that porpuse.
I like a lot the idea of a long press on the Sonoff button, that puts it into manual, and then a short press on the buttons toggles between On and Off...

@colinl
Copy link
Owner

colinl commented Nov 19, 2018

If you SetOption1 to "on" and set ButtonTopic to a string then that should stop the button from driving the relay. When you short press the button it sends an mqtt button message with the value "TOGGLE", and for a long press it sends "HOLD". Then you can use those externally to control the manual operation.

@AXYSSA
Copy link
Author

AXYSSA commented Nov 19, 2018

Looking again at part 4 above, I see that you are using a timer to switch the relay. That won't work if the timeprop file (xdrv_91_timeprop.ino) is included in the source directory. It is not enough just to remove the #define, which is telling the pid algorithm whether to use it, you must remove the file also.

Looking at xdrv_91 again I can see that it would not be difficult to add a timeprop_enable command to enable/disable the timeprop algorithm completely so you could drive it the way you want to. I would be very happy to apply a PR to add that feature if you wanted to have a crack at it. If you look at how the set power command is implemented you should be able to see how to add an enable/disable feature. I have not got time to do it myself at the moment.

Perhaps the wording on the use of PID_UPDATE_SECS is ambiguous in the description. It says that usually this should be set to 0 to run the algorithm as each process value is received, then suggests that 15 secs may be appropriate. I meant that usually it should be set to zero, and then you should arrange process values to be process values to be available every 15 seconds. That is done with tele_period.

What sort of heater will you be using and how is that heater controlled?

That would be great!! I just realized (with PID and timeprop) that the Timer is trying to work, at least hahaha, at the moment that I put the "arm" option enable in the webserver (that I don't know what it means...).
So now the device try to power on/off the relay, I watch in the "MQTT Lens" the message from the device powering ON/OFF, but inmediatly it toggle to the previous state (OFF/ON)... In the led and in the serial console I could see nothing.

image

So, I'll try to fix it by myselve, adding a timeprop_enable command to enable/disable the timeprop algorithm, and I'll let you know if I could make it work.

The heater is a wall heater, working by natural thermal convection.
Oh! and I will make the SetOption1 advice that you just mencioned.

Thank you so much for the support and all the advices.
We'll be talking soon.
Greetings!!

@colinl
Copy link
Owner

colinl commented Nov 19, 2018

In terms of what it has to do I think it is just necessary for it to prevent the call of ExecuteCommandPower in Timeprop_Every_Second. Ideally the command should specify which output is to be enabled/disabled.

@Puav
Copy link

Puav commented Apr 18, 2020

Once timeprop is disabled, how to PWM drive an SSR connected to GPIO12?

@colinl
Copy link
Owner

colinl commented Apr 18, 2020

I don't think this question is related to the subject of this issue, however, the PID algorithm will produce a linear value between 0 and 1 that you can use to drive the PWM. I am sorry but I don't know about PWM output. You might be better to ask that on the mailing list.

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

No branches or pull requests

4 participants