import lacrosse
#Get the latest temperature value from a device named 'temperature'
# First setup your La Crosse View app
email = '{{EMAIL}}'
password = '{{PASSWORD}}'
print("Logging in...")
token = lacrosse.lacrosse_login(email, password)
print("Getting locations...")
locations = lacrosse.lacrosse_get_locations(token)
print("Getting devices...")
devices = lacrosse.lacrosse_get_devices(token, locations)
print(devices)
# for device in devices:
# if device['device_name'] == 'temperature':
# weather_data = lacrosse.lacrosse_get_weather_data(token, device)
# print("Current temperature is: {} {}".format(weather_data['Temperature']['values'][-1]['s'], weather_data['Temperature']['unit']))
Full Code
import lacrosse
import time
import os
import sys
import re
from paho.mqtt import client as mqtt_client
##Log in Information for Lacrosse
email = '{{YOUR EMAIL}}'
password = '{{YOUR PASSWORD}}'
##Configure MQTT Client
broker="{{MQTT BROKER}}"
port=1883
mqtt_user = "{{MQTT USER}}"
mqtt_pass = "{{MQTT PASSWORD}}"
client_id = "WeatherStation"
topic = "homeassistant/sensor"
sub = "lacrosse"
def connect_mqtt():
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to MQTT Broker!")
else:
print("Failed to connect, return code %d\n", rc)
# Set Connecting Client ID
client = mqtt_client.Client(client_id)
client.username_pw_set(mqtt_user, mqtt_pass)
client.on_connect = on_connect
client.connect(broker, port)
return client
# Get the latest temperature value from a device named 'temperature'
# First setup your La Crosse View app
def publish(client,name,finaluom,data):
time.sleep(1)
topicpart = name.replace(" ","_")
fulltopic = topic + "/lacrosse_" + topicpart
statetopic = fulltopic + "/state"
data = float(data)
#print(fulltopic)
#Initialize
config = fulltopic + "/" + "config"
##convert UOM to Match Home Assistant
if finaluom == "degrees_fahrenheit":
finaluom = "°F"
if finaluom == "relative_humidity":
finaluom = "%"
if finaluom == "degrees_celsius":
data = (data * 9/5) + 32
finaluom = "°F"
if finaluom == "kilometers_per_hour":
data = (data * .621371)
finaluom = "mph"
configdata = '{"name": "' + name + '","state_topic": "' + statetopic + '", "unit_of_measurement": "' + finaluom + '", "value_template": "{{value_json}}"}'
result = client.publish(config, configdata)
result = client.publish(statetopic, data)
# result: [0, 1]
status = result[0]
#if status == 0:
#print(f"Send `{data}` to topic `{statetopic}`")
#else:
#print(f"Failed to send message to topic {topic}")
#print("Logging in...")
token = lacrosse.lacrosse_login(email, password)
#print("Getting locations...")
locations = lacrosse.lacrosse_get_locations(token)
#print("Getting devices...")
devices = lacrosse.lacrosse_get_devices(token, locations)
#print(devices)
client = connect_mqtt()
for device in devices:
StationDevices = device['sensor_field_names']
weather_data = lacrosse.lacrosse_get_weather_data(token, device)
#print(weather_data)
for sensors in StationDevices:
if device['sensor_type_name'] == 'Weather Station Display':
temp = "Display" + str(locals()['sensors'])
if device['sensor_type_name'] == 'LTV-WSDTH04':
temp = "Station" + str(locals()['sensors'])
if device['sensor_type_name'] == 'Rain 2.0 Sensor':
temp = str(locals()['sensors'])
value = weather_data[locals()['sensors']]['values'][-1]['s']
value = float(value)
uom = weather_data[locals()['sensors']]['unit']
#exec("%s = %d" % (temp,value))
label = re.sub(r'((?<=[a-z])[A-Z]|(?<!\A)[A-Z](?=[a-z]))', r' \1', temp)
publish(client,label,uom,value)
After taking a year off being crazy busy, I am going to try this whole blogging thing again. I hope to be able to start making new videos in the coming weeks. Right now I am trying to get some posts created and get some video shot. I have quite a few items in the…
https://youtu.be/QNiEH77bKO0 Code for Node-Red This little block of code is used in Node-Red as a part of Home Assistant. It works by sending a timestamp every minute which is compared to input datetime we created earlier. If those two match, then it fires the command to turn on the light to green. Code for YAML…
Power Consumption Setup Sensor Code Example Power Sensor Example Refresh When On Automation Charging Station Automation To quickly import this Blueprint into your Home Assistant environment, just click the link below! Make sure to update your Home Assistant URL before completing the import. Notify when automation runs Hot Water Kettle Automation Automation to Notify when…
References / Resources Home Asisstant Supervised on RPi 4 – https://community.home-assistant.io/t/install-supervised-supervisor-on-raspberry-pi4-with-docker-installation/291186/4 Home Assistant Supervised GitHub – https://github.com/home-assistant/supervised-installer#supported-machine-types Kiosk Browser for Ubuntu: https://obrienlabs.net/setup-kiosk-ubuntu-chromium/ Up to date installer: https://peyanski.com/how-to-install-home-assistant-supervised-official-way/#Home_Assistant_Supervised_method Install Home Assistant with Docker So first we need to make sure our system is up to date sudo apt-get update && sudo apt-get upgrade Then we need…
Video Transcript COMING SOON Links in Video Team Tracker Integration (GitHub) – https://tsh.li/TeamTracker Team Tracker Card (GitHub) – https://tsh.li/Ttcard Product Links (We use affiliate links, so if you purchase something it goes to help the channel) Indoor Govee Lights Govee Glide Lively (Wall Lights) – https://amzn.to/3T1XqeFGovee String Lights T1 – https://amzn.to/47L0e4rGovee Hexa Pro 10pk –…
VIDEO Your Tesla might read SMS messages out loud. Your smart glasses might do the same. But try getting a Home Assistant alert directly into either of those—and you’ll quickly hit a wall. Most infotainment systems don’t support notifications from anything but basic SMS, and even then, only through specific, outdated channels. So how do…