# # You should have received a copy of the GNU General Public License # along with python-openhab. If not, see <http://www.gnu.org/licenses/>. # import datetime import openhab from openhab import Item base_url = 'http://localhost:8080/rest' # fetch all items items = openhab.fetch_all_items(base_url, autoupdate=True) # fetch other items, show how to toggle a switch sunset = items.get('Sunset') sunrise = items.get('Sunrise') knx_day_night = items.get('KNX_day_night') now = datetime.datetime.now() if now > sunrise.state and now < sunset.state: knx_day_night.on() else: knx_day_night.off() print knx_day_night.state
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with python-openhab. If not, see <http://www.gnu.org/licenses/>. # import datetime import openhab from openhab import Item base_url = 'http://localhost:8080/rest' # fetch all items items = openhab.fetch_all_items(base_url, autoupdate=True) # fetch other items, show how to toggle a switch sunset = items.get('Sunset') sunrise = items.get('Sunrise') knx_day_night = items.get('KNX_day_night') now = datetime.datetime.now() if now > sunrise.state and now < sunset.state: knx_day_night.on() else: knx_day_night.off() print knx_day_night.state
sleep(.1) # print('switch on pin %s' % gpio) GPIO.output(gpio, GPIO.LOW) # set switch on (relais are inverted) sleep(.1) # print('switch off pin %s' % gpio) GPIO.output(gpio, GPIO.HIGH) # set switch off (relais are inverted) print('done.') while 1: try: print("I'm up and running ...") base_url = 'http://openhab:8080/rest' # fetch all items items = openhab.fetch_all_items(base_url) # get temp item while 1: for temp in temps: soll = items.get(temp['soll']) ist = items.get(temp['ist']) switch = items.get(temp['switch']) if ist.state < soll.state and switch.state != 'ON': switch.state = 'ON' print('Enabled heating for %s' % switch.name) if ist.state >= soll.state + .5 and switch.state != 'OFF': switch.state = 'OFF' print('Disabled heating for %s' % switch.name)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with python-openhab. If not, see <http://www.gnu.org/licenses/>. # import datetime import openhab base_url = 'http://localhost:8080/rest' openhab = openhab.OpenHAB(base_url) # fetch all items items = openhab.fetch_all_items() # fetch other items, show how to toggle a switch sunset = items.get('Sunset') sunrise = items.get('Sunrise') knx_day_night = items.get('KNX_day_night') now = datetime.datetime.now(datetime.timezone.utc) if now > sunrise.state and now < sunset.state: knx_day_night.on() else: knx_day_night.off() print(knx_day_night.state)
def test_fetch_all_items(): items = openhab.fetch_all_items() assert len(items)
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with python-openhab. If not, see <http://www.gnu.org/licenses/>. # import openhab base_url = 'http://localhost:8080/rest' openhab = openhab.OpenHAB(base_url) # fetch all items print(" - Print all items:") all_items = openhab.fetch_all_items() for i in all_items.values(): print(i) # fetch some group lights_group = openhab.get_item("Lights") print(" - Send command to group") lights_group.on() print(" - Update all lights to OFF") for v in lights_group.members.values(): v.update('OFF') print(" - Print all lights:") for v in lights_group.members.values():
import openhab # Obtenu librarie ici # Mais ça ne fait pas ce que je veux. # C'ets bon pour faire une applic autonome externe en Python # https://github.com/sim0nx/python-openhab base_url = 'http://192.168.2.165:8080/rest' # fetch all items items = openhab.fetch_all_items(base_url) sunset = items.get('ConsommationWeb') print sunset.state