[How-To] Sense Power ON/OFF Toggle Via One-Wire

BraveSirRobbin

Moderator
Sensing Power ON/OFF Toggle with 1-Wire Technology

by Michael McSharry

This article describes two related capabilities. The first is a hardware interface design that uses 1-wire technology to determine if a piece of equipment is powered ON. The second is a system/software design that describes how room temperature is controlled with a space heater using a Proportional-Derivative software controller, IR and 1-wire sensors.

A classic problem when using IR to control ON/OFF of equipment when only a single ON/OFF IR toggle is available for control is to know the current powered state of the equipment. There are multiple approaches to measure or infer if power is applied. What is described here is a method to use 1-wire technology to provide a positive indication if power is being used by an appliance. The circuit was designed to determine if an IR-controlled space heater is ON or OFF.


Interface Design

The actual power sensing is being performed by a CR Magnets 3110 current sensor. This method was selected because the high voltage power is isolated from the low voltage sensing circuit and no additional power or battery is required to support the remainder of the interface electronics. The 1-wire technology was used vs. RF or X10 powerflash because the state of the 1-wire device can be queried whenever there is interest in the ON/OFF state while with RF or powerflash it is only a 1-way system where the receiver needs to be listening when the state change is announced.

The current sensor provides a voltage across a load resistor that is proportional to the current that is flowing. For this application the amount of current only needs to be measured to distinguish ON from OFF. The CR 3110 works with alternating current and the 1-wire devices operate with direct current so the CR 3110 output needs to be converted to DC. This is accomplished with a bridge diode for the AC conversion and a capacitor to smooth it out. Components selected to perform this function are not critical. The circuit is shown in Figure 1.


mms1.jpg

Figure 1 Circuit Diagram

The resistive load being applied to the CR 3110 will determine the voltage measured. The amount of current flowing will also be determined with this voltage. During initial experiments it was determined that approximately 2.7 volts was delivered with a load of 47K and no loops. Since the desired voltage was a little higher than 2.7 a loop was added and the resistor decreased to 10K to give a 4.7V reading.

When using the CR 3110 only one wire conductor is inserted in to the magnetic core. This means that the power cord from the appliance needs to be split open. Rather than doing this, a short extension can be disected. This way the appliance cord is not disturbed and if any mistakes are made then the loss is only a $3 extension.

This circuit was assembled using point to point solder connections and then encased in a plastic case to provide electrical and mechanical protection. The external interface to the 1-wire bus was made using a RJ11 modular jack with pinout the same as other 1-wire devices that use a similar interconnect method. It is pictured in Figure 3 below.

The 1-wire DS2405 is configured as an input device that will report ON with voltages of over 2.5 and OFF below that approximate value. The current level can be read by whatever software or firmware is used to manage the 1-wire bus. A DS2406 can be used as pin-for-pin replacement to the DS2405 at a higher cost. The benefit of the DS2406 is its ability to respond to an alarm poll from the host and avoid the need to explicitly poll the device except in cases where the state has changed.


Parts List

Current Sensor: www.crmagnetics.com CR3110
Bridge Rectifier: www.goldmine-elec-products.com WL02 (G12976) or T05P (G1113)
Resistor: 10K www.goldmine-elec-products.com
Capacitor 100 uf 25V www.goldmine-elec-products.com
1-Wire Switch www.hobby-boards.com DS2405


Use of Circuit in Control Application to Maintain Room Temperature

The application being addressed is control of an electric fireplace in the master bedroom during the nightime to maintain the bedroom temperature in a comfortable sleeping range. The fireplace is turned ON and OFF with an IR toggle that is being sourced by an ADI Ocelot. The current power state of the fireplace is determined from the DS2405 of the sensing circuit. The room temperature is measured using 1-wire device DS18B20.

The automation environment employed in this scenario is PC-based using xapmcs1Wire to manage the 1-wire devices and xapmcsADIOcelot to manage the ADI Ocelot’s IR. A script running under xapmcsADIOcelot contains the desired control logic to turn the IR ON/OFF based upon the fireplace power state and room temperature. Other resources are employed to collect data etc, but are not essential for the actual control.

Data has been collected over time to understand the heat loss characteristics of the room and the heating capacity of the electric heater. The heater measurements were easily obtained by taking non-sunlight measurements of the room temperature as the heater was turned on. The outside and surrounding room temperatures were at the same approximate level as the bedroom so that the measurement did not need to consider the heat loss aspect. These measurements showed a consistent two degrees per hour increase in room temperature when the electric fireplace was ON.

