A source that computes electrical power (W) from a voltage and a current source. Once registered, it appears in every source picker: mixes, logic switches, special functions, other widgets, telemetry screens.
-- Power source: a Lua source computing watts from a voltage and a current-- sensor. It shows up in every source picker (mixes, logic switches, widgets).-- https://frskyrc.github.io/ethos-lua-doc/cookbook/lua-source/localcfg={volts=nil,amps=nil}localfunctionsourceInit(source)source:unit(UNIT_WATT)source:decimals(0)source:value(0)endlocalfunctionsourceWakeup(source)localv=cfg.voltsandcfg.volts:value()locala=cfg.ampsandcfg.amps:value()ifvandathenlocalw=math.floor(v*a+0.5)ifw~=source:value()thensource:value(w)end-- write only on changeendendlocalfunctionsourceConfigure(source)localline=form.addLine("Voltage")form.addSourceField(line,nil,function()returncfg.voltsend,function(s)cfg.volts=send)line=form.addLine("Current")form.addSourceField(line,nil,function()returncfg.ampsend,function(s)cfg.amps=send)endlocalfunctionsourceRead(source)cfg.volts=storage.read("volts")cfg.amps=storage.read("amps")endlocalfunctionsourceWrite(source)storage.write("volts",cfg.volts)storage.write("amps",cfg.amps)endlocalfunctioninit()system.registerSource({key="power",name="Power (W)",init=sourceInit,wakeup=sourceWakeup,configure=sourceConfigure,read=sourceRead,write=sourceWrite})endreturn{init=init}
Enable it under Model → Lua, pick the voltage and current sources in its settings, then choose Power (W) anywhere a source is offered. For example, a logic switch that turns on above 1500 W, or the built-in Value widget.