title: Simulate battery charging in real time with python simpy
body: <p>I'm trying to do a simulation with simpy for a battery charging. The parameters needed are the battery capacity (W), the state of charge of the battery (in percentage) and the charging power of the charger (W/h)</p>
  <p>My code looks like this:</p>
  <pre><code>import simpy
  import random
  
  battery_percentage = []
  
  class ChargingCycle(object):
      def __init__(self, env, battery_capacity, SoC, charging_power):
          self.env = env
          self.battery_capacity = battery_capacity
          self.SoC = SoC
          self.charging_power = simpy.Resource(env,charging_power)
  
      def charge(self, battery):
          print(self.charging_power)
          power_per_minute = self.charging_power/60
          charge_in_kw = (self.SoC/100)/self.battery_capacity
          charge_in_kw += power_per_minute
          self.SoC = charge_in_kw/self.battery_capacity*100
  
      
  def start_charging(env, battery, charging):
      with charging.charging_power.request() as request:
          yield request
          yield env.process(charging.charge(battery))
      
  
  def run_charging(env, battery_capacity, SoC, charging_power):
      charging = ChargingCycle(env, battery_capacity, SoC, charging_power)
      battery = 0
      while True:
          yield env.timeout(1)
          battery += 1
          env.process(start_charging(env, battery, charging))
  
  def main():
      env = simpy.Environment()
      env.process(run_charging(env,45000, 10, 7630))
      env.run(until=360)
  
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>
  <p>Basically I want to get the charging power for every minute, and every minute I add the power given from the charger to the battery to a variable <code>charge_in_kw</code> and I update the state of charge <code>SoC</code>.</p>
  <p>When I run the simulation I get this error:</p>
  <pre><code>File &quot;c:\Users\sc57978\Desktop\OCPP\sim_charge.py&quot;, line 17, in charge
  power_per_minute = self.charging_power/60
  
  TypeError: unsupported operand type(s) for /: 'Resource' and 'int'
  </code></pre>
  <p>Someone knows how can I fix this?</p>