Help me with my Schoolsoft project?

Im new to python and would like some experienced guidance in how to create this Connector.

The idea is to pass the userid/pwd to a site that my Childs uses and retrieve the lunch menu.
They uses a site called Schoolsoft.

The result from the lunch menu should be passed, per weekday back to 5 sensors, one for each schoolday.

I have done some things but can’t make it to work and are pretty sure that there are a few things that needs correction. eg. the pass of data from site to 5 sensors.

Anyone up for advices or would like to get payed to develop this for me?


Schoolsoft lunchmeny

import logging

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle

_LOGGER = logging.getLogger(__name__)

# Validation of the user's configuration
	vol.Required(CONF_SCHOOL): cv.string,
	vol.Required(CONF_USERNAME): cv.string,
	vol.Required(CONF_PASSWORD): cv.string,
	vol.Required(CONF_USERTYPE): cv.string

def setup_platform(hass, config, add_devices, discovery_info=None):
	sensor_name = CONF_NAME
	school = config.get(CONF_SCHOOL)
	username = config.get(CONF_USERNAME)
	password = config.get(CONF_PASSWORD)
	usertype = config.get(CONF_USERTYPE)
    sensor_name = 'Lunchmenu'


class Schoolsoft(Entity):
	"""Implementation of the schoolsoft sensor."""

	def __init__(self, sensor_name, matsedel, school, username, password, usertype):
		"""Initialize the sensor."""
		self._name = sensor_name
		self._state = None
		self._data = {}
		self.update() = school
		self.username = username
		self.password = password
		self.usertype = usertype

		self.cookies = {}

		_login_page_re = r"https://sms(\d*)"
		self._login_page_re = re.compile(_login_page_re % school)

	def name(self):
		"""Return the name of the sensor."""
		return self._name

	def state(self):
		"""Return the state of the sensor."""
		return self._state

	def icon(self):
		"""Icon to use in the frontend, if any."""
		return 'mdi:food'

    def try_get(self, url, attempts = 0):
		r = requests.get(url, cookies=self.cookies)

		login_page_match = self._login_page_re.match(r.url)
		if login_page_match:
			server_n = login_page_match.groups()
			if attempts < 1:
				# Sends a post request with self.username && self.password
				loginr =, data = {
					"action": "login",
					"usertype": self.usertype,
					"ssusername": self.username,
					"sspassword": self.password
					}, cookies=self.cookies, allow_redirects=False)

				# Saves login cookie for faster access after first call
				self.cookies = loginr.cookies

				return self.try_get(url, attempts+1)
				raise AuthFailure("Invalid username or password")
			return r

	def update(self):

		menu_html = self.try_get("{}/jsp/student/right_student_lunchmenu.jsp?menu=lunchmenu".format(
		menu = BeautifulSoup(menu_html.text, "html.parser")

		lunch_menu = []

		for div in menu.find_all("td", {"style": "word-wrap: break-word"}):
			food_info = div.get_text(separator=u"<br/>").split(u"<br/>")

		self._state = true

No-one that can offer to help?

I made a bash-script to get info from schoolsoft. PM if you want it.

1 Like

Found this old topic and I’m trying to make a family Dashboard. All three kids will be using Schoolsoft soon and an integration for schedules, homework and lunch menu would be great! I this script still valid?

Antar att svenska fungerar…

Shell koden ligger här:

Ladda ner filen och lägga på lämplig plats i HASS.

Här är sensors i yaml

- platform: command_line
  name: SchoolSoft
  - updated
  - dag
  - elev0
  - dag0
  - tider0
  - mat0
  - aktiviteter0
  - elev1
  - dag1
  - tider1
  - mat1
  - aktiviteter1
  - elev2
  - dag2
  - tider2
  - mat2
  - aktiviteter2
  - icon
  scan_interval: 14400 # 4 timmar
  command_timeout: 30
  command: !secret schoolsoft_script
  value_template: '{{ value_json.dag0 }}'

Här är secret länken som jag hänvisar i ovan:

schoolsoft_script: "bash /config/scripts/ -u anv_namn -p lösenord -k kommun -o json"

Kommunen hittar du i slutet på SchoolSoft hemsidan adress.

Sedan har jag en template sensor för varje barn.

- platform: template
      friendly_name: 'Mat'
      icon_template: mdi:food
      value_template: "{{ state_attr('sensor.schoolsoft', 'mat0') }}"
      friendly_name: 'Barn'
      icon_template: mdi:clock
      value_template: "{{ state_attr('sensor.schoolsoft', 'tider0') }}"
1 Like

Stort tack för ultrasnabbt svar!

Dyker ner i koden i helgen och ser om jag får ut data nästa vecka!

Det här hade ju varit superkul att få igång. Jag tror jag lyckats en bit men får inte in några värden i sensorn. Har du någon koll på vad jag kan göra för fel?