Heat can also be added to the room from adjacent rooms as well as from sunlight radiation. The sunlight does not need to be considered in this case because the heating need was only during the nighttime hours. Similarly the adjacent room temperatures did not need to be considered because the master bedroom did not exchange airflow well with other rooms when the door was closed.

The heat loss from the room through the walls, windows, and ceiling is dependent upon the outside temperatures. The dependency is intuitive, but the magnitude and relationship needed data for outside vs. bedroom temperatures. Measurements were taken between 2 AM and 8 AM as this is a well controlled period of time where decays could be easily measured. Seven days of data was selected to span the range of expected temperature gradients that are expected. With this limited sample an adequate correlation could be approximated. The data and the corresponding graphic are shown below.

This results in the following equations:
Electric Heater Temperature Increase: 2.0 degrees/hour
Room Temperature Loss: 0.012 degrees/hour/deltaTemperature degree


mmc.jpg



mms2.jpg

Figure 2 Heat Loss vs. Temperature Gradient

This data is useful for two purposes. The first is that the heater has sufficient output to maintain the room at a reasonable temperature. The second is that it provides some bounds for the control algorithm that can be used to protect from the heater being ON too long. In a perfect world the sensor and the control mechanisms are 100% foolproof. In reality control systems need to protect against faulty sensors and actuators.

The control approach selected to keep the bedroom at a comfortable sleeping temperature is a basic proportional-derivative control. The steady state error will be overcome by other control protection characteristics so no integral component is needed for this application. Another control approach that is typical for thermostats would use a fixed anticipation threshold.

When data was being collected to understand the behavior of the room heating it was determined that the temperature overshoots had a duration of eight minutes between when the fireplace was turned ON or OFF until the temperature peaked. This delta time saw a temperature undershoot of 0.5 degrees and undershoot of 0.9 degrees while controlling to a 4 degree band. If the control band required a tolerance of less than 1 degree then the simpler proportional control would be unstable.

Another consideration for stability is the sampling rate of the temperature and the noise that is present in this sensor’s reading. The control calculation is being performed in a one minute control cycle. Ideally the temperature sampling rate should be no slower than twice this rate. In my case I elected to sample at a two minute interval based upon the resolution of the sensor. The sensor can only discriminate 0.125 degrees and the maximum temperature rate that is expected is 0.03 degrees per minute so it would take four minutes to measure a change in temperature at the maximum heating rate.

There will be a corresponding irregular temperature derivative because of the quantization of temperature into 0.125 increments. It will typically jump from 0 to 0.125 in a two minute interval giving an apparent change rate of 0.06 degrees/minute which is actually much higher than the actual change rate. To deal with this, the derivative value is filtered which unfortunately yields a lag in the term and negates some of the benefits of the PD controller.

When the electric fireplace is ON it will be able to increase the temperature by two degrees in one hour. A limit of 100 minutes is used as the maximum time the heater will be ON at any given time to protect from the effects of bad sensor inputs.

After the heater is turned OFF the room temperature is expected to decay at the rate that is dependent upon the outside temperature, but the rate will not be greater than one degree/hour or two hours for a two degree temperature loss. When the fireplace is turned OFF it will not be turned ON again for a minimum of 120 minutes

The controller only needs to be active during the sleeping hours. During the other hours the room maintains an adequate temperature with air exchange from the warmer hallway that is heated with a wood fireplace on the lower level.

Based upon the above analysis and rationale the following script in xapmcsADIOcelot was implemented to realize the desired control.

xapmcsADIOcelot.txt (Segment)

Code:
'if master bedroom is cold at nighttime
'then keep electric fireplace ON until temperature warms

'Fireplace controlled with IR (ElectricFireplace)
'Fireplace ON/OFF measured with DS2405 (FireplacePower)
'Temperature measured with DS18B20 (MasterBedroom)

'if no power messages received then assume OFF
Set oPower = xap.request("FireplacePower")
If oPower Is Nothing Then
    sPower = "OFF"
Else
    sPower = UCase(oPower("input.state.1.state"))
End If

'retrieve the times when last ON and OFF control action taken
‘if no record of the ON/OFF times then assume a long time ago
TimeTurnedOn = xap.GetVar(“FireplaceOn”)
If not isDate(TimeTurnedOn) then
    MinutesSinceTurnedOn = 1000
Else
    MinutesSinceTurnedOn = DateDiff(“n”,TimeTurnedOn,now)
End if

TimeTurnedOff = xap.GetVar(“FireplaceOff”)
If not isDate(TimeTurnedOff) then
    MinutesSinceTurnedOff = 1000
Else
    MinutesSinceTurnedOff = DateDiff(“n”,TimeTurnedOff,now)
End if

'if it has been ON for more than 100 minutes then turn it OFF
‘if it has been OFF for less than 120 minutes then don’t turn it ON
If sPower = "OFF" then
    If MinutesSinceTurnedOff < 120 then
        Exit sub
    End if
Else
    If MinutesSinceTurnedOn > 100 then
        xap.response "ElectricFireplace", 1
        xap.Writelog "ADIOcelot", "Turning Fireplace OFF after 100 minutes ON"
        xap.SaveVar “FireplaceOff”, now
        exit sub
    End if
Else
End if

'assure electric fireplace off between 7 AM and 10 PM
If Hour(Now) >= 7 Then
    If Hour(Now) < 22 Then
        If sPower <> "OFF" Then
            xap.response "ElectricFireplace", 1
            xap.Writelog "ADIOcelot", "Turning Fireplace Off during daytime hours"
            xap.SaveVar “FireplaceOff”, now
        End If
        Exit Sub
    End If
End If

'if no bedroom temperature messages have been received then do nothing
Set oTemperature = xap.request("MasterBedroom")
If oTemperature Is Nothing Then
    Exit Sub
End If

'determine if a control action is necessary
sTemperature = oTemperature("input.state.1.text")
iControlAction = xap.ControlTemperature(60,62,sTemperature,.5)
 
if iControlAction = -1 then
    ‘turn OFF if not already OFF
    If sPower <> "OFF" Then
        xap.response "ElectricFireplace", 1
        xap.Writelog "ADI", "Turning Fireplace Off because above temperature setpoint"
        xap.SaveVar “FireplaceOff”, now
    End If
    Exit Sub

'if dynamic temperature is between upper and lower limits then do nothing
ElseIf iControlAction = 0 Then
    Exit Sub
End If

If sPower <> "OFF" Then
    Exit Sub
End If

'turn on the electric fireplace
xap.response "ElectricFireplace", 1
xap.Writelog "ADI", "Turning Fireplace On because below temperature setpoint"
xap.SaveVar “FireplaceOn”, now
Exit Sub

mms3.jpg

Figure 3 Assembly of Components

About Michael McSharry :lol:

Michael has been designing flight control systems for space and military applications since the 1970s and became interested in home automation about five years ago. He poked around with various HA technologies primarily as a learning experiece. Michael's current focus is the R&D associated with distributed computing and the management of redundancy to maximize functional availability within this architecture. In the long term Michael expects IP-based connectivity to increase amongst devices within the household. An area of opportunity and challenge is a decentralized management of these devices to achieve a natural convergence of functionality.

CocoonTech thanks Michael for his contribution to its How-To forums!
 
Does this "product" exist in a prebuilt, commercial device? I'm trying to figure out how to automate turning on/off 20 LCD Displays that will be scattered around a college campus. I'll probably use the Global Cache GC-100 in conjunction with StarDraw Control. But I'm running into the exact problem you explain -- how do I know I'm not turning the unit off, when I meant to turn it on?
 
bhelman said:
how do I know I'm not turning the unit off, when I meant to turn it on?
some, not all, have discrete IR codes for ON/OFF . . you'll need to hunt around some of the IR forums to find out if your specific units do . .
 
how do I know I'm not turning the unit off, when I meant to turn it on?

If the ON/OFF is IR controlled then the discrete code idea is good. My guess, however, is that the LCD is not designed for automation so the availabilty of discrete IR control is unlikely.

Another option may be to control the power being applied to the LCD using a device with direct ON/OFF control. For example, if your LCD is powered from a 12VDC walwart then replace the walwart with a 12VDC power supply and conect the Global Cache discrete output to control the switch input of the power supply or and external on/off discrete provided by the power supply for this purpose. I assume the Global Cache RS232 output will control the LCD contents. I do not have a specific commercial products, but just trying to brainstorm other approaches.
 
Back
Top