willasm / obsidian-open-weather

Obsidian plugin for OpenWeather API
MIT License
49 stars 3 forks source link

dynamically updating weather in a dashboard #3

Closed securanota closed 1 year ago

securanota commented 1 year ago

Hello, I use a page that I call my "Daily Dashboard" to pull in a variety of data and tasks. The content is static relying on embeds and queries to pull in current information. I'm trying to use your plugin to add the weather to this page, but so far I've been unsuccessful. I can add it using a command, but this doesn't update. I tried using <div class="weather_current_1"></div> but nothing displays. Am I doing it wrong or is this possible? I need it refresh without depending on a daily template loading. Thanks! Jack

willasm commented 1 year ago

This is very strange? I was able to reproduce this once but restarted Obsidian and I can not get it to happen again? Try restarting Obsidian and let me know if it is working after that.

For dynamic weather you do need to use the div like <div class="weather_current_4"></div> and use "weather_current_1", "weather_current_2", "weather_current_3" or "weather_current_4" inside the div to correspond to one of the four strings in the settings.

Also, are you seeing any errors? If you just got your API key it will be a while before it is activated.

securanota commented 1 year ago

image

I opened the developer console, but there are no errors. The weather does show correctly in the status bar, and I can insert it using the command palette. I tried disabling every plugin except yours then restarting, but still nothing in live preview or reading mode.

willasm commented 1 year ago

This is frustrating!!! I got it to happen one more time and switching to another note and back fixed it? I thought it might have to do with the update frequency time setting in the plugin settings (default is 15 min) but that is not it. It should update automatically when switching to edit or preview mode which it does for me 99% of the time. I'm going to check my code for the triggers to update the div. Maybe something changed with the last big update to Obsidian. I also will point out I have only been using them in my daily notes template which works every time. I have only been able to reproduce this by manually adding the div to a note. I'll keep at it until I find the problem.

One of the triggers is on file open, so try closing the note and open it again and see if that triggers it.

willasm commented 1 year ago

May be getting somewhere with this. I got it to happen again and checked it out in the dev console and the div is actually updated with the current weather, it is just not being displayed. the opacity is set to zero for some reason which I have it set to in my daily template to create the hover effect, but this is happening with that css snippet disabled? I'm close to figuring this out.

You may want to try using <div class="weather_current_1" style="opacity: 1;"></div> to force opacity to 1.

willasm commented 1 year ago

Finally solved this! It requires a css snippet to be added to your snippets folder. I'm not sure why as it should still display the weather string, just without any styling. That was how it was working originally. Anyhow to enable this, first add to the frontmatter of the note your using it in the following cssclass line...

---
cssclass: openweather
---

Then add the following css snippet to your vaults snippet folder vault/.obsidian/snippets (create the snippets folder if it does not exist already)... Don't forget to enable the snippet in settings/appearance (at the bottom).

.openweather {
    padding-left: 25px !important;
    padding-right: 25px !important;
    padding-top: 20px !important;
}

/* Current weather One, Two, Three and Four settings */
/* These are not necessary but demonstrate how to style the weather string */
.weather_current_1, .weather_current_2, .weather_current_3, .weather_current_4 {
    display: flex;
    float: left;
    clear: left;
    color: #c4caa5;
    background-color: #133e2c;
    align-items: center;
    top: 80px;
    left: 35px;
    position: absolute;
    font-family: monospace;
    font-size: 14pt !important;
    margin: 10px 5px;
    padding: 10px 20px;
    box-shadow: 3px 3px 2px #414654;
}

Thanks for bringing this to my attention. I will update the readme to reflect this information.

securanota commented 1 year ago

Thanks for your work on this, but unfortunately I've still got nothing. image

willasm commented 1 year ago

I did see this once, but switching to another note, then back corrected it. I'm testing this in a completely empty vault with only this plugin installed. The green square is a good sign, that is the background for the div which means it is now displaying, but the weather update has not been triggered to fill in the data. Try again to close and reopen the note.

securanota commented 1 year ago

I've tried open/close the file, restart Obsidian, and restart with only openweather as an active plugin. Same result everytime.

willasm commented 1 year ago

Can you try this in a new blank note with just the frontmatter cssclass line and the div below the frontmatter. I can not get this to replicate.

securanota commented 1 year ago

Sure. This is the note content: image

Here is the result: image

securanota commented 1 year ago

I'm using the Minimal theme.

willasm commented 1 year ago

Everything looks correct and the green box tells me you have the snippet installed correctly. After about 30 tries I got it to replicate. I now have 10 notes that are displaying the the same thing. I just set the update frequency to 1 minute and after a minute they are now displaying. Try setting the update frequency to 1 minute and see if it updates after a minute. The default is 15 min but changing to reading view is supposed to force an update??

willasm commented 1 year ago

By the way I use minimal theme as well so I know that is not the problem.

willasm commented 1 year ago

When you get a chance can you please try the updated main.js that I uploaded to the repo. Just overwrite the one in the plugins directory with the new one. I removed the conditional checks on the div update routine so it should not fail to run at all. I have not had it fail for me once with the conditionals removed.

securanota commented 1 year ago

I'm sorry I haven't been able to try this sooner. I did update the main.js. I even tried creating another vault with only your plugin active but I continue to get the same results.

I'm using the latest insider build of Obsidian on Windows 11.

I have no other problems with Obsidian or other plugins.

willasm commented 1 year ago

Terribly sorry about not responding to this sooner, have not had access to my pc for quite a while. I have just uploaded an updated main.js and have added many changes to this version. I made to test to update the dynamic div's much simpler. It now will updated whenever a file is opened as well as when rendering is completed. This should hopefully solve the div not being updated. Also added a new setting, Exclude Folder which will exclude a folder from automatic template strings replacement (set this to your templates folder so it does not replace the strings in your template) Is now enabled for mobile, (it just disables the statusbar settings for mobile devices)

Will create a release after I complete updating the documentation and do some code cleanup.