Skip to main content

DateTime

synapse.datetime creates an entity that is intended to work with full iso timestamps.

Home Assistant Counterpart

✏️ Usage

The datetime entity has the ability to present values as dayjs, Date, or iso strings, default is iso

minimum properties

synapse.datetime({
context,
name: "My datetime entity"
});

override type

synapse.datetime<{ date_type: "dayjs" }>({
date_type: "dayjs", // must match
});

Entity specific attributes

By default datetime entities have managed: true set, and will automatically set values in response to service calls.

⚙️ Configuration

date_type

Control the format that data is presented to your code in

TypeFormat
isoiso timestamp string
datejavascript Date
dayjsDayjs object

native_value

This represents the current value in the requested date_type.

🌐 Events

These events are related to service calls being made against your entity. They will occur via dashboard interactions as well as other automations running.

Entities have managed: true set by default, allowing them to automatically handle incoming value change requests.

set_value / onSetValue

NOTE: This is not the same thing as the onChange event.

const entity = synapse.datetime<{ date_type: "dayjs" }>({
managed: false, // take full control of native_value
set_value({ value }) {
// process service call directly in with matched `date_type`
// ??
// write new value
entity.native_value = value;
}
});

entity.onSetValue(({ value }) => {
// chained attaches work too
